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 <martin.renvoize@openfifth.co.uk>
(cherry picked from commit 6a13c6e5066384e59e52f0d48f5a430958671ef2)
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-06-18 17:01:00 +01:00 committed by Pedro Amorim
parent 275d870be7
commit dfea147183
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 12 additions and 1 deletions

View File

@ -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;
};