From d1e04245063173ccb8aa6ce3983c758ae675832f Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Wed, 31 Jul 2024 21:29:16 +0000 Subject: [PATCH] Bug 35434: (follow-up) Unit test --- t/db_dependent/Koha/Item.t | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 9e3824842a..e43e5bf946 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -539,8 +539,9 @@ subtest "as_marc_field() tests" => sub { subtest 'pickup_locations() tests' => sub { - plan tests => 68; + plan tests => 70; + t::lib::Mocks::mock_preference('canreservefromotherbranches', 1); $schema->storage->txn_begin; my $dbh = C4::Context->dbh; @@ -842,6 +843,39 @@ subtest 'pickup_locations() tests' => sub { t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); + t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); + t::lib::Mocks::mock_preference( 'canreservefromotherbranches', 0 ); + t::lib::Mocks::mock_userenv( { branchcode => $library4->branchcode } ); + + my $item4 = $builder->build_sample_item( + { + homebranch => $library4->branchcode, + holdingbranch => $library4->branchcode + } + )->store; + my $patron5 = $builder->build_object( + { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '5', flags => 84 } } ); + + @pickup_locations = map { + my $pickup_location = $_; + grep { $pickup_location->branchcode eq $_ } @branchcodes + } $item4->pickup_locations( { patron => $patron5 } )->as_list; + ok( + scalar(@pickup_locations) == 1 && @pickup_locations[0] eq $library4->branchcode, + 'There should be only one branch in the pickup locations, the connected branch' + ); + + t::lib::Mocks::mock_userenv( { branchcode => $library2->branchcode } ); + + @pickup_locations = map { + my $pickup_location = $_; + grep { $pickup_location->branchcode eq $_ } @branchcodes + } $item4->pickup_locations( { patron => $patron5 } )->as_list; + ok( + scalar(@pickup_locations) == 0, + 'The pickup locations should be empty if the user connected branch is not the same as the item home branch' + ); + $schema->storage->txn_rollback; }; -- 2.34.1