Bug 21535: Anonymize function in Patron should not scramble email addresses
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Wed, 10 Oct 2018 13:34:22 +0000 (15:34 +0200)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 9 May 2019 19:30:06 +0000 (19:30 +0000)
Scrambled email addresses will only generate warnings etc.
Clear them although they might be in BorrowerMandatoryField.

Test plan:
Run t/db_dependent/Koha/Patrons.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

t/db_depepended/Koha/Patrons.t runs with no warnings.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Patron.pm
t/db_dependent/Koha/Patrons.t

index 6a25d71..04b54a3 100644 (file)
@@ -1358,7 +1358,9 @@ sub anonymize {
         warn "Exiting anonymize: patron ".$self->borrowernumber." still has issues";
         return;
     }
-    my $mandatory = { map { (lc $_, 1); }
+    # Mandatory fields come from the corresponding pref, but email fields
+    # are removed since scrambled email addresses only generate errors
+    my $mandatory = { map { (lc $_, 1); } grep { !/email/ }
         split /\s*\|\s*/, C4::Context->preference('BorrowerMandatoryField') };
     $mandatory->{userid} = 1; # needed since sub store does not clear field
     my @columns = $self->_result->result_source->columns;
index 7e4a535..c9dd9c9 100644 (file)
@@ -1761,7 +1761,7 @@ subtest 'lock' => sub {
 };
 
 subtest 'anonymize' => sub {
-    plan tests => 9;
+    plan tests => 10;
 
     my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } );
     my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } );
@@ -1782,6 +1782,7 @@ subtest 'anonymize' => sub {
     isnt( $patron1->surname, $surname, 'Surname changed' );
     ok( $patron1->surname =~ /^\w{10}$/, 'Mandatory surname randomized' );
     is( $patron1->branchcode, $branchcode, 'Branch code skipped' );
+    is( $patron1->email, undef, 'Email was mandatory, must be cleared' );
 
     # Test wrapper in Koha::Patrons
     $patron1->surname($surname)->store; # restore