Bugzilla – Attachment 23635 Details for
Bug 10277
Add C4::Context->IsSuperLibrarian()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10277: Add UT for C4::Context::IsSuperLibrarian
Bug-10277-Add-UT-for-C4ContextIsSuperLibrarian.patch (text/plain), 2.25 KB, created by
Kyle M Hall
on 2013-12-18 15:29:43 UTC
(
hide
)
Description:
Bug 10277: Add UT for C4::Context::IsSuperLibrarian
Filename:
MIME Type:
Creator:
Kyle M Hall
Created:
2013-12-18 15:29:43 UTC
Size:
2.25 KB
patch
obsolete
>From e21416be8a6af4fb3045831c683d11e1d28406ed Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 18 Dec 2013 16:12:00 +0100 >Subject: [PATCH] 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> >--- > C4/Context.pm | 10 +++++++--- > t/Context.t | 28 +++++++++++++++++++++++++--- > 2 files changed, 32 insertions(+), 6 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 4f6683e..9ff9352 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -1242,10 +1242,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; >diff --git a/t/Context.t b/t/Context.t >index 12d1675..9c561cb 100755 >--- a/t/Context.t >+++ b/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" ); >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10277
:
18206
|
18421
|
18422
|
18425
|
18427
|
18518
|
19229
|
20776
|
21144
|
23479
|
23480
|
23481
|
23482
|
23518
|
23523
|
23634
|
23635
|
23860
|
23861