From dfea14718301faf66f8389e74342a8adcdc59548 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 18 Jun 2026 17:01:00 +0100 Subject: [PATCH] Bug 42385: (QA follow-up) Test PickupLibrary fall-through to ItemHomeLibrary The original _GetCircControlBranch tests covered the case where CircControl is PickupLibrary but no userenv branch is available, in which case the resolution falls through to the ItemHomeLibrary behaviour. That coverage was lost when the tests moved to t/db_dependent/Koha/Policy/Circulation.t, since the PickupLibrary subtest always mocks a userenv. This restores coverage for the fall-through path: with CircControl set to PickupLibrary, no userenv, and no pickup_library_id, the controlling library is resolved from the item's home library. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Policy/Circulation.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Martin Renvoize (cherry picked from commit 6a13c6e5066384e59e52f0d48f5a430958671ef2) Signed-off-by: Pedro Amorim --- t/db_dependent/Koha/Policy/Circulation.t | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Policy/Circulation.t b/t/db_dependent/Koha/Policy/Circulation.t index 80ddda6b5c..b86bb1ec20 100755 --- a/t/db_dependent/Koha/Policy/Circulation.t +++ b/t/db_dependent/Koha/Policy/Circulation.t @@ -24,6 +24,7 @@ use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; +use C4::Context; use Koha::Database; BEGIN { use_ok('Koha::Policy::Circulation'); } @@ -33,7 +34,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'circ_control_library() - PickupLibrary' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; @@ -60,6 +61,16 @@ subtest 'circ_control_library() - PickupLibrary' => sub { 'Uses explicit pickup_library_id when provided' ); + # No userenv and no pickup_library_id: falls back to ItemHomeLibrary behaviour + C4::Context->unset_userenv; + t::lib::Mocks::mock_preference( 'HomeOrHoldingBranch', 'homebranch' ); + + is( + Koha::Policy::Circulation->circ_control_library( $item, $patron ), + $item->homebranch, + 'Falls back to item home library when no userenv and no pickup_library_id' + ); + $schema->storage->txn_rollback; };