Bug 37757: (follow-up) Warn on bad values and survive
Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
b262e350f1
commit
d50aa6aa72
|
|
@ -20,7 +20,7 @@ package Koha::Patron;
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use List::MoreUtils qw( any uniq );
|
||||
use List::MoreUtils qw( any none uniq );
|
||||
use JSON qw( to_json );
|
||||
use Unicode::Normalize qw( NFKD );
|
||||
use Try::Tiny;
|
||||
|
|
@ -1642,6 +1642,11 @@ sub notice_email_address {
|
|||
|
||||
my $which_address = C4::Context->preference("EmailFieldPrimary");
|
||||
|
||||
if ( $which_address && ( none { $_ eq $which_address } qw{email emailpro B_email cardnumber MULTI} ) ) {
|
||||
warn "Invalid value for EmailFieldPrimary ($which_address)";
|
||||
$which_address = undef;
|
||||
}
|
||||
|
||||
# if syspref is set to 'first valid', look up email address
|
||||
return $self->first_valid_email_address
|
||||
unless $which_address;
|
||||
|
|
|
|||
|
|
@ -1791,7 +1791,7 @@ subtest 'notify_library_of_registration()' => sub {
|
|||
|
||||
subtest 'notice_email_address() tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
plan tests => 5;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -1817,6 +1817,21 @@ subtest 'notice_email_address() tests' => sub {
|
|||
"Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is 'MULTI' and EmailFieldSelection is 'email,emailpro'"
|
||||
);
|
||||
|
||||
my $invalid = 'potato';
|
||||
|
||||
t::lib::Mocks::mock_preference( 'EmailFieldPrecedence', 'email|emailpro' );
|
||||
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', $invalid );
|
||||
|
||||
my $email;
|
||||
warning_is { $email = $patron->notice_email_address(); }
|
||||
qq{Invalid value for EmailFieldPrimary ($invalid)},
|
||||
'Warning correctly generated on invalid system preference';
|
||||
|
||||
is(
|
||||
$email, $patron->email,
|
||||
"Koha::Patron->notice_email_address falls back to correct value when EmailFieldPrimary is invalid"
|
||||
);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue