Bug 8435: (follow-up) use a transaction for unit tests
[koha.git] / t / db_dependent / Serials_2.t
1 #!/usr/bin/perl
2 use Modern::Perl;
3
4 use Test::More tests => 4;
5
6 use_ok('C4::Serials');
7 use_ok('C4::Budgets');
8
9 my $dbh = C4::Context->dbh;
10 $dbh->{AutoCommit} = 0;
11 $dbh->{RaiseError} = 1;
12
13 my $supplierlist=eval{GetSuppliersWithLateIssues()};
14 ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
15
16 my $biblionumber = 1;
17 my $budgetid;
18 my $bpid = AddBudgetPeriod({
19     budget_period_startdate => '01-01-2015',
20     budget_period_enddate   => '31-12-2015',
21     budget_description      => "budget desc"
22 });
23
24 my $budget_id = AddBudget({
25     budget_code        => "ABCD",
26     budget_amount      => "123.132",
27     budget_name        => "Périodiques",
28     budget_notes       => "This is a note",
29     budget_description => "Serials",
30     budget_active      => 1,
31     budget_period_id   => $bpid
32 });
33
34 my $subscriptionid = NewSubscription(
35     undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
36     undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
37     undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
38     undef,      undef,  undef, undef, undef,      undef,         undef,  1,
39     "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
40     "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
41 );
42 die unless $subscriptionid;
43
44 # Can edit a subscription
45 my @USERENV = (
46     1,
47     'test',
48     'MASTERTEST',
49     'Test',
50     'Test',
51     't',
52     0,
53     0,
54 );
55
56 C4::Context->_new_userenv ('DUMMY_SESSION_ID');
57 C4::Context->set_userenv ( @USERENV );
58 my $userenv = C4::Context->userenv;
59
60 my $subscription = GetSubscription( $subscriptionid );
61
62 is( C4::Serials::can_edit_subscription($subscription), 1, "User can edit a subscription with an empty branchcode");
63 #TODO add UT when C4::Auth->set_permissions (or setuserflags) will exist.
64
65 $dbh->rollback;