From 9af0aa288c23a6722333adebba7b8b3e12ed78e2 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 18 Apr 2014 19:56:51 +0000 Subject: [PATCH] Bug 12048: add regression test This patch adds a regression test for verifying that superlibrarians can see all subscription when IndependentBranches is on. Signed-off-by: Galen Charlton --- t/db_dependent/Bookseller.t | 50 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index d12f263e3c..a2754d1c67 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -2,7 +2,8 @@ use Modern::Perl; -use Test::More tests => 69; +use Test::More tests => 72; +use Test::MockModule; use C4::Context; use Koha::DateUtils; use DateTime::Duration; @@ -194,7 +195,7 @@ is( $bookseller1fromid->{subscriptioncount}, 0, 'Supplier1 has 0 subscription' ); my $id_subscription1 = NewSubscription( - undef, "", $id_supplier1, undef, $id_budget, $biblionumber, + undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber, '01-01-2013',undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 1, "subscription notes",undef, '01-01-2013', undef, undef, @@ -206,7 +207,7 @@ my @subscriptions = SearchSubscriptions({biblionumber => $biblionumber}); is($subscriptions[0]->{publicnotes}, 'subscription notes', 'subscription search results include public notes (bug 10689)'); my $id_subscription2 = NewSubscription( - undef, "", $id_supplier1, undef, $id_budget, $biblionumber, + undef, 'BRANCH2', $id_supplier1, undef, $id_budget, $biblionumber, '01-01-2013',undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 1, "subscription notes",undef, '01-01-2013', undef, undef, @@ -364,7 +365,7 @@ ModBasket($basket4info); #Add 1 subscription my $id_subscription3 = NewSubscription( - undef, "", $id_supplier1, undef, $id_budget, $biblionumber, + undef, "BRANCH1", $id_supplier1, undef, $id_budget, $biblionumber, '01-01-2013',undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 1, "subscription notes",undef, '01-01-2013', undef, undef, @@ -663,6 +664,47 @@ ok( exists( $suppliers{$id_supplier1} ), "Supplier1 has late orders and $daysago10==$daysago10 " ) ; +C4::Context->_new_userenv('DUMMY SESSION'); +C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 0, '', ''); +my $userenv = C4::Context->userenv; + +my $module = Test::MockModule->new('C4::Auth'); +$module->mock( + 'haspermission', + sub { + # simulate user that has serials permissions but + # NOT superserials + my ($userid, $flagsrequired) = @_; + return 0 if 'superserials' eq ($flagsrequired->{serials} // 0); + return exists($flagsrequired->{serials}); + } +); + +C4::Context->set_preference('IndependentBranches', 0); +@subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'}); +is( + scalar(grep { !$_->{cannotdisplay} } @subscriptions ), + 3, + 'ordinary user can see all subscriptions with IndependentBranches off' +); + +C4::Context->set_preference('IndependentBranches', 1); +@subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'}); +is( + scalar(grep { !$_->{cannotdisplay} } @subscriptions ), + 1, + 'ordinary user can see only their library\'s subscriptions with IndependentBranches on' +); + +# don the cape and turn into Superlibrarian! +C4::Context::set_userenv(0,0,0,'firstname','surname', 'BRANCH1', 'Library 1', 1, '', ''); +@subscriptions = SearchSubscriptions({expiration_date => '2013-12-31'}); +is( + scalar(grep { !$_->{cannotdisplay} } @subscriptions ), + 3, + 'superlibrarian can see all subscriptions with IndependentBranches on (bug 12048)' +); + #End transaction $dbh->rollback; -- 2.20.1