From 2898375444876949a2a0841b5300d2850c665b05 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 14 Mar 2018 13:43:29 +0000 Subject: [PATCH] Bug 16787: (follow-up) Return noReservesAllowed if 0 holds per record To test: 1 - Set 'Holds per record' to 0 for some itemtype/patorn combination 2 - Attempt to plac a hold 3 - Will see 'Too many..' 4 - Apply patch 5 - Try again 6 - Should now see 'No holds..' 7 - prove -v t/db_dependent/Holds.t --- C4/Reserves.pm | 3 +++ t/db_dependent/Holds.t | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 4e9a1b9..b518e7e 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -363,6 +363,9 @@ sub CanItemBeReserved { found => undef, # Found holds don't count against a patron's holds limit } ); + if ( $holds_per_record == 0 ) { + return "noReservesAllowed"; + } if ( $holds->count() >= $holds_per_record ) { return "tooManyHoldsForThisRecord"; } diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 6829aff..6b91527 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -331,9 +331,13 @@ subtest 'CanItemBeReserved' => sub { q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, '*', '*', 'CAN', 2, 2 ); + $dbh->do( + q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, + '*', '*', 'CANNOT_RECORD', 0, 0 + ); subtest 'noReservesAllowed' => sub { - plan tests => 4; + plan tests => 5; my ( $biblionumber_cannot ) = create_helper_biblio('CANNOT'); my ( undef, undef, $itemnumber_1_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_cannot); @@ -343,6 +347,9 @@ subtest 'CanItemBeReserved' => sub { my ( undef, undef, $itemnumber_2_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_can); my ( undef, undef, $itemnumber_2_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblionumber_can); + my ($biblionumber_record_cannot) = create_helper_biblio('CANNOT_RECORD'); + my ( undef, undef, $itemnumber_3_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT_RECORD' } , $biblionumber_record_cannot); + Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; t::lib::Mocks::mock_preference('item-level_itypes', 1); @@ -363,6 +370,10 @@ subtest 'CanItemBeReserved' => sub { CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot), 'OK', "With biblio level set, rule from biblio must be picked (CAN)" ); + is( + CanItemBeReserved( $borrowernumbers[0], $itemnumber_3_cannot), 'noReservesAllowed', + "When no holds allowed and no holds per record allowed should return noReservesAllowed" + ); }; subtest 'tooManyHoldsForThisRecord + tooManyReserves + itemAlreadyOnHold' => sub { -- 2.1.4