Lines 7-13
use t::lib::TestBuilder;
Link Here
|
7 |
|
7 |
|
8 |
use C4::Context; |
8 |
use C4::Context; |
9 |
|
9 |
|
10 |
use Test::More tests => 61; |
10 |
use Test::More tests => 59; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
|
12 |
|
13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
Lines 244-262
is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
Link Here
|
244 |
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
244 |
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
245 |
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) |
245 |
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) |
246 |
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber); |
246 |
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber); |
247 |
# Cleanup circulation rules |
247 |
delete_all_rules(); |
248 |
$dbh->do('DELETE FROM circulation_rules'); |
|
|
249 |
# $dbh->do( |
250 |
# q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) |
251 |
# VALUES (?, ?, ?, ?, ?)}, |
252 |
# {}, |
253 |
# '*', '*', '*', 25, 99 |
254 |
# ); |
255 |
$dbh->do( |
248 |
$dbh->do( |
256 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) |
249 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) |
257 |
VALUES (?, ?, ?, ?, ?)}, |
250 |
VALUES (?, ?, ?, ?, ?)}, |
258 |
{}, |
251 |
{}, |
259 |
'*', '*', 'CANNOT', 0, 99 |
252 |
'*', '*', '*', 25, 99 |
260 |
); |
253 |
); |
261 |
|
254 |
|
262 |
# make sure some basic sysprefs are set |
255 |
# make sure some basic sysprefs are set |
Lines 324-361
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
Link Here
|
324 |
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); |
317 |
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); |
325 |
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); |
318 |
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); |
326 |
|
319 |
|
327 |
# Regression test for bug 9532 |
320 |
subtest 'CanItemBeReserved' => sub { |
328 |
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' }); |
321 |
plan tests => 2; |
329 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber); |
|
|
330 |
AddReserve( |
331 |
$branch_1, |
332 |
$borrowernumbers[0], |
333 |
$biblio->biblionumber, |
334 |
'', |
335 |
1, |
336 |
); |
337 |
is( |
338 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', |
339 |
"cannot request item if policy that matches on item-level item type forbids it" |
340 |
); |
341 |
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); |
342 |
ok( |
343 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', |
344 |
"can request item if policy that matches on item type allows it" |
345 |
); |
346 |
|
322 |
|
347 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
323 |
delete_all_rules(); |
348 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber); |
324 |
|
349 |
ok( |
325 |
my $itemtype_can = $builder->build({source => "Itemtype"})->{itemtype}; |
350 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', |
326 |
my $itemtype_cant = $builder->build({source => "Itemtype"})->{itemtype}; |
351 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
327 |
my $itemtype_cant_record = $builder->build({source => "Itemtype"})->{itemtype}; |
352 |
); |
328 |
|
|
|
329 |
$dbh->do( |
330 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, |
331 |
'*', '*', $itemtype_cant, 0, 99 |
332 |
); |
333 |
$dbh->do( |
334 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, |
335 |
'*', '*', $itemtype_can, 2, 2 |
336 |
); |
337 |
$dbh->do( |
338 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, |
339 |
'*', '*', $itemtype_cant_record, 0, 0 |
340 |
); |
341 |
Koha::CirculationRules->set_rules( |
342 |
{ |
343 |
branchcode => $branch_1, |
344 |
itemtype => $itemtype_cant, |
345 |
categorycode => undef, |
346 |
rules => { |
347 |
holdallowed => 0, |
348 |
returnbranch => 'homebranch', |
349 |
} |
350 |
} |
351 |
); |
352 |
Koha::CirculationRules->set_rules( |
353 |
{ |
354 |
branchcode => $branch_1, |
355 |
itemtype => $itemtype_can, |
356 |
categorycode => undef, |
357 |
rules => { |
358 |
holdallowed => 1, |
359 |
returnbranch => 'homebranch', |
360 |
} |
361 |
} |
362 |
); |
363 |
|
364 |
subtest 'noReservesAllowed' => sub { |
365 |
plan tests => 5; |
366 |
|
367 |
my $biblionumber_cannot = $builder->build_sample_biblio({ itemtype => $itemtype_cant })->biblionumber; |
368 |
my $biblionumber_can = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
369 |
my $biblionumber_record_cannot = $builder->build_sample_biblio({ itemtype => $itemtype_cant_record })->biblionumber; |
370 |
my ( undef, undef, $itemnumber_1_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can } , $biblionumber_cannot); |
371 |
my ( undef, undef, $itemnumber_1_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_cant } , $biblionumber_cannot); |
372 |
|
373 |
my ( undef, undef, $itemnumber_2_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can } , $biblionumber_can); |
374 |
my ( undef, undef, $itemnumber_2_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_cant } , $biblionumber_can); |
375 |
|
376 |
my ( undef, undef, $itemnumber_3_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_cant_record } , $biblionumber_record_cannot); |
377 |
|
378 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
379 |
|
380 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
381 |
is( |
382 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot)->{status}, 'noReservesAllowed', |
383 |
"With item level set, rule from item must be picked (CANNOT)" |
384 |
); |
385 |
is( |
386 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can)->{status}, 'OK', |
387 |
"With item level set, rule from item must be picked (CAN)" |
388 |
); |
389 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
390 |
is( |
391 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can)->{status}, 'noReservesAllowed', |
392 |
"With biblio level set, rule from biblio must be picked (CANNOT)" |
393 |
); |
394 |
is( |
395 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot)->{status}, 'OK', |
396 |
"With biblio level set, rule from biblio must be picked (CAN)" |
397 |
); |
398 |
is( |
399 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_3_cannot)->{status}, 'noReservesAllowed', |
400 |
"When no holds allowed and no holds per record allowed should return noReservesAllowed" |
401 |
); |
402 |
}; |
403 |
|
404 |
subtest 'tooManyHoldsForThisRecord + tooManyReserves + itemAlreadyOnHold' => sub { |
405 |
plan tests => 7; |
406 |
|
407 |
my $biblionumber_1 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
408 |
my ( undef, undef, $itemnumber_11) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can } , $biblionumber_1); |
409 |
my ( undef, undef, $itemnumber_12) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can } , $biblionumber_1); |
410 |
my $biblionumber_2 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
411 |
my ( undef, undef, $itemnumber_21) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can } , $biblionumber_2); |
412 |
my ( undef, undef, $itemnumber_22) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can } , $biblionumber_2); |
413 |
|
414 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
415 |
|
416 |
# Biblio-level hold |
417 |
AddReserve( |
418 |
$branch_1, |
419 |
$borrowernumbers[0], |
420 |
$biblionumber_1, |
421 |
'', |
422 |
1, |
423 |
); |
424 |
for my $item_level ( 0..1 ) { |
425 |
t::lib::Mocks::mock_preference('item-level_itypes', $item_level); |
426 |
is( |
427 |
# FIXME This is not really correct, but CanItemBeReserved does not check if biblio-level holds already exist |
428 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_11)->{status}, 'OK', |
429 |
"A biblio-level hold already exists - another hold can be placed on a specific item item" |
430 |
); |
431 |
} |
432 |
|
433 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
434 |
# Item-level hold |
435 |
AddReserve( |
436 |
$branch_1, |
437 |
$borrowernumbers[0], |
438 |
$biblionumber_1, |
439 |
'', |
440 |
1, |
441 |
undef, undef, undef, undef, $itemnumber_11 |
442 |
); |
443 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=5, holds_per_record=1}); |
444 |
is( |
445 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12)->{status}, 'tooManyHoldsForThisRecord', |
446 |
"A item-level hold already exists and holds_per_record=1, another hold cannot be placed on this record" |
447 |
); |
448 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=1, holds_per_record=1}); |
449 |
is( |
450 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12)->{status}, 'tooManyHoldsForThisRecord', |
451 |
"A item-level hold already exists and holds_per_record=1 - tooManyHoldsForThisRecord has priority over tooManyReserves" |
452 |
); |
453 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=5, holds_per_record=2}); |
454 |
is( |
455 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12)->{status}, 'OK', |
456 |
"A item-level hold already exists but holds_per_record=2- another item-level hold can be placed on this record" |
457 |
); |
458 |
|
459 |
AddReserve( |
460 |
$branch_1, |
461 |
$borrowernumbers[0], |
462 |
$biblionumber_2, |
463 |
'', |
464 |
1, |
465 |
undef, undef, undef, undef, $itemnumber_21 |
466 |
); |
467 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=2, holds_per_record=2}); |
468 |
is( |
469 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_21)->{status}, 'itemAlreadyOnHold', |
470 |
"A item-level holds already exists on this item, itemAlreadyOnHold should be raised" |
471 |
); |
472 |
is( |
473 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_22)->{status}, 'tooManyReserves', |
474 |
"This patron has already placed reservesallowed holds, tooManyReserves should be raised" |
475 |
); |
476 |
}; |
477 |
}; |
353 |
|
478 |
|
354 |
|
479 |
|
355 |
# Test branch item rules |
480 |
# Test branch item rules |
356 |
|
481 |
|
357 |
$dbh->do('DELETE FROM issuingrules'); |
482 |
delete_all_rules(); |
358 |
$dbh->do('DELETE FROM circulation_rules'); |
|
|
359 |
$dbh->do( |
483 |
$dbh->do( |
360 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
484 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
361 |
VALUES (?, ?, ?, ?)}, |
485 |
VALUES (?, ?, ?, ?)}, |
Lines 701-707
subtest 'CanItemBeReserved / branch_not_in_hold_group' => sub {
Link Here
|
701 |
# Cleanup database |
825 |
# Cleanup database |
702 |
Koha::Holds->search->delete; |
826 |
Koha::Holds->search->delete; |
703 |
$dbh->do('DELETE FROM issues'); |
827 |
$dbh->do('DELETE FROM issues'); |
704 |
$dbh->do('DELETE FROM issuingrules'); |
828 |
delete_all_rules(); |
705 |
$dbh->do( |
829 |
$dbh->do( |
706 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
830 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
707 |
VALUES (?, ?, ?, ?)}, |
831 |
VALUES (?, ?, ?, ?)}, |
Lines 789-795
subtest 'CanItemBeReserved / branch_not_in_hold_group' => sub {
Link Here
|
789 |
'Patron cannot place hold because patron\'s home library is not part of hold group' |
913 |
'Patron cannot place hold because patron\'s home library is not part of hold group' |
790 |
); |
914 |
); |
791 |
|
915 |
|
792 |
# Cleanup default_cirt_rules |
916 |
# Cleanup default_circ_rules |
793 |
$dbh->do('DELETE FROM circulation_rules'); |
917 |
$dbh->do('DELETE FROM circulation_rules'); |
794 |
|
918 |
|
795 |
# Insert default circ rule to "any" for library 2 |
919 |
# Insert default circ rule to "any" for library 2 |
Lines 845-850
subtest 'CanItemBeReserved / branch_not_in_hold_group' => sub {
Link Here
|
845 |
categorycode => undef, |
969 |
categorycode => undef, |
846 |
rules => { |
970 |
rules => { |
847 |
holdallowed => 2, |
971 |
holdallowed => 2, |
|
|
972 |
holdsperrecord => 1, |
848 |
hold_fulfillment_policy => 'any', |
973 |
hold_fulfillment_policy => 'any', |
849 |
returnbranch => 'any' |
974 |
returnbranch => 'any' |
850 |
} |
975 |
} |
Lines 1114-1120
subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub {
Link Here
|
1114 |
'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for itemtype 2' |
1239 |
'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for itemtype 2' |
1115 |
); |
1240 |
); |
1116 |
|
1241 |
|
1117 |
# Cleanup default_branch_item_rules |
|
|
1118 |
$dbh->do('DELETE FROM circulation_rules'); |
1242 |
$dbh->do('DELETE FROM circulation_rules'); |
1119 |
|
1243 |
|
1120 |
# Insert branch item rule to "any" for itemtype 2 and library 2 |
1244 |
# Insert branch item rule to "any" for itemtype 2 and library 2 |
Lines 1161-1163
subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub {
Link Here
|
1161 |
|
1285 |
|
1162 |
$schema->storage->txn_rollback; |
1286 |
$schema->storage->txn_rollback; |
1163 |
}; |
1287 |
}; |
1164 |
- |
1288 |
|
|
|
1289 |
sub delete_all_rules { |
1290 |
my $dbh = C4::Context->dbh; |
1291 |
$dbh->do('DELETE FROM issuingrules'); |
1292 |
$dbh->do('DELETE FROM circulation_rules'); |
1293 |
} |