From f35924400279fea998b18b1f9e18cbecc5df6011 Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Wed, 29 Mar 2023 13:43:28 +0000 Subject: [PATCH] Bug 33200: (follow-up) Adding Unit test, renaming _Removereserve Signed-off-by: Phil Ringnalda --- C4/Reserves.pm | 8 ++++---- t/db_dependent/Reserves.t | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 7e3b4692d4..e1191dea2f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1757,19 +1757,19 @@ sub _Findgroupreserve { return @results; } -=head2 _Removereserve +=head2 _FilterHoldsForIndependentBranches - @reserves = &_Removereserve( @reserves ); + @reserves = &_FilterHoldsForIndependentBranches( @reserves ); Check transfers is allowed from system preference and remove the reserves made from other branches -C<&_Removereserve> returns : +C<&_FilterHoldsForIndependentBranches> returns : C<@results> is an array of references-to-hash whose keys are mostly fields from the reserves table of the Koha database, plus =cut -sub _Removereserve { +sub _FilterHoldsForIndependentBranches { my ( @reserves) = @_; if ( C4::Context->preference("IndependentBranchesTransfers") && !C4::Context->IsSuperLibrarian() && scalar @reserves) { my @results; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 616506b9b7..1d12c445b0 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 69; +use Test::More tests => 81; use Test::MockModule; use Test::Warn; @@ -62,6 +62,7 @@ my $frameworkcode = q//; t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); +t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 ); # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached $dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a' and frameworkcode=?", undef, $frameworkcode); @@ -128,6 +129,32 @@ ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its re ($status, $reserve, $all_reserves) = CheckReserves( $item ); is($status, "Reserved", "CheckReserves Test 2"); +# Set the preference 'IndependentBranchesTransfers' is set to 'yes' +# the userenv branch and the branche code are not the same holds should be filtered +t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 1 ); +($status, $reserve, $all_reserves) = CheckReserves( $item ); +is( $status, "", 'Reserves is filtered'); + +# Set the userenv branchcode to be the same to the item branchcode. +t::lib::Mocks::mock_userenv({ branchcode => $branchcode }); +($status, $reserve, $all_reserves) = CheckReserves( $item ); +is( $status, "Reserved", 'Reserves should not be filtered'); + +t::lib::Mocks::mock_userenv({ branchcode => $branch_1 }); +t::lib::Mocks::mock_preference( 'IndependentBranchesTransfers', 0 ); +my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch'); +t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); +ok( + $item->homebranch eq Koha::Policy::Holds->holds_control_library( $item, $patron ), + "Koha::Policy::Holds->holds_control_library returns item home branch when set to ItemHomeLibrary" +); +t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); +ok( + $patron->branchcode eq Koha::Policy::Holds->holds_control_library( $item, $patron ), + "Koha::Policy::Holds->holds_control_library returns patron home branch when set to PatronLibrary" +); +t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch ); + ### ### Regression test for bug 10272 ### -- 2.34.1