|
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 => 22; |
| 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-135
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 |
|
|
Lines 161-168
$data = C4::Circulation::checkHighHolds( $item, $patron );
Link Here
|
| 161 |
is( $data->{exceeded}, 0, "Should not exceed threshold" ); |
161 |
is( $data->{exceeded}, 0, "Should not exceed threshold" ); |
| 162 |
|
162 |
|
| 163 |
|
163 |
|
| 164 |
# Place 6 more holds - patrons 5,6,7,8,9,10 |
164 |
# Place 7 more holds - patrons 5,6,7,8,9,10,11 |
| 165 |
for my $i ( 5 .. 10 ) { |
165 |
for my $i ( 5 .. 11 ) { |
| 166 |
my $patron = $patrons[$i]; |
166 |
my $patron = $patrons[$i]; |
| 167 |
my $hold = Koha::Hold->new( |
167 |
my $hold = Koha::Hold->new( |
| 168 |
{ |
168 |
{ |
|
Lines 173-178
for my $i ( 5 .. 10 ) {
Link Here
|
| 173 |
)->store(); |
173 |
)->store(); |
| 174 |
} |
174 |
} |
| 175 |
|
175 |
|
|
|
176 |
# Note in counts below, patron's own hold is not counted |
| 177 |
|
| 176 |
# 12 holds, threshold is 1 over 10 holdable items = 11 |
178 |
# 12 holds, threshold is 1 over 10 holdable items = 11 |
| 177 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
179 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 178 |
is( $data->{exceeded}, 1, "Should exceed threshold of 1" ); |
180 |
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 ); |
244 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 243 |
is( $data->{duration}, 2, "Circulation rules override system preferences" ); |
245 |
is( $data->{duration}, 2, "Circulation rules override system preferences" ); |
| 244 |
|
246 |
|
|
|
247 |
|
| 248 |
subtest "Test patron's own holds do not count towards HighHolds count" => sub { |
| 249 |
|
| 250 |
plan tests => 2; |
| 251 |
|
| 252 |
my $item = $builder->build_sample_item(); |
| 253 |
my $item2 = $builder->build_sample_item({ biblionumber => $item->biblionumber }); |
| 254 |
my $item3 = $builder->build_sample_item({ biblionumber => $item->biblionumber }); |
| 255 |
|
| 256 |
my $patron = $builder->build_object({ |
| 257 |
class => 'Koha::Patrons', |
| 258 |
value => { |
| 259 |
branchcode => $item->homebranch |
| 260 |
} |
| 261 |
}); |
| 262 |
my $hold = $builder->build_object({ |
| 263 |
class => 'Koha::Holds', |
| 264 |
value => { |
| 265 |
biblionumber => $item->biblionumber, |
| 266 |
borrowernumber => $patron->id, |
| 267 |
suspend => 0, |
| 268 |
found => undef |
| 269 |
} |
| 270 |
}); |
| 271 |
|
| 272 |
Koha::CirculationRules->set_rules( |
| 273 |
{ |
| 274 |
branchcode => $item->homebranch, |
| 275 |
categorycode => undef, |
| 276 |
itemtype => $item->itype, |
| 277 |
rules => { |
| 278 |
issuelength => '14', |
| 279 |
lengthunit => 'days', |
| 280 |
reservesallowed => '99', |
| 281 |
holds_per_record => '1', |
| 282 |
} |
| 283 |
} |
| 284 |
); |
| 285 |
|
| 286 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds', 1 ); |
| 287 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration', 1 ); |
| 288 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 ); |
| 289 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'static' ); |
| 290 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsIgnoreStatuses', 'damaged,itemlost,notforloan,withdrawn' ); |
| 291 |
|
| 292 |
my $data = C4::Circulation::checkHighHolds( $item , $patron ); |
| 293 |
ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if static decrease"); |
| 294 |
t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' ); |
| 295 |
# 3 items on record, patron has 1 hold |
| 296 |
$data = C4::Circulation::checkHighHolds( $item, $patron ); |
| 297 |
ok( !$data->{exceeded}, "Patron's hold on the record does not limit their own circulation if dynamic decrease"); |
| 298 |
|
| 299 |
}; |
| 300 |
|
| 245 |
$schema->storage->txn_rollback(); |
301 |
$schema->storage->txn_rollback(); |
| 246 |
- |
|
|