@@ -, +, @@ --- Koha/Util/Normalize.pm | 16 +++++++++++----- t/Koha/Util/Normalize.t | 20 +++++++++++++++++++- 2 files changed, 30 insertions(+), 6 deletions(-) --- a/Koha/Util/Normalize.pm +++ a/Koha/Util/Normalize.pm @@ -41,8 +41,10 @@ Default normalization function =cut sub legacy_default { + my ( $string ) = @_; + return if !defined( $string ); - my $string = uc shift; + $string = uc $string; $string =~ s/[.;:,\]\[\)\(\/'"]//g; $string =~ s/^\s+//; @@ -59,8 +61,8 @@ Normalization function removing spaces =cut sub remove_spaces { - - my $string = shift; + my ( $string ) = @_; + return if !defined( $string ); $string =~ s/\s+//g; @@ -74,8 +76,10 @@ Normalization function converting characters into upper-case =cut sub upper_case { + my ( $string ) = @_; + return if !defined( $string ); - my $string = uc shift; + $string = uc $string; return $string; } @@ -87,8 +91,10 @@ Normalization function converting characters into lower-case =cut sub lower_case { + my ( $string ) = @_; + return if !defined( $string ); - my $string = lc shift; + $string = lc $string; return $string; } --- a/t/Koha/Util/Normalize.t +++ a/t/Koha/Util/Normalize.t @@ -17,12 +17,30 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::Warn; BEGIN { use_ok('Koha::Util::Normalize'); } +subtest 'pass undef' => sub { + plan tests => 8; + + is( legacy_default(), undef, 'legacy_default returns undef' ); + warning_is { legacy_default() } undef, 'no warn from legacy_default'; + + is( remove_spaces(), undef, 'remove_spaces returns undef' ); + warning_is { remove_spaces() } undef, 'no warn from remove_spaces'; + + is( upper_case(), undef, 'upper_case returns undef' ); + warning_is { upper_case() } undef, 'no warn from upper_case'; + + is( lower_case(), undef, 'lower_case returns undef' ); + warning_is { lower_case() } undef, 'no warn from lower_case'; +}; + + subtest 'legacy_default() normalizer' => sub { plan tests => 1; --