From d9de25f4bb0eca10fefe81abd5f5eca248a7805f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 15 Apr 2025 16:33:01 -0300 Subject: [PATCH] Bug 32034: Add more tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Item/Transfer.t | 79 ++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item/Transfer.t b/t/db_dependent/Koha/Item/Transfer.t index 92158644e2a..5c0c9c2c613 100755 --- a/t/db_dependent/Koha/Item/Transfer.t +++ b/t/db_dependent/Koha/Item/Transfer.t @@ -21,11 +21,13 @@ use Modern::Perl; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); +use Koha::Item::Transfers; +use t::lib::Mocks; use t::lib::TestBuilder; use Test::NoWarnings; -use Test::More tests => 8; +use Test::More tests => 9; use Test::Exception; my $schema = Koha::Database->new->schema; @@ -314,3 +316,78 @@ subtest 'cancel tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'store() tests' => sub { + + plan tests => 5; + + $schema->storage->txn_begin; + + my $library_a = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library_b = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $item = $builder->build_sample_item( + { + homebranch => $library_a->branchcode, + holdingbranch => $library_b->branchcode, + } + ); + + # make sure there aren't transfer logs + $schema->resultset('ActionLog')->search( { module => 'TRANSFERS' } )->delete(); + is( $schema->resultset('ActionLog')->search( { module => 'TRANSFERS' } )->count(), 0, 'No transfer logs' ); + + # enable logging + t::lib::Mocks::mock_preference( 'TransfersLog', 1 ); + + # Add a new transfer entry + my $transfer = Koha::Item::Transfer->new( + { + itemnumber => $item->itemnumber, + frombranch => $library_b->branchcode, + tobranch => $library_a->branchcode, + datesent => \'NOW()', + datearrived => undef, + datecancelled => undef, + reason => 'Manual', + cancellation_reason => undef, + } + )->store(); + is( + $schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'CREATE' } )->count(), 1, + 'Logging enabled, log added on creation' + ); + + $transfer->reason('Reserve')->store(); + is( + $schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'UPDATE' } )->count(), 1, + 'Logging enabled, log added on update' + ); + + # enable logging + t::lib::Mocks::mock_preference( 'TransfersLog', 0 ); + $transfer = Koha::Item::Transfer->new( + { + itemnumber => $item->itemnumber, + frombranch => $library_b->branchcode, + tobranch => $library_a->branchcode, + datesent => \'NOW()', + datearrived => undef, + datecancelled => undef, + reason => 'Manual', + cancellation_reason => undef, + } + )->store(); + is( + $schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'CREATE' } )->count(), 1, + 'Logging disabled, log not generated on creation' + ); + + $transfer->reason('Reserve')->store(); + is( + $schema->resultset('ActionLog')->search( { module => 'TRANSFERS', action => 'UPDATE' } )->count(), 1, + 'Logging enabled, log not generated on update' + ); + + $schema->storage->txn_rollback; +}; -- 2.49.0