From 382949ecfc4405f058872fd8c764c598ca05c595 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Fri, 29 Sep 2023 09:04:52 +0000 Subject: [PATCH] Bug 34883: Add unit test Content-Type: text/plain; charset=utf-8 prove -v t/db_dependent/Koha/Patrons/Import.t Signed-off-by: Marcel de Rooy --- t/db_dependent/Koha/Patrons/Import.t | 46 +++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t index 6bb4fde8b3..9a33f8efcf 100755 --- a/t/db_dependent/Koha/Patrons/Import.t +++ b/t/db_dependent/Koha/Patrons/Import.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 177; +use Test::More tests => 178; use Test::Warn; use Test::Exception; use Encode qw( encode_utf8 ); @@ -1233,6 +1233,50 @@ subtest 'test update_dateexpiry when no dateexpiry in file' => sub { }; +subtest 'prevent regression in update of dateexpiry with no date related flags' => sub { + # If the --update-expiration or --expiration-from-today flgas are not passed, the behaviour should be as foolows: + # 1) dateexpiry column is blank - preserve existing patron expiry date + # 2) dateexpiry column has a date value - update expiry date to match this new date + plan tests => 2; + + my $csv_headers = 'cardnumber,surname,branchcode,categorycode,dateenrolled,dateexpiry'; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + $patron->dateexpiry( '2099-12-31' ); + $patron->dateenrolled( dt_from_string->add( months => '-24', end_of_month => 'limit' ) )->store; + my $csv_values = join( + ',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode, + $patron->dateenrolled, '' + ); + + my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_values ); + open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; + my $params = { file => $handle_1, matchpoint => 'cardnumber', overwrite_cardnumber => 1 }; + my $result = $patrons_import->import_patrons( $params, {} ); + $patron->discard_changes(); + + is( + $patron->dateexpiry, '2099-12-31', + 'No expiry date provided in CSV so the existing patron expiry date is preserved' + ); + + $csv_values = join( + ',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode, + $patron->dateenrolled, '2098-01-01' + ); + + $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_values ); + open( $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!"; + $params = { file => $handle_1, matchpoint => 'cardnumber', overwrite_cardnumber => 1 }; + $result = $patrons_import->import_patrons( $params, {} ); + $patron->discard_changes(); + + is( + $patron->dateexpiry, '2098-01-01', + 'Expiry date updated to match the date provided in the CSV file' + ); +}; + + # got is { code => $code, attribute => $attribute } # expected is { $code => \@attributes } sub compare_patron_attributes { -- 2.30.2