Bug 7688: (follow-up) have Serials.t create its test subscription
[koha.git] / t / db_dependent / Serials.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!
4 # Add more tests here!!!
5
6 use Modern::Perl;
7 use YAML;
8
9 use CGI;
10 use C4::Serials;
11 use C4::Serials::Frequency;
12 use C4::Serials::Numberpattern;
13 use C4::Debug;
14 use C4::Bookseller;
15 use C4::Biblio;
16 use C4::Budgets;
17 use Test::More tests => 35;
18
19 BEGIN {
20     use_ok('C4::Serials');
21 }
22
23 my $dbh = C4::Context->dbh;
24
25 # Start transaction
26 $dbh->{AutoCommit} = 0;
27 $dbh->{RaiseError} = 1;
28
29 my $booksellerid = C4::Bookseller::AddBookseller(
30     {
31         name => "my vendor",
32         address1 => "bookseller's address",
33         phone => "0123456",
34         active => 1
35     }
36 );
37
38 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
39
40 my $budgetid;
41 my $bpid = AddBudgetPeriod({
42     budget_period_startdate => '01-01-2015',
43     budget_period_enddate   => '12-31-2015',
44     budget_description      => "budget desc"
45 });
46
47 my $budget_id = AddBudget({
48     budget_code        => "ABCD",
49     budget_amount      => "123.132",
50     budget_name        => "Périodiques",
51     budget_notes       => "This is a note",
52     budget_description => "Serials",
53     budget_active      => 1,
54     budget_period_id   => $bpid
55 });
56
57 my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
58 my $pattern_id = AddSubscriptionNumberpattern({
59     label => 'Test numberpattern 1',
60     numberingmethod => '{X}'
61 });
62
63 my $subscriptionid = NewSubscription(
64     undef,      "",     undef, undef, $budget_id, $biblionumber,
65     '2013-01-01', $frequency_id, undef, undef,  undef,
66     undef,      undef,  undef, undef, undef, undef,
67     1,          "notes",undef, '2013-01-01', undef, $pattern_id,
68     undef,       undef,  0,    "intnotes",  0,
69     undef, undef, 0,          undef,         '2013-12-31', 0
70 );
71
72 my $subscriptioninformation = GetSubscription( $subscriptionid );
73
74 my @subscriptions = GetSubscriptions( $$subscriptioninformation{bibliotitle} );
75 isa_ok( \@subscriptions, 'ARRAY' );
76
77 @subscriptions = GetSubscriptions( undef, $$subscriptioninformation{issn} );
78 isa_ok( \@subscriptions, 'ARRAY' );
79
80 @subscriptions = GetSubscriptions( undef, undef, $$subscriptioninformation{ean} );
81 isa_ok( \@subscriptions, 'ARRAY' );
82
83 @subscriptions = GetSubscriptions( undef, undef, undef, $$subscriptioninformation{bibnum} );
84 isa_ok( \@subscriptions, 'ARRAY' );
85
86 my $frequency = GetSubscriptionFrequency($subscriptioninformation->{periodicity});
87 my $old_frequency;
88 if (not $frequency->{unit}) {
89     $old_frequency = $frequency->{id};
90     $frequency->{unit} = "month";
91     $frequency->{unitsperissue} = 1;
92     $frequency->{issuesperunit} = 1;
93     $frequency->{description} = "Frequency created by t/db_dependant/Serials.t";
94     $subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency);
95
96     ModSubscription( @$subscriptioninformation{qw(
97         librarian branchcode aqbooksellerid cost aqbudgetid startdate
98         periodicity firstacquidate irregularity numberpattern locale
99         numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
100         innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
101         letter manualhistory internalnotes serialsadditems staffdisplaycount
102         opacdisplaycount graceperiod location enddate subscriptionid
103         skip_serialseq
104     )} );
105 }
106 my $expirationdate = GetExpirationDate($subscriptionid) ;
107 ok( $expirationdate, "expiration date is not NULL" );
108
109 is(C4::Serials::GetLateIssues(), undef, 'test getting late issues');
110
111 ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');
112
113 my ($serials_count, @serials) = GetSerials($subscriptionid);
114 ok($serials_count > 0, 'Subscription has at least one serial');
115 my $serial = $serials[0];
116
117 ok(C4::Serials::GetSerialStatusFromSerialId($serial->{serialid}), 'test getting Serial Status From Serial Id');
118
119 isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information');
120
121 # Delete created frequency
122 if ($old_frequency) {
123     my $freq_to_delete = $subscriptioninformation->{periodicity};
124     $subscriptioninformation->{periodicity} = $old_frequency;
125
126     ModSubscription( @$subscriptioninformation{qw(
127         librarian branchcode aqbooksellerid cost aqbudgetid startdate
128         periodicity firstacquidate irregularity numberpattern locale
129         numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
130         innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
131         letter manualhistory internalnotes serialsadditems staffdisplaycount
132         opacdisplaycount graceperiod location enddate subscriptionid
133         skip_serialseq
134     )} );
135
136     DelSubscriptionFrequency($freq_to_delete);
137 }
138
139
140 # Test calling subs without parameters
141 is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial');
142 is(C4::Serials::UpdateClaimdateIssues(), undef, 'test updating claim date');
143 is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription');
144 is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data');
145 is(C4::Serials::GetSubscriptionsFromBiblionumber(), undef, 'test getting subscriptions form biblio number');
146
147 is(C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing');
148 is(C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing');
149
150 is(C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials');
151
152 is(C4::Serials::GetDistributedTo(), undef, 'test getting distributed when nothing is entered');
153
154 is(C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing');
155
156 is(C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing');
157
158 is(C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered');
159
160 is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history');
161
162 is(C4::Serials::ModSerialStatus(),undef, 'test modding serials');
163
164 is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered');
165
166 is(C4::Serials::ItemizeSerials(),undef, 'test getting nothing when nothing is entered');
167
168 is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired');
169 is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired');
170
171 is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
172
173 is(C4::Serials::removeMissingIssue(), undef, 'test removing a missing issue');
174
175 is(C4::Serials::updateClaim(),undef, 'test updating claim');
176
177 is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
178
179 is(C4::Serials::check_routing(), undef, 'test checking route');
180
181 is(C4::Serials::addroutingmember(),undef, 'test adding route member');
182
183 $dbh->rollback;