From bf8f7bb58898c0d343eba62ffebdc808a3f177da Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 12 Nov 2025 00:01:03 +0000 Subject: [PATCH] Bug 41145: Add unit test coverage for stopping duplicated borrowerslog logging due to extended patron attributes being deleted on import This adds to the unit tests in t/db_dependent/Koha/Patrons/Import.t. It confirms that repeating the same patron import (with extended patron attributes) will not generate duplicated borrowersLog entries. Test plan: 1. prove t/db_dependent/Koha/Patrons/Import.t Sponsored-by: Auckland University of Technology Signed-off-by: David Nind Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Patrons/Import.t | 45 +++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t index c552fe019ca..60c5ec6e04e 100755 --- a/t/db_dependent/Koha/Patrons/Import.t +++ b/t/db_dependent/Koha/Patrons/Import.t @@ -30,6 +30,7 @@ use Test::MockModule; use Koha::Database; use Koha::Patron::Relationships; use Koha::DateUtils qw(dt_from_string); +use Koha::ActionLogs; use File::Temp qw(tempfile tempdir); my $temp_dir = tempdir( 'Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1 ); @@ -1497,7 +1498,9 @@ subtest 'patron_attributes' => sub { } subtest 'update existing patron' => sub { - plan tests => 19; + plan tests => 22; + + t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); my $patron = $builder->build_object( { @@ -1523,8 +1526,19 @@ subtest 'patron_attributes' => sub { is( $result->{overwritten}, 1 ); + my $action_logs = Koha::ActionLogs->search( + { + module => "MEMBERS", + action => "MODIFY", + object => $patron->borrowernumber, + } + ); + is( $action_logs->count, 0, ' ' ); + compare_patron_attributes( $patron->extended_attributes->unblessed, {%$attributes} ); + t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); + # Adding a new non-repeatable attribute my $new_attributes = { $normal_attribute_type->code => ['my normal attribute 2'], @@ -1544,6 +1558,35 @@ subtest 'patron_attributes' => sub { # The normal_attribute_type has been replaced with 'my normal attribute 2' compare_patron_attributes( $patron->extended_attributes->unblessed, { %$attributes, %$new_attributes } ); + $action_logs = Koha::ActionLogs->search( + { + module => "MEMBERS", + action => "MODIFY", + object => $patron->borrowernumber, + } + ); + + is( $action_logs->count, 1, ' ' ); + + $result = $patrons_import->import_patrons( + { + file => $fh, + matchpoint => 'cardnumber', + overwrite_cardnumber => 1, + preserve_extended_attributes => 1 + } + ); + + $action_logs = Koha::ActionLogs->search( + { + module => "MEMBERS", + action => "MODIFY", + object => $patron->borrowernumber, + } + ); + + is( $action_logs->count, 1, ' ' ); + # UniqueIDConstraint $patron->extended_attributes->delete; # reset $builder->build_object( -- 2.52.0