Bug 10277: Add UT for C4::Context::IsSuperLibrarian
Note that I modify the return value. Before this patch, it returned an
empty string or 1. Now it returns 0 or 1.
Test plan:
- same as the original patch
- verify that unit tests pass:
prove t/Context.t
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script, including new tests.
Checked the code and tested superlibrarian behaviour in some places:
moremember.pl:
With IndyBranches only superlibrarian can delete borrowers from
other branches. Accessing the borrower with a direct link.
OK
C4/Members.pm
With IndyBranches only superlibrarian can search for borrowres
from other branches.
OK
tools/holidays.pl
With IndyBranches only superlibrarian can edit holidays for other
branches.
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 3e866d216d)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
d003bfa37c
commit
618a119f0d
|
|
@ -1249,10 +1249,14 @@ sub tz {
|
|||
=cut
|
||||
|
||||
sub IsSuperLibrarian {
|
||||
my $userenv = C4::Context->userenv
|
||||
|| carp("C4::Context->userenv not defined!");
|
||||
my $userenv = C4::Context->userenv;
|
||||
|
||||
return $userenv->{flags} % 2 == 1;
|
||||
unless ( $userenv and exists $userenv->{flags} ) {
|
||||
carp("C4::Context->userenv not defined!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $userenv->{flags} % 2;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
28
t/Context.t
28
t/Context.t
|
|
@ -1,10 +1,32 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Modern::Perl;
|
||||
use DBI;
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 6;
|
||||
use Test::MockModule;
|
||||
|
||||
BEGIN {
|
||||
use_ok('C4::Context');
|
||||
}
|
||||
|
||||
my $context = new Test::MockModule('C4::Context');
|
||||
my $userenv = {};
|
||||
|
||||
$context->mock('userenv', sub {
|
||||
return $userenv;
|
||||
});
|
||||
|
||||
local $SIG{__WARN__} = sub { die $_[0] };
|
||||
|
||||
eval { C4::Context::IsSuperLibrarian(); };
|
||||
like ( $@, qr/not defined/, "IsSuperLibrarian logs an error if no userenv is defined" );
|
||||
|
||||
$userenv->{flags} = 42;
|
||||
my $is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
|
||||
is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
|
||||
is ( $is_super_librarian, 0, "With flag=42, it is not a super librarian" );
|
||||
|
||||
$userenv->{flags} = 421;
|
||||
$is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
|
||||
is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
|
||||
is ( $is_super_librarian, 1, "With flag=1, it is a super librarian" );
|
||||
|
|
|
|||
Loading…
Reference in New Issue