From ed2794681f14ffe1916eda1743566bda548bbf33 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 3 Jul 2023 14:50:19 +0300 Subject: [PATCH] Bug 34152: Fix failing t/db_dependent/Koha/Item.t tests This patch fixes following issues in t/db_dependent/Koha/Item.t tests: - "Can't call method "can_edit_items_from" on an undefined value at .../Koha/Item.pm line 298." with sending patron data to mocked environment - "holds tests" test failures due "not_same_branch" errors by mocking IndependentBranches enabled and adding mock user environment To test: 1. Run prove t/db_dependent/Koha/Item.t. => Tests should fail. 2. Apply this patch. 3. Run prove t/db_dependent/Koha/Item.t again. => Success! Sponsored-by: Koha-Suomi Oy --- t/db_dependent/Koha/Item.t | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 66c4d16830..96c34fb191 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -849,9 +849,8 @@ subtest 'deletion' => sub { my $library = $builder->build_object({ class => 'Koha::Libraries' }); my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); - t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode }); - my $patron = $builder->build_object({class => 'Koha::Patrons'}); + t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library->branchcode }); $item = $builder->build_sample_item({ library => $library->branchcode }); # book_on_loan @@ -932,11 +931,15 @@ subtest 'deletion' => sub { plan tests => 9; # to avoid noise - t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); + t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $patron = $builder->build_object({class => 'Koha::Patrons'}); + t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library->branchcode }); $schema->storage->txn_begin; - my $item = $builder->build_sample_item; + my $item = $builder->build_sample_item({ library => $library->branchcode }); my $processing = $builder->build_object( { class => 'Koha::Holds', value => { itemnumber => $item->id, itemnumber => $item->id, found => 'P' } } ); my $safe_to_delete = $item->safe_to_delete; -- 2.34.1