From 8c9c40a76b48989aceb71e0d9729290a34c841c1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 21 Jul 2023 10:46:41 +0200 Subject: [PATCH] Bug 33940: Consider NULL as valid Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/Policy/Patrons/Cardnumber.pm | 2 +- t/db_dependent/Koha/Policy/Patrons/Cardnumber.t | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/Policy/Patrons/Cardnumber.pm b/Koha/Policy/Patrons/Cardnumber.pm index 43eb124050f..1d3ec4cbe3f 100644 --- a/Koha/Policy/Patrons/Cardnumber.pm +++ b/Koha/Policy/Patrons/Cardnumber.pm @@ -51,7 +51,7 @@ Returns whether a cardnumber is valid of not for a given I object. sub is_valid { my ( $class, $cardnumber, $patron ) = @_; - return Koha::Result::Boolean->new(0)->add_message( { message => "is_empty" } ) + return Koha::Result::Boolean->new(1) unless defined $cardnumber; return Koha::Result::Boolean->new(0)->add_message( { message => "already_exists" } ) diff --git a/t/db_dependent/Koha/Policy/Patrons/Cardnumber.t b/t/db_dependent/Koha/Policy/Patrons/Cardnumber.t index 7937cb412c7..e08ccb3976a 100755 --- a/t/db_dependent/Koha/Policy/Patrons/Cardnumber.t +++ b/t/db_dependent/Koha/Policy/Patrons/Cardnumber.t @@ -31,7 +31,7 @@ my $builder = t::lib::TestBuilder->new; subtest 'is_valid' => sub { - plan tests => 21; + plan tests => 23; $schema->storage->txn_begin; @@ -92,6 +92,9 @@ subtest 'is_valid' => sub { ok( !$policy->is_valid( q{1234567890123456} ), "1234567890123456 is longer than $pref"); ok( !$policy->is_valid( q{1234567890} ), "1234567890 is longer than $pref"); + ok( $policy->is_valid(undef), "If cardnumber is null, we assume they're allowed") ; + ok( !$policy->is_valid(""), "Empty string is not correct" ); + $schema->storage->txn_rollback; }; -- 2.42.0