Bug 29826: Manage call of Template Plugin Branches GetName() with null or empty branchcode

Bug 26587 added a concatenation that sends a warning if var is undef :
$ prove t/db_dependent/Template/Plugin/Branches.t
Use of uninitialized value $branchcode in concatenation (.) or string at /kohadevbox/koha/Koha/Template/Plugin/Branches.pm line 35.

This patch adds an early return empty string when GetName is called with $branchcode null or empty string.

Test plan :
1) Run t/db_dependent/Template/Plugin/Branches.t without patch
2) Run with the patch to see warning disappear

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Fridolin Somers 2022-01-07 15:34:49 -10:00
parent 2c821535ef
commit 666ec45473
2 changed files with 6 additions and 1 deletions

View File

@ -30,6 +30,8 @@ use Koha::Libraries;
sub GetName {
my ( $self, $branchcode ) = @_;
return q{} unless defined $branchcode;
return q{} if $branchcode eq q{};
my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
my $cache_key = "Library_branchname:" . $branchcode;

View File

@ -38,7 +38,7 @@ my $builder = t::lib::TestBuilder->new;
subtest 'all() tests' => sub {
plan tests => 18;
plan tests => 19;
$schema->storage->txn_begin;
@ -68,6 +68,9 @@ subtest 'all() tests' => sub {
$name = $plugin->GetName(undef);
is($name, '', 'received empty string as name of NULL/undefined library code');
$name = $plugin->GetName(q{});
is($name, '', 'received empty string as name of empty string library code');
is($plugin->GetLoggedInBranchcode(), '', 'no active library code if there is no active user session');
is($plugin->GetLoggedInBranchname(), '', 'no active library name if there is no active user session');