From 4454337a181b9810e08414a1890bb18cfa83555e Mon Sep 17 00:00:00 2001 From: William Lavoie Date: Thu, 3 Apr 2025 11:29:39 -0400 Subject: [PATCH] Bug 33200: Preventing holds from creating transfers with IndependentBranchesTransfers enabled --- t/db_dependent/Reserves.t | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 66b7125ade0..7c6db2643c7 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 81; +use Test::More tests => 73; use Test::MockModule; use Test::Warn; @@ -155,6 +155,32 @@ ok( ); t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch ); +# 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 ### @@ -1450,7 +1476,7 @@ sub count_hold_print_messages { my $message_count = $dbh->selectall_arrayref(q{ SELECT COUNT(*) FROM message_queue - WHERE letter_code = 'HOLD' + WHERE letter_code = 'HOLD' AND message_transport_type = 'print' }); return $message_count->[0]->[0]; -- 2.43.0