|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 66; |
20 |
use Test::More tests => 71; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
|
23 |
|
|
Lines 529-541
AddReserve(
Link Here
|
| 529 |
priority => 1, |
529 |
priority => 1, |
| 530 |
} |
530 |
} |
| 531 |
); |
531 |
); |
|
|
532 |
|
| 532 |
my (undef, $canres, undef) = CheckReserves($item->itemnumber); |
533 |
my (undef, $canres, undef) = CheckReserves($item->itemnumber); |
| 533 |
|
534 |
|
| 534 |
is( CanReserveBeCanceledFromOpac(), undef, |
535 |
is( CanReserveBeCanceledFromOpac(), undef, |
| 535 |
'CanReserveBeCanceledFromOpac should return undef if called without any parameter' |
536 |
'CanReserveBeCanceledFromOpac should return undef if called without any parameter' |
| 536 |
); |
537 |
); |
| 537 |
is( |
538 |
is( |
| 538 |
CanReserveBeCanceledFromOpac( $canres->{resserve_id} ), |
539 |
CanReserveBeCanceledFromOpac( $canres->{reserve_id} ), |
| 539 |
undef, |
540 |
undef, |
| 540 |
'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id' |
541 |
'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id' |
| 541 |
); |
542 |
); |
|
Lines 724-790
MoveReserve( $item->itemnumber, $borrowernumber );
Link Here
|
| 724 |
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days'); |
725 |
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days'); |
| 725 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
726 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
| 726 |
|
727 |
|
| 727 |
|
728 |
#Test bug 23172. Check when returning an item that any patron category/item type combinations that forbid reservation are skipped over when allocating the item to a bib-level hold |
| 728 |
|
729 |
$dbh->do('DELETE FROM circulation_rules'); |
| 729 |
|
|
|
| 730 |
|
| 731 |
|
| 732 |
#Test bug 23172. Check when returning an item that any patron category/item type combinations that forbid reservation are skipped over |
| 733 |
#when allocating the item to a bib-level hold |
| 734 |
$dbh->do('DELETE FROM issuingrules'); |
| 735 |
|
| 736 |
#Create two new patrons |
| 737 |
my $patronnumcat1 = Koha::Patron->new({branchcode => $branch_1, categorycode => $category_1})->store->borrowernumber; |
| 738 |
my $patronnumcat2 = Koha::Patron->new({branchcode => $branch_1, categorycode => $category_2})->store->borrowernumber; |
| 739 |
|
| 740 |
#Create a new biblio record |
| 741 |
my $bibnum3 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber; |
| 742 |
|
730 |
|
| 743 |
#Create a second item type |
731 |
#Create a second item type |
| 744 |
my $itemtype2 = $builder->build({ source => 'Itemtype', value => { notforloan => undef } } )->{itemtype}; |
732 |
my $itemtype2 = $builder->build({ source => 'Itemtype', value => { notforloan => undef } } )->{itemtype}; |
| 745 |
|
733 |
|
| 746 |
# Create an item from new itemtype |
|
|
| 747 |
my ( $item_bibnum2, $item_bibitemnum2, $itemnumber2 ) = AddItem( |
| 748 |
{ homebranch => $branch_1, |
| 749 |
holdingbranch => $branch_1, |
| 750 |
itype => $itemtype2, |
| 751 |
barcode => 'bug23172_CPL' |
| 752 |
}, |
| 753 |
$bibnum3 |
| 754 |
); |
| 755 |
|
| 756 |
#Make a general All patron category/all item type rule |
734 |
#Make a general All patron category/all item type rule |
| 757 |
$dbh->do( |
735 |
Koha::CirculationRules->set_rules( |
| 758 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record) |
736 |
{ |
| 759 |
VALUES (?, ?, ?, ?, ?, ?)}, |
737 |
branchcode => undef, |
| 760 |
{}, |
738 |
categorycode => undef, |
| 761 |
'*', '*', '*', 25, 1, 1 |
739 |
itemtype => undef, |
|
|
740 |
rules => { |
| 741 |
reservesallowed => 25, |
| 742 |
holds_per_record => 1, |
| 743 |
holds_per_day => 1, |
| 744 |
} |
| 745 |
} |
| 762 |
); |
746 |
); |
| 763 |
|
747 |
|
| 764 |
#When patron category = $category_1 and itemtype = $itemtype1 then reservesallowed, holds_per_day and holds_per_record are 0 |
748 |
#When patron category = $category_1 and itemtype = $itemtype2 then reservesallowed, holds_per_day and holds_per_record are 0 |
| 765 |
$dbh->do( |
749 |
Koha::CirculationRules->set_rules( |
| 766 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record) |
750 |
{ |
| 767 |
VALUES (?, ?, ?, ?, ?, ?)}, |
751 |
branchcode => $branch_1, |
| 768 |
{}, |
752 |
categorycode => $category_1, |
| 769 |
$category_1, $branch_1, $itemtype2, 0, 1, 1 |
753 |
itemtype => $itemtype2, |
|
|
754 |
rules => { |
| 755 |
reservesallowed => 0, |
| 756 |
holds_per_record => 0, |
| 757 |
holds_per_day => 0, |
| 758 |
} |
| 759 |
} |
| 770 |
); |
760 |
); |
| 771 |
|
761 |
|
| 772 |
#When patron category = $category_2 and itemtype = $itemtype2 then reservesallowed, holds_per_day and holds_per_record are 1 |
762 |
#When patron category = $category_2 and itemtype = $itemtype2 then reservesallowed, holds_per_day and holds_per_record are 1 |
| 773 |
$dbh->do( |
763 |
Koha::CirculationRules->set_rules( |
| 774 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record) |
764 |
{ |
| 775 |
VALUES (?, ?, ?, ?, ?, ?)}, |
765 |
branchcode => $branch_1, |
| 776 |
{}, |
766 |
categorycode => $category_2, |
| 777 |
$category_2, $branch_1, $itemtype2, 1, 1, 1 |
767 |
itemtype => $itemtype2, |
|
|
768 |
rules => { |
| 769 |
reservesallowed => 1, |
| 770 |
holds_per_record => 1, |
| 771 |
holds_per_day => 1, |
| 772 |
} |
| 773 |
} |
| 774 |
); |
| 775 |
|
| 776 |
#When patron category = $category_1 and itemtype = $itemtype2 AND different branch, then reservesallowed, holds_per_day and holds_per_record are 0 |
| 777 |
Koha::CirculationRules->set_rules( |
| 778 |
{ |
| 779 |
branchcode => $branch_2, |
| 780 |
categorycode => $category_1, |
| 781 |
itemtype => $itemtype2, |
| 782 |
rules => { |
| 783 |
reservesallowed => 0, |
| 784 |
holds_per_record => 0, |
| 785 |
holds_per_day => 0, |
| 786 |
} |
| 787 |
} |
| 778 |
); |
788 |
); |
| 779 |
|
789 |
|
|
|
790 |
#Create a new biblio record |
| 791 |
my $bibnum3 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber; |
| 792 |
|
| 793 |
# Create an item from new itemtype |
| 794 |
my $item2 = $builder->build_sample_item({ |
| 795 |
homebranch => $branch_1, |
| 796 |
holdingbranch => $branch_1, |
| 797 |
itype => $itemtype2, |
| 798 |
barcode => 'bug23172_CPL', |
| 799 |
biblionumber => $bibnum3 |
| 800 |
}); |
| 801 |
|
| 802 |
#Create two new patrons |
| 803 |
my $patronnumcat1 = Koha::Patron->new({branchcode => $branch_1, categorycode => $category_1})->store->borrowernumber; |
| 804 |
my $patronnumcat2 = Koha::Patron->new({branchcode => $branch_1, categorycode => $category_2})->store->borrowernumber; |
| 805 |
my $patronnumcat3 = Koha::Patron->new({branchcode => $branch_2, categorycode => $category_1})->store->borrowernumber; |
| 806 |
|
| 780 |
#Remove existing reserves |
807 |
#Remove existing reserves |
| 781 |
$dbh->do("DELETE FROM reserves"); |
808 |
$dbh->do("DELETE FROM reserves"); |
| 782 |
|
809 |
|
| 783 |
#Create Bib-level hold for borrower who has a patron category of $category_2 |
|
|
| 784 |
my $reserveid2 = AddReserve($branch_1, $patronnumcat2, $bibnum3); |
| 785 |
|
| 786 |
#Bib-level hold for borrower who has a patron category of $category_1 |
810 |
#Bib-level hold for borrower who has a patron category of $category_1 |
| 787 |
my $reserveid1 = AddReserve($branch_1, $patronnumcat1, $bibnum3 ); |
811 |
my $reserveid1 = AddReserve({ |
|
|
812 |
branchcode => $branch_1, |
| 813 |
borrowernumber => $patronnumcat1, |
| 814 |
biblionumber => $bibnum3 |
| 815 |
}); |
| 816 |
|
| 817 |
#Create Bib-level hold for borrower who has a patron category of $category_2 |
| 818 |
my $reserveid2 = AddReserve({ |
| 819 |
branchcode => $branch_1, |
| 820 |
borrowernumber => $patronnumcat2, |
| 821 |
biblionumber => $bibnum3 |
| 822 |
}); |
| 788 |
|
823 |
|
| 789 |
#Check bib-level hold priority and confirm hold made by patronnumcat1 (who fits into issuingrule with reserveallowed = 0) has first priority |
824 |
#Check bib-level hold priority and confirm hold made by patronnumcat1 (who fits into issuingrule with reserveallowed = 0) has first priority |
| 790 |
my $reserve1 = Koha::Holds->find($reserveid1); |
825 |
my $reserve1 = Koha::Holds->find($reserveid1); |
|
Lines 793-819
is( $reserve1->priority, 1, 'patronnumcat1 reserve is first priority');
Link Here
|
| 793 |
my $reserve2 = Koha::Holds->find($reserveid2); |
828 |
my $reserve2 = Koha::Holds->find($reserveid2); |
| 794 |
is( $reserve2->priority, 2, 'patronnumcat2 reserve is second priority'); |
829 |
is( $reserve2->priority, 2, 'patronnumcat2 reserve is second priority'); |
| 795 |
|
830 |
|
| 796 |
#Return the item |
831 |
#Test with ReservesControlBranch system preference set to ItemHomeLibrary |
|
|
832 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
| 833 |
|
| 834 |
# Reserve 1 should be skipped because the circ rule for that patron's category does not allow reserves |
| 797 |
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1); |
835 |
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1); |
| 798 |
|
836 |
|
| 799 |
#First priority hold is skipped as issuingrule is checked and the first hold does not respect issuingrules (as one of the three fields: reservesallowed, holds_per_day is 0) therefore not allocating item to this bib-level hold |
837 |
#First priority hold is skipped as issuingrule is checked and the first hold does not respect issuingrules (as one of the three fields: reservesallowed, holds_per_day is 0) therefore not allocating item to this bib-level hold |
| 800 |
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat2,'Skip allocating item to first priority hold as it does not respect issuingrules instead allocate to next valid hold (bug 23172)'); |
838 |
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat2,'First priority hold is skipped because circulation rules disallow holds for this patron category, so item is allocated to next hold.'); |
| 801 |
|
839 |
|
| 802 |
#Remove and re-add the issuing rule that prevented patronnumcat1 bib-level hold from being allocated upon item return making reservesallowed, holds_per_day and holds_per_record > 0 |
840 |
#Remove existing reserves |
| 803 |
$dbh->do(q{DELETE FROM issuingrules WHERE categorycode = ? AND branchcode = ? AND itemtype = ?}, |
841 |
$dbh->do("DELETE FROM reserves"); |
| 804 |
{}, |
842 |
|
| 805 |
$category_1, $branch_1, $itemtype2 |
843 |
#Bib-level hold for borrower who has a patron category of $category_1 |
| 806 |
); |
844 |
my $reserveid3 = AddReserve({ |
| 807 |
$dbh->do( |
845 |
branchcode => $branch_1, |
| 808 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_day, holds_per_record) |
846 |
borrowernumber => $patronnumcat3, |
| 809 |
VALUES (?, ?, ?, ?, ?, ?)}, |
847 |
biblionumber => $bibnum3 |
| 810 |
{}, |
848 |
}); |
| 811 |
$category_1, $branch_1, $itemtype2, 1, 1, 1 |
849 |
|
|
|
850 |
#Create Bib-level hold for borrower who has a patron category of $category_2 |
| 851 |
my $reserveid4 = AddReserve({ |
| 852 |
branchcode => $branch_1, |
| 853 |
borrowernumber => $patronnumcat2, |
| 854 |
biblionumber => $bibnum3 |
| 855 |
}); |
| 856 |
|
| 857 |
#Test with ReservesControlBranch system preference set to PatronLibrary |
| 858 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'PatronLibrary'); |
| 859 |
|
| 860 |
# Reserve 1 should be skipped because the circ rule for that patron's library does not allow reserves |
| 861 |
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1); |
| 862 |
|
| 863 |
#First priority hold is skipped as issuingrule is checked and the first hold does not respect issuingrules (as one of the three fields: reservesallowed, holds_per_day is 0) therefore not allocating item to this bib-level hold |
| 864 |
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat2,'First priority hold is skipped because circulation rules disallow holds for this branch, so item is allocated to next hold.'); |
| 865 |
|
| 866 |
# Update the circulation rule that prevented patronnumcat3 bib-level hold from being allocated upon item return making reservesallowed, holds_per_day and holds_per_record > 0 |
| 867 |
Koha::CirculationRules->set_rules( |
| 868 |
{ |
| 869 |
branchcode => $branch_2, |
| 870 |
categorycode => $category_1, |
| 871 |
itemtype => $itemtype2, |
| 872 |
rules => { |
| 873 |
reservesallowed => 1, |
| 874 |
holds_per_record => 1, |
| 875 |
holds_per_day => 1, |
| 876 |
} |
| 877 |
} |
| 812 |
); |
878 |
); |
| 813 |
|
879 |
|
| 814 |
#Return the item again and notice this time it is allocated to the bib-level hold made by patronnumcat1 |
880 |
#Return the item again and notice this time it is allocated to the bib-level hold made by patronnumcat1 |
| 815 |
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1); |
881 |
(undef, $messages, undef, undef) = AddReturn('bug23172_CPL', $branch_1); |
| 816 |
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat1,'Skip allocating item to first priority hold as it does not respect issuingrules instead allocate to next valid hold (bug 23172)'); |
882 |
is( $messages->{ResFound}->{borrowernumber}, $patronnumcat3,'Skip allocating item to first priority hold as it does not respect issuingrules instead allocate to next valid hold (bug 23172)'); |
| 817 |
|
883 |
|
| 818 |
$cache->clear_from_cache("MarcStructure-0-$frameworkcode"); |
884 |
$cache->clear_from_cache("MarcStructure-0-$frameworkcode"); |
| 819 |
$cache->clear_from_cache("MarcStructure-1-$frameworkcode"); |
885 |
$cache->clear_from_cache("MarcStructure-1-$frameworkcode"); |
| 820 |
- |
|
|