Bug 11779: (follow-up) improve GetLoggedInBranchcode() and add test cases
This patch adjusts the new GetLoggedInBranchcode() template function so
that it returns the empty string rather than undef if there is no
active user environment. That way, there won't be lots of undefined
value warnings if/when this function gets used in the OPAC.
This patch also adds test cases.
To test:
[1] Verify that there are no regressions in the main test
plan for this bug.
[2] Verify that prove -v t/db_dependent/Koha_template_plugin_Branches.t
passes.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 065a3a5efa)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
f08154588c
commit
1b02c031a3
|
|
@ -39,7 +39,9 @@ sub GetName {
|
|||
sub GetLoggedInBranchcode {
|
||||
my ($self) = @_;
|
||||
|
||||
return C4::Context->userenv->{'branch'} if C4::Context->userenv;
|
||||
return C4::Context->userenv ?
|
||||
C4::Context->userenv->{'branch'} :
|
||||
'';
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Copyright 2013 Equinox Software, Inc.
|
||||
# Copyright 2013-2014 Equinox Software, Inc.
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 5;
|
||||
use Test::More tests => 7;
|
||||
|
||||
use C4::Context;
|
||||
BEGIN {
|
||||
use_ok('Koha::Template::Plugin::Branches');
|
||||
}
|
||||
|
|
@ -35,3 +36,11 @@ is($name, '', 'received empty string as name of the "__ANY__" placeholder librar
|
|||
|
||||
$name = $plugin->GetName(undef);
|
||||
is($name, '', 'received empty string as name of NULL/undefined library code');
|
||||
|
||||
my $library = $plugin->GetLoggedInBranchcode();
|
||||
is($library, '', 'no active library if there is no active user session');
|
||||
|
||||
C4::Context->_new_userenv('DUMMY_SESSION_ID');
|
||||
C4::Context::set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0);
|
||||
$library = $plugin->GetLoggedInBranchcode();
|
||||
is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library');
|
||||
|
|
|
|||
Loading…
Reference in New Issue