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