From a620c1bb116d82ea27934f643789a84f5c002a2b 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 --- 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 da5b75fc00..dc99bc1cbb 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -394,7 +394,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() ); # Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set) if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions') diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index ddd8ccd941..285d4d3663 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 => 70; +use Test::More tests => 72; use MARC::Record; use C4::Biblio; @@ -369,6 +369,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