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.