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 => 72; |
10 |
use Test::More tests => 71; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
|
12 |
|
13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
Lines 391-416
AddReserve(
Link Here
|
391 |
} |
391 |
} |
392 |
); |
392 |
); |
393 |
is( |
393 |
is( |
394 |
CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'tooManyReserves', |
394 |
CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status}, 'noReservesAllowed', |
395 |
"cannot request item if policy that matches on item-level item type forbids it" |
395 |
"cannot request item if policy that matches on item-level item type forbids it" |
396 |
); |
396 |
); |
397 |
is( |
397 |
is( |
398 |
CanItemBeReserved( $borrowernumbers[0], $item->itemnumber, undef, { ignore_hold_counts => 1 })->{status}, 'tooManyReserves', |
398 |
CanItemBeReserved( $borrowernumbers[0], $item->itemnumber, undef, { ignore_hold_counts => 1 })->{status}, 'noReservesAllowed', |
399 |
"cannot request item if policy that matches on item-level item type forbids it even if ignoring counts" |
399 |
"cannot request item if policy that matches on item-level item type forbids it even if ignoring counts" |
400 |
); |
400 |
); |
401 |
|
401 |
|
402 |
$item->itype('CAN')->store; |
402 |
subtest 'CanItemBeReserved' => sub { |
403 |
ok( |
403 |
plan tests => 2; |
404 |
CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status} eq 'OK', |
|
|
405 |
"can request item if policy that matches on item type allows it" |
406 |
); |
407 |
|
404 |
|
408 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
405 |
my $itemtype_can = $builder->build({source => "Itemtype"})->{itemtype}; |
409 |
$item->itype(undef)->store; |
406 |
my $itemtype_cant = $builder->build({source => "Itemtype"})->{itemtype}; |
410 |
ok( |
407 |
my $itemtype_cant_record = $builder->build({source => "Itemtype"})->{itemtype}; |
411 |
CanItemBeReserved( $borrowernumbers[0], $item->itemnumber)->{status} eq 'tooManyReserves', |
408 |
|
412 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
409 |
Koha::CirculationRules->set_rules( |
413 |
); |
410 |
{ |
|
|
411 |
categorycode => undef, |
412 |
branchcode => undef, |
413 |
itemtype => $itemtype_cant, |
414 |
rules => { |
415 |
reservesallowed => 0, |
416 |
holds_per_record => 99, |
417 |
} |
418 |
} |
419 |
); |
420 |
Koha::CirculationRules->set_rules( |
421 |
{ |
422 |
categorycode => undef, |
423 |
branchcode => undef, |
424 |
itemtype => $itemtype_can, |
425 |
rules => { |
426 |
reservesallowed => 2, |
427 |
holds_per_record => 2, |
428 |
} |
429 |
} |
430 |
); |
431 |
Koha::CirculationRules->set_rules( |
432 |
{ |
433 |
categorycode => undef, |
434 |
branchcode => undef, |
435 |
itemtype => $itemtype_cant_record, |
436 |
rules => { |
437 |
reservesallowed => 0, |
438 |
holds_per_record => 0, |
439 |
} |
440 |
} |
441 |
); |
442 |
|
443 |
Koha::CirculationRules->set_rules( |
444 |
{ |
445 |
branchcode => $branch_1, |
446 |
itemtype => $itemtype_cant, |
447 |
rules => { |
448 |
holdallowed => 0, |
449 |
returnbranch => 'homebranch', |
450 |
} |
451 |
} |
452 |
); |
453 |
Koha::CirculationRules->set_rules( |
454 |
{ |
455 |
branchcode => $branch_1, |
456 |
itemtype => $itemtype_can, |
457 |
rules => { |
458 |
holdallowed => 1, |
459 |
returnbranch => 'homebranch', |
460 |
} |
461 |
} |
462 |
); |
463 |
|
464 |
subtest 'noReservesAllowed' => sub { |
465 |
plan tests => 5; |
466 |
|
467 |
my $biblionumber_cannot = $builder->build_sample_biblio({ itemtype => $itemtype_cant })->biblionumber; |
468 |
my $biblionumber_can = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
469 |
my $biblionumber_record_cannot = $builder->build_sample_biblio({ itemtype => $itemtype_cant_record })->biblionumber; |
470 |
|
471 |
my $itemnumber_1_can = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can, biblionumber => $biblionumber_cannot })->itemnumber; |
472 |
my $itemnumber_1_cannot = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_cant, biblionumber => $biblionumber_cannot })->itemnumber; |
473 |
my $itemnumber_2_can = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can, biblionumber => $biblionumber_can })->itemnumber; |
474 |
my $itemnumber_2_cannot = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_cant, biblionumber => $biblionumber_can })->itemnumber; |
475 |
my $itemnumber_3_cannot = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_cant_record, biblionumber => $biblionumber_record_cannot })->itemnumber; |
476 |
|
477 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
478 |
|
479 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
480 |
is( |
481 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot)->{status}, 'noReservesAllowed', |
482 |
"With item level set, rule from item must be picked (CANNOT)" |
483 |
); |
484 |
is( |
485 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can)->{status}, 'OK', |
486 |
"With item level set, rule from item must be picked (CAN)" |
487 |
); |
488 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
489 |
is( |
490 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can)->{status}, 'noReservesAllowed', |
491 |
"With biblio level set, rule from biblio must be picked (CANNOT)" |
492 |
); |
493 |
is( |
494 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot)->{status}, 'OK', |
495 |
"With biblio level set, rule from biblio must be picked (CAN)" |
496 |
); |
497 |
is( |
498 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_3_cannot)->{status}, 'noReservesAllowed', |
499 |
"When no holds allowed and no holds per record allowed should return noReservesAllowed" |
500 |
); |
501 |
}; |
502 |
|
503 |
subtest 'tooManyHoldsForThisRecord + tooManyReserves + itemAlreadyOnHold' => sub { |
504 |
plan tests => 7; |
505 |
|
506 |
my $biblionumber_1 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
507 |
my $itemnumber_11 = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can, biblionumber => $biblionumber_1 })->itemnumber; |
508 |
my $itemnumber_12 = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can, biblionumber => $biblionumber_1 })->itemnumber; |
509 |
my $biblionumber_2 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
510 |
my $itemnumber_21 = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can, biblionumber => $biblionumber_2 })->itemnumber; |
511 |
my $itemnumber_22 = $builder->build_sample_item({ homebranch => $branch_1, holdingbranch => $branch_1, itype => $itemtype_can, biblionumber => $biblionumber_2 })->itemnumber; |
512 |
|
513 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
514 |
|
515 |
# Biblio-level hold |
516 |
AddReserve({ |
517 |
branch => $branch_1, |
518 |
borrowernumber => $borrowernumbers[0], |
519 |
biblionumber => $biblionumber_1, |
520 |
}); |
521 |
for my $item_level ( 0..1 ) { |
522 |
t::lib::Mocks::mock_preference('item-level_itypes', $item_level); |
523 |
is( |
524 |
# FIXME This is not really correct, but CanItemBeReserved does not check if biblio-level holds already exist |
525 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_11)->{status}, 'OK', |
526 |
"A biblio-level hold already exists - another hold can be placed on a specific item item" |
527 |
); |
528 |
} |
529 |
|
530 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
531 |
# Item-level hold |
532 |
AddReserve({ |
533 |
branch => $branch_1, |
534 |
borrowernumber => $borrowernumbers[0], |
535 |
biblionumber => $biblionumber_1, |
536 |
itemnumber => $itemnumber_11, |
537 |
}); |
538 |
|
539 |
$dbh->do('DELETE FROM circulation_rules'); |
540 |
Koha::CirculationRules->set_rules( |
541 |
{ |
542 |
categorycode => undef, |
543 |
branchcode => undef, |
544 |
itemtype => undef, |
545 |
rules => { |
546 |
reservesallowed => 5, |
547 |
holds_per_record => 1, |
548 |
} |
549 |
} |
550 |
); |
551 |
is( |
552 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12)->{status}, 'tooManyHoldsForThisRecord', |
553 |
"A item-level hold already exists and holds_per_record=1, another hold cannot be placed on this record" |
554 |
); |
555 |
Koha::CirculationRules->set_rules( |
556 |
{ |
557 |
categorycode => undef, |
558 |
branchcode => undef, |
559 |
itemtype => undef, |
560 |
rules => { |
561 |
reservesallowed => 1, |
562 |
holds_per_record => 1, |
563 |
} |
564 |
} |
565 |
); |
566 |
is( |
567 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12)->{status}, 'tooManyHoldsForThisRecord', |
568 |
"A item-level hold already exists and holds_per_record=1 - tooManyHoldsForThisRecord has priority over tooManyReserves" |
569 |
); |
570 |
Koha::CirculationRules->set_rules( |
571 |
{ |
572 |
categorycode => undef, |
573 |
branchcode => undef, |
574 |
itemtype => undef, |
575 |
rules => { |
576 |
reservesallowed => 5, |
577 |
holds_per_record => 2, |
578 |
} |
579 |
} |
580 |
); |
581 |
is( |
582 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12)->{status}, 'OK', |
583 |
"A item-level hold already exists but holds_per_record=2- another item-level hold can be placed on this record" |
584 |
); |
585 |
|
586 |
AddReserve({ |
587 |
branch => $branch_1, |
588 |
borrowernumber => $borrowernumbers[0], |
589 |
biblionumber => $biblionumber_2, |
590 |
itemnumber => $itemnumber_21 |
591 |
}); |
592 |
Koha::CirculationRules->set_rules( |
593 |
{ |
594 |
categorycode => undef, |
595 |
branchcode => undef, |
596 |
itemtype => undef, |
597 |
rules => { |
598 |
reservesallowed => 2, |
599 |
holds_per_record => 2, |
600 |
} |
601 |
} |
602 |
); |
603 |
is( |
604 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_21)->{status}, 'itemAlreadyOnHold', |
605 |
"A item-level holds already exists on this item, itemAlreadyOnHold should be raised" |
606 |
); |
607 |
is( |
608 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_22)->{status}, 'tooManyReserves', |
609 |
"This patron has already placed reservesallowed holds, tooManyReserves should be raised" |
610 |
); |
611 |
}; |
612 |
}; |
414 |
|
613 |
|
415 |
|
614 |
|
416 |
# Test branch item rules |
615 |
# Test branch item rules |
417 |
- |
|
|