From 2b29f32dc503d78b1ea57cad9b744bbe50ea4df2 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Mon, 16 Sep 2024 08:42:11 +0000 Subject: [PATCH] Bug 37522: Unit tests NB, since the 6th argument to logaction is now mandatory for logging item modifications, one had to modify one line from the previous tests by adding this additional parameter. Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- t/db_dependent/Log.t | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t index 0a1f695ef7..2aaad4bdd0 100755 --- a/t/db_dependent/Log.t +++ b/t/db_dependent/Log.t @@ -16,7 +16,7 @@ use Modern::Perl; use Data::Dumper qw( Dumper ); -use Test::More tests => 6; +use Test::More tests => 7; use C4::Context; use C4::Log qw( logaction cronlogaction ); @@ -177,7 +177,7 @@ subtest 'Reduce log size by unblessing Koha objects' => sub { is( $logs->count, 1, 'Action found' ); is( length($logs->next->info), length($str), 'Length exactly identical' ); - logaction( 'CATALOGUING', 'MODIFY', $item->itemnumber, $item, 'opac' ); + logaction( 'CATALOGUING', 'MODIFY', $item->itemnumber, $item, 'opac', $item ); $logs = Koha::ActionLogs->search({ module => 'CATALOGUING', action => 'MODIFY', object => $item->itemnumber }); is( substr($logs->next->info, 0, 5), 'item ', 'Prefix item' ); is( length($logs->reset->next->info), 5+length($str), 'Length + 5' ); @@ -218,4 +218,23 @@ subtest 'Test storing diff of objects' => sub { is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' ); }; +subtest 'Test storing original version of an item' => sub { + plan tests => 1; + + $Data::Dumper::Sortkeys = 1; + my $builder = t::lib::TestBuilder->new; + my $item = $builder->build_sample_item; + my $original = $item->get_from_storage; + + # make sure that $item->...->store logs the update + t::lib::Mocks::mock_preference( 'CataloguingLog', 1 ); + $item->barcode('_MY_OTHER_BARCODE_')->store(); + + # update was logged under CATALOGUING / MODIFY so we can retrieve the log now + my $log = + Koha::ActionLogs->search( { module => 'CATALOGUING', action => 'MODIFY', object => $item->itemnumber } )->next; + my $info = $log->info; + is( $info, "item " . Dumper( $original->unblessed ), 'Original version of item logged successfully' ); +}; + $schema->storage->txn_rollback; -- 2.39.5