From c72b3364855bc3c796efceb29df15ba4d28310db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 May 2021 11:59:23 +0200 Subject: [PATCH] Bug 28220: Add test for updating an existing patron Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Patrons/Import.t | 80 +++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t index c8ff7ada9c..bef31e56f8 100755 --- a/t/db_dependent/Koha/Patrons/Import.t +++ b/t/db_dependent/Koha/Patrons/Import.t @@ -845,7 +845,7 @@ subtest 'test_format_dates' => sub { subtest 'patron_attributes' => sub { - plan tests => 16; + plan tests => 17; t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); @@ -968,6 +968,84 @@ subtest 'patron_attributes' => sub { is( $patron, undef ); } + subtest 'update existing patron' => sub { + plan tests => 6; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { cardnumber => $cardnumber } + } + ); + + my $attributes = { + $unique_attribute_type->code => ['my unique attribute 1'], + $repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], + $normal_attribute_type->code => ['my normal attribute 1'], + }; + my $fh = build_csv({ %$attributes }); + my $result = $patrons_import->import_patrons( + { + file => $fh, + matchpoint => 'cardnumber', + overwrite_cardnumber => 1, + preserve_extended_attributes => 1 + } + ); + + is( $result->{overwritten}, 1 ); + + compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); + + # Adding a new non-repeatable attribute + my $new_attributes = { + $normal_attribute_type->code => ['my normal attribute 2'], + }; + $fh = build_csv({ %$new_attributes }); + $result = $patrons_import->import_patrons( + { + file => $fh, + matchpoint => 'cardnumber', + overwrite_cardnumber => 1, + preserve_extended_attributes => 1 + } + ); + + is( $result->{overwritten}, 1 ); + + # The normal_attribute_type has been replaced with 'my normal attribute 2' + compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes, %$new_attributes } ); + + + # uniqueness + $patron->extended_attributes->delete; # reset + $builder->build_object( + { + class => 'Koha::Patron::Attributes', + value => { code => $unique_attribute_type->code, attribute => 'unique' } + } + ); + $attributes = { + $unique_attribute_type->code => ['unique'], + $repeatable_attribute_type->code => [ 'my repeatable attribute 1', 'my repeatable attribute 2' ], + $normal_attribute_type->code => ['my normal attribute 1'], + }; + $fh = build_csv({ %$attributes }); + $result = $patrons_import->import_patrons( + { + file => $fh, + matchpoint => 'cardnumber', + overwrite_cardnumber => 1, + preserve_extended_attributes => 1 + } + ); + + is( $result->{overwritten}, 0 ); + + compare_patron_attributes($patron->extended_attributes->unblessed, { %$attributes } ); + + }; + }; # got is { code => $code, attribute => $attribute } -- 2.20.1