|
Lines 30-36
use Koha::CirculationRules;
Link Here
|
| 30 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
| 31 |
use t::lib::Mocks; |
31 |
use t::lib::Mocks; |
| 32 |
|
32 |
|
| 33 |
use Test::More tests => 21; |
33 |
use Test::More tests => 26; |
| 34 |
|
34 |
|
| 35 |
my $dbh = C4::Context->dbh; |
35 |
my $dbh = C4::Context->dbh; |
| 36 |
my $schema = Koha::Database->new()->schema(); |
36 |
my $schema = Koha::Database->new()->schema(); |
|
Lines 129-138
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged,
Link Here
|
| 129 |
|
129 |
|
| 130 |
my $data = C4::Circulation::checkHighHolds( $item, $patron ); |
130 |
my $data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 131 |
is( $data->{exceeded}, 1, "Static mode should exceed threshold" ); |
131 |
is( $data->{exceeded}, 1, "Static mode should exceed threshold" ); |
| 132 |
is( $data->{outstanding}, 6, "Should have 6 outstanding holds" ); |
132 |
is( $data->{outstanding}, 5, "Should have 5 outstanding holds" ); |
| 133 |
is( $data->{duration}, 0, "Should have duration of 0 because of specific circulation rules" ); |
133 |
is( $data->{duration}, 0, "Should have duration of 0 because of specific circulation rules" ); |
| 134 |
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" ); |
134 |
is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" ); |
| 135 |
|
135 |
|
|
|
136 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 5 ); |
| 137 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 138 |
is( $data->{exceeded}, 0, "Static mode should not exceed threshold when it equals outstanding holds" ); |
| 139 |
is( $data->{outstanding}, 5, "Should have 5 outstanding holds" ); |
| 140 |
is( $data->{duration}, 0, "Should have duration of 0 because decrease not calculated" ); |
| 141 |
is( $data->{due_date}, undef, "duedate undefined as not decreasing loan period" ); |
| 142 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 ); |
| 143 |
|
| 136 |
Koha::CirculationRules->set_rules( |
144 |
Koha::CirculationRules->set_rules( |
| 137 |
{ |
145 |
{ |
| 138 |
branchcode => undef, |
146 |
branchcode => undef, |
|
Lines 161-168
$data = C4::Circulation::checkHighHolds( $item, $patron );
Link Here
|
| 161 |
is( $data->{exceeded}, 0, "Should not exceed threshold" ); |
169 |
is( $data->{exceeded}, 0, "Should not exceed threshold" ); |
| 162 |
|
170 |
|
| 163 |
|
171 |
|
| 164 |
# Place 6 more holds - patrons 5,6,7,8,9,10 |
172 |
# Place 7 more holds - patrons 5,6,7,8,9,10,11 |
| 165 |
for my $i ( 5 .. 10 ) { |
173 |
for my $i ( 5 .. 11 ) { |
| 166 |
my $patron = $patrons[$i]; |
174 |
my $patron = $patrons[$i]; |
| 167 |
my $hold = Koha::Hold->new( |
175 |
my $hold = Koha::Hold->new( |
| 168 |
{ |
176 |
{ |
|
Lines 173-178
for my $i ( 5 .. 10 ) {
Link Here
|
| 173 |
)->store(); |
181 |
)->store(); |
| 174 |
} |
182 |
} |
| 175 |
|
183 |
|
|
|
184 |
# Note in counts below, patron's own hold is not counted |
| 185 |
|
| 176 |
# 12 holds, threshold is 1 over 10 holdable items = 11 |
186 |
# 12 holds, threshold is 1 over 10 holdable items = 11 |
| 177 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
187 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 178 |
is( $data->{exceeded}, 1, "Should exceed threshold of 1" ); |
188 |
is( $data->{exceeded}, 1, "Should exceed threshold of 1" ); |
|
Lines 242-245
Koha::CirculationRules->set_rule(
Link Here
|
| 242 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
252 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 243 |
is( $data->{duration}, 2, "Circulation rules override system preferences" ); |
253 |
is( $data->{duration}, 2, "Circulation rules override system preferences" ); |
| 244 |
|
254 |
|
|
|
255 |
|
| 256 |
subtest "Test patron's own holds do not count towards HighHolds count" => sub { |
| 257 |
|
| 258 |
plan tests => 2; |
| 259 |
|
| 260 |
my $item = $builder->build_sample_item(); |
| 261 |
my $item2 = $builder->build_sample_item({ biblionumber => $item->biblionumber }); |
| 262 |
my $item3 = $builder->build_sample_item({ biblionumber => $item->biblionumber }); |
| 263 |
|
| 264 |
my $patron = $builder->build_object({ |
| 265 |
class => 'Koha::Patrons', |
| 266 |
value => { |
| 267 |
branchcode => $item->homebranch |
| 268 |
} |
| 269 |
}); |
| 270 |
my $hold = $builder->build_object({ |
| 271 |
class => 'Koha::Holds', |
| 272 |
value => { |
| 273 |
biblionumber => $item->biblionumber, |
| 274 |
borrowernumber => $patron->id, |
| 275 |
suspend => 0, |
| 276 |
found => undef |
| 277 |
} |
| 278 |
}); |
| 279 |
|
| 280 |
Koha::CirculationRules->set_rules( |
| 281 |
{ |
| 282 |
branchcode => $item->homebranch, |
| 283 |
categorycode => undef, |
| 284 |
itemtype => $item->itype, |
| 285 |
rules => { |
| 286 |
issuelength => '14', |
| 287 |
lengthunit => 'days', |
| 288 |
reservesallowed => '99', |
| 289 |
holds_per_record => '1', |
| 290 |
} |
| 291 |
} |
| 292 |
); |
| 293 |
|
| 294 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds', 1 ); |
| 295 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration', 1 ); |
| 296 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 ); |
| 297 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'static' ); |
| 298 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged,itemlost,notforloan,withdrawn' ); |
| 299 |
|
| 300 |
my $data = C4::Circulation::checkHighHolds( $item , $patron ); |
| 301 |
ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if static decrease"); |
| 302 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' ); |
| 303 |
# 3 items on record, patron has 1 hold |
| 304 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 305 |
ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if dynamic decrease"); |
| 306 |
|
| 307 |
}; |
| 308 |
|
| 245 |
$schema->storage->txn_rollback(); |
309 |
$schema->storage->txn_rollback(); |
| 246 |
- |
|
|