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