From 201b4b4af9207f378bdadf17d605814983dd0645 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Fri, 31 Jan 2025 21:15:44 +0000 Subject: [PATCH] Bug 23010: Add unit tests --- t/db_dependent/Koha/Item.t | 51 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 7d115cdb3ab..4fd9ce78d4b 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -20,7 +20,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 38; +use Test::More tests => 39; use Test::Exception; use Test::MockModule; use Test::Warn; @@ -45,12 +45,59 @@ use t::lib::Dates; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; +subtest 'store PreventWithDrawingItemsStatus' => sub { + plan tests => 2; + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference( 'PreventWithDrawingItemsStatus', 'intransit,checkedout' ); + my $library_1 = $builder->build( { source => 'Branch' } ); + my $library_2 = $builder->build( { source => 'Branch' } ); + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); + + my $item = $builder->build_sample_item({ + withdrawn => 0, + }); + + #Check item out + C4::Circulation::AddIssue( $patron, $item->barcode ); + + throws_ok { $item->withdrawn('1')->store } + 'Koha::Exceptions::Item::Transfer::OnLoan', + 'Exception thrown when trying to withdraw checked-out item'; + + my $item_2 = $builder->build_sample_item({ + withdrawn => 0, + }); + + #set in_transit + my $transfer_1 = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $item_2->itemnumber, + frombranch => $library_1->{branchcode}, + tobranch => $library_2->{branchcode}, + datesent => '1999-12-31', + } + } + ); + + throws_ok { $item_2->withdrawn('1')->store } + 'Koha::Exceptions::Item::Transfer::InTransit', + 'Exception thrown when trying to withdraw item in transit'; + + t::lib::Mocks::mock_preference( 'PreventWithDrawingItemsStatus', '' ); + + $schema->storage->txn_rollback; +}; + subtest 'z3950_status' => sub { plan tests => 9; $schema->storage->txn_begin; t::lib::Mocks::mock_preference( 'z3950Status', '' ); - my $itemtype = $builder->build_object( { class => "Koha::ItemTypes" } ); my $item = $builder->build_sample_item( { -- 2.39.5