From 5248f12a0e48630cca6d877179bb86fde70f4929 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 31 Oct 2013 09:49:12 +0100 Subject: [PATCH] Bug 8435: (follow-up) handle lack of userenv gracefully C4::Serials::can_edit_subscription now deals with C4::Context->userenv. Signed-off-by: Galen Charlton --- C4/Serials.pm | 1 + t/db_dependent/Serials_2.t | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 7c4bf82328..da876e2678 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -2805,6 +2805,7 @@ Return 1 if the subscription is editable by the current logged user (or a given sub can_edit_subscription { my ( $subscription, $userid ) = @_; + return 0 unless C4::Context->userenv; my $flags = C4::Context->userenv->{flags}; $userid ||= C4::Context->userenv->{'id'}; my $independent_branches = C4::Context->preference('IndependentBranches'); diff --git a/t/db_dependent/Serials_2.t b/t/db_dependent/Serials_2.t index 72d71d9d31..3d921b8d18 100644 --- a/t/db_dependent/Serials_2.t +++ b/t/db_dependent/Serials_2.t @@ -1,10 +1,12 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use MARC::Record; + use C4::Biblio qw( AddBiblio ); +use C4::Context; use_ok('C4::Serials'); use_ok('C4::Budgets'); @@ -12,6 +14,7 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; + my $supplierlist=eval{GetSuppliersWithLateIssues()}; ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues"); @@ -39,16 +42,19 @@ my $budget_id = AddBudget({ }); my $subscriptionid = NewSubscription( - undef, "", undef, undef, $budget_id, $biblionumber, '01-01-2013',undef, - undef, undef, undef, undef, undef, undef, undef, undef, - undef, undef, undef, undef, undef, undef, undef, undef, - undef, undef, undef, undef, undef, undef, undef, 1, - "notes", undef, undef, undef, undef, undef, undef, 0, - "intnotes", 0, undef, undef, 0, undef, '12-31-2013', + undef, "", undef, undef, $budget_id, $biblionumber, + '2013-01-01', undef, undef, undef, undef, + undef, undef, undef, undef, undef, undef, + 1, "notes",undef, '2013-01-01', undef, undef, + undef, undef, 0, "intnotes", 0, + undef, undef, 0, undef, '2013-12-31', 0 ); die unless $subscriptionid; -# Can edit a subscription + +my $subscription = GetSubscription( $subscriptionid ); +is( C4::Serials::can_edit_subscription($subscription), 0, "cannot edit a subscription without userenv set"); + my @USERENV = ( 1, 'test', @@ -62,9 +68,9 @@ my @USERENV = ( C4::Context->_new_userenv ('DUMMY_SESSION_ID'); C4::Context->set_userenv ( @USERENV ); -my $userenv = C4::Context->userenv; -my $subscription = GetSubscription( $subscriptionid ); +# Can edit a subscription +my $userenv = C4::Context->userenv; is( C4::Serials::can_edit_subscription($subscription), 1, "User can edit a subscription with an empty branchcode"); #TODO add UT when C4::Auth->set_permissions (or setuserflags) will exist. -- 2.39.5