From 16b1e24580e1c996187c23b91978a54341db1f02 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 6 Apr 2021 13:21:50 +0000 Subject: [PATCH] Bug 28078: (follow-up) Add param check to 'itemAlreadyOnHold' test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Joonas Kylmälä Signed-off-by: Jonathan Druart (cherry picked from commit a620c1bb116d82ea27934f643789a84f5c002a2b) Signed-off-by: Fridolin Somers (cherry picked from commit 20ce0fdab0896c2f95b49f655c93052f87baeff6) Signed-off-by: Andrew Fuerste-Henry --- C4/Reserves.pm | 2 +- t/db_dependent/Holds.t | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 9367e836d3..bb510f1bc4 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -380,7 +380,7 @@ sub CanItemBeReserved { # Check that the patron doesn't have an item level hold on this item already return { status =>'itemAlreadyOnHold' } - if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count(); + if ( !$params->{ignore_hold_counts} && Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count() ); my $controlbranch = C4::Context->preference('ReservesControlBranch'); diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index b98292afc8..3a8733aca9 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -7,7 +7,7 @@ use t::lib::TestBuilder; use C4::Context; -use Test::More tests => 69; +use Test::More tests => 71; use MARC::Record; use C4::Biblio; @@ -367,6 +367,14 @@ t::lib::Mocks::mock_preference( 'SkipHoldTrapOnNotForLoanValue', '-1' ); ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for item with notforloan value matching SkipHoldTrapOnNotForLoanValue" ); t::lib::Mocks::mock_preference( 'SkipHoldTrapOnNotForLoanValue', '-1|1' ); ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for item with notforloan value matching SkipHoldTrapOnNotForLoanValue" ); +is( + CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'itemAlreadyOnHold', + "cannot request item that you have already reservedd" +); +is( + CanItemBeReserved( $borrowernumbers[0], $item->itemnumber, undef, { ignore_hold_counts => 1 })->{status}, 'OK', + "can request item if we are not checking holds counts, but only if policy allows or forbids it" +); $hold->delete(); # Regression test for bug 9532 -- 2.39.5