Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 9; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
25 |
use C4::Circulation; |
25 |
use C4::Circulation; |
Lines 500-505
subtest 'get_items_that_can_fill' => sub {
Link Here
|
500 |
|
500 |
|
501 |
}; |
501 |
}; |
502 |
|
502 |
|
|
|
503 |
subtest 'remaining_holds_total' => sub { |
504 |
plan tests => 3; |
505 |
|
506 |
my $biblio = $builder->build_sample_biblio; |
507 |
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
508 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
509 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
510 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
511 |
my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
512 |
|
513 |
t::lib::Mocks::mock_userenv({ patron => $patron_1 }); |
514 |
t::lib::Mocks::mock_preference('maxreserves', 4); |
515 |
Koha::CirculationRules->set_rules({ |
516 |
itemtype => $itype_1->itemtype, |
517 |
branchcode => undef, |
518 |
categorycode => $patron_1->categorycode, |
519 |
rules => { |
520 |
reservesallowed => 5, |
521 |
}, |
522 |
}); |
523 |
|
524 |
my $reserve_id_1 = C4::Reserves::AddReserve( |
525 |
{ |
526 |
borrowernumber => $patron_1->borrowernumber, |
527 |
biblionumber => $biblio->biblionumber, |
528 |
priority => 1, |
529 |
itemnumber => $item_1->itemnumber, |
530 |
} |
531 |
); |
532 |
|
533 |
my $reserve_id_2 = C4::Reserves::AddReserve( |
534 |
{ |
535 |
borrowernumber => $patron_1->borrowernumber, |
536 |
biblionumber => $biblio->biblionumber, |
537 |
priority => 1, |
538 |
itemnumber => $item_2->itemnumber, |
539 |
} |
540 |
); |
541 |
|
542 |
my $reserve_id_3 = C4::Reserves::AddReserve( |
543 |
{ |
544 |
borrowernumber => $patron_1->borrowernumber, |
545 |
biblionumber => $biblio->biblionumber, |
546 |
priority => 1, |
547 |
itemnumber => $item_3->itemnumber, |
548 |
} |
549 |
); |
550 |
|
551 |
my $reserve_id_4 = C4::Reserves::AddReserve( |
552 |
{ |
553 |
borrowernumber => $patron_1->borrowernumber, |
554 |
biblionumber => $biblio->biblionumber, |
555 |
priority => 1, |
556 |
itemnumber => undef, |
557 |
} |
558 |
); |
559 |
|
560 |
my $remaining_holds_total = Koha::Holds->remaining_holds_total; |
561 |
is( $remaining_holds_total, 0, "No patron was passed to calculate their holds" ); |
562 |
|
563 |
$remaining_holds_total = Koha::Holds->remaining_holds_total({ patron => $patron_1, biblio => $biblio }); |
564 |
is( $remaining_holds_total, 0, "Patron has reached maxreserves system preference maximum holds" ); |
565 |
|
566 |
t::lib::Mocks::mock_preference('maxreserves', 5); |
567 |
|
568 |
$remaining_holds_total = Koha::Holds->remaining_holds_total({ patron => $patron_1, biblio => $biblio }); |
569 |
is( $remaining_holds_total, 1, "Patron has one more allowed hold based on reservesallowed circulation rule" ); |
570 |
}; |
571 |
|
572 |
subtest 'remaining_holds_record' => sub { |
573 |
plan tests => 3; |
574 |
|
575 |
my $biblio = $builder->build_sample_biblio; |
576 |
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
577 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
578 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
579 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
580 |
my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
581 |
|
582 |
t::lib::Mocks::mock_userenv({ patron => $patron_1 }); |
583 |
t::lib::Mocks::mock_preference('maxreserves', 10); |
584 |
Koha::CirculationRules->set_rules({ |
585 |
itemtype => $itype_1->itemtype, |
586 |
branchcode => undef, |
587 |
categorycode => $patron_1->categorycode, |
588 |
rules => { |
589 |
holds_per_record => 3, |
590 |
}, |
591 |
}); |
592 |
|
593 |
my $reserve_id_1 = C4::Reserves::AddReserve( |
594 |
{ |
595 |
borrowernumber => $patron_1->borrowernumber, |
596 |
biblionumber => $biblio->biblionumber, |
597 |
priority => 1, |
598 |
itemnumber => $item_1->itemnumber, |
599 |
} |
600 |
); |
601 |
|
602 |
my $reserve_id_2 = C4::Reserves::AddReserve( |
603 |
{ |
604 |
borrowernumber => $patron_1->borrowernumber, |
605 |
biblionumber => $biblio->biblionumber, |
606 |
priority => 1, |
607 |
itemnumber => $item_2->itemnumber, |
608 |
} |
609 |
); |
610 |
|
611 |
my $reserve_id_3 = C4::Reserves::AddReserve( |
612 |
{ |
613 |
borrowernumber => $patron_1->borrowernumber, |
614 |
biblionumber => $biblio->biblionumber, |
615 |
priority => 1, |
616 |
itemnumber => $item_3->itemnumber, |
617 |
} |
618 |
); |
619 |
|
620 |
my $remaining_holds_record = Koha::Holds->remaining_holds_record; |
621 |
is( $remaining_holds_record, 0, "No patron or biblio passed" ); |
622 |
|
623 |
$remaining_holds_record = Koha::Holds->remaining_holds_record({ patron => $patron_1, biblio => $biblio }); |
624 |
is( $remaining_holds_record, 0, "Patron has reached holds_per_record circulation rule maximum holds" ); |
625 |
|
626 |
Koha::Holds->find( $reserve_id_3 )->delete; |
627 |
|
628 |
$remaining_holds_record = Koha::Holds->remaining_holds_record({ patron => $patron_1, biblio => $biblio }); |
629 |
is( $remaining_holds_record, 1, "Patron has one more allowed hold on this record based on reservesallowed circulation rule" ); |
630 |
}; |
631 |
|
632 |
subtest 'remaining_holds_today' => sub { |
633 |
plan tests => 3; |
634 |
|
635 |
my $biblio = $builder->build_sample_biblio; |
636 |
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
637 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
638 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
639 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype }); |
640 |
my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
641 |
|
642 |
t::lib::Mocks::mock_userenv({ patron => $patron_1 }); |
643 |
t::lib::Mocks::mock_preference('maxreserves', 10); |
644 |
Koha::CirculationRules->set_rules({ |
645 |
itemtype => $itype_1->itemtype, |
646 |
branchcode => undef, |
647 |
categorycode => $patron_1->categorycode, |
648 |
rules => { |
649 |
holds_per_day => 5, |
650 |
}, |
651 |
}); |
652 |
|
653 |
my $reserve_id_1 = C4::Reserves::AddReserve( |
654 |
{ |
655 |
borrowernumber => $patron_1->borrowernumber, |
656 |
biblionumber => $biblio->biblionumber, |
657 |
priority => 1, |
658 |
itemnumber => $item_1->itemnumber, |
659 |
} |
660 |
); |
661 |
|
662 |
my $reserve_id_2 = C4::Reserves::AddReserve( |
663 |
{ |
664 |
borrowernumber => $patron_1->borrowernumber, |
665 |
biblionumber => $biblio->biblionumber, |
666 |
priority => 1, |
667 |
itemnumber => $item_2->itemnumber, |
668 |
} |
669 |
); |
670 |
|
671 |
my $reserve_id_3 = C4::Reserves::AddReserve( |
672 |
{ |
673 |
borrowernumber => $patron_1->borrowernumber, |
674 |
biblionumber => $biblio->biblionumber, |
675 |
priority => 1, |
676 |
itemnumber => $item_3->itemnumber, |
677 |
} |
678 |
); |
679 |
|
680 |
my $reserve_id_4 = C4::Reserves::AddReserve( |
681 |
{ |
682 |
borrowernumber => $patron_1->borrowernumber, |
683 |
biblionumber => $biblio->biblionumber, |
684 |
priority => 1, |
685 |
itemnumber => undef, |
686 |
} |
687 |
); |
688 |
|
689 |
my $remaining_holds_total = Koha::Holds->remaining_holds_today; |
690 |
is( $remaining_holds_total, 0, "No patron was passed to calculate their holds" ); |
691 |
|
692 |
$remaining_holds_total = Koha::Holds->remaining_holds_today({ patron => $patron_1, biblio => $biblio }); |
693 |
is( $remaining_holds_total, 1, "Patron has one more allowed hold based on holds_per_day circulation rule" ); |
694 |
}; |
695 |
|
503 |
$schema->storage->txn_rollback; |
696 |
$schema->storage->txn_rollback; |
504 |
|
697 |
|
505 |
1; |
698 |
1; |
506 |
- |
|
|