Koha/t/db_dependent/Serials_2.t
Jonathan Druart 5248f12a0e 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 <gmc@esilibrary.com>
2013-10-31 15:29:42 +00:00

78 lines
2 KiB
Perl

#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 5;
use MARC::Record;
use C4::Biblio qw( AddBiblio );
use C4::Context;
use_ok('C4::Serials');
use_ok('C4::Budgets');
my $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
my $supplierlist=eval{GetSuppliersWithLateIssues()};
ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
my $record = MARC::Record->new();
$record->append_fields(
MARC::Field->new( '952', '0', '0', a => 'CPL', b => 'CPL' )
);
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio($record, '');
my $budgetid;
my $bpid = AddBudgetPeriod({
budget_period_startdate => '01-01-2015',
budget_period_enddate => '12-31-2015',
budget_description => "budget desc"
});
my $budget_id = AddBudget({
budget_code => "ABCD",
budget_amount => "123.132",
budget_name => "Périodiques",
budget_notes => "This is a note",
budget_description => "Serials",
budget_active => 1,
budget_period_id => $bpid
});
my $subscriptionid = NewSubscription(
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;
my $subscription = GetSubscription( $subscriptionid );
is( C4::Serials::can_edit_subscription($subscription), 0, "cannot edit a subscription without userenv set");
my @USERENV = (
1,
'test',
'MASTERTEST',
'Test',
'Test',
't',
0,
0,
);
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
C4::Context->set_userenv ( @USERENV );
# 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.
$dbh->rollback;