Bug 11439: (follow up) add missing rollback call
[koha.git] / t / db_dependent / Serials.t
blobe9429826bc33241573b662570a90983eafca27b5
1 #!/usr/bin/perl
3 # This Koha test module is a stub!
4 # Add more tests here!!!
6 use Modern::Perl;
7 use YAML;
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;
19 BEGIN {
20 use_ok('C4::Serials');
23 my $dbh = C4::Context->dbh;
25 # Start transaction
26 $dbh->{AutoCommit} = 0;
27 $dbh->{RaiseError} = 1;
29 my $booksellerid = C4::Bookseller::AddBookseller(
31 name => "my vendor",
32 address1 => "bookseller's address",
33 phone => "0123456",
34 active => 1
38 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
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 });
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 });
57 my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
58 my $pattern_id = AddSubscriptionNumberpattern({
59 label => 'Test numberpattern 1',
60 numberingmethod => '{X}'
61 });
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
72 my $subscriptioninformation = GetSubscription( $subscriptionid );
74 my @subscriptions = GetSubscriptions( $$subscriptioninformation{bibliotitle} );
75 isa_ok( \@subscriptions, 'ARRAY' );
77 @subscriptions = GetSubscriptions( undef, $$subscriptioninformation{issn} );
78 isa_ok( \@subscriptions, 'ARRAY' );
80 @subscriptions = GetSubscriptions( undef, undef, $$subscriptioninformation{ean} );
81 isa_ok( \@subscriptions, 'ARRAY' );
83 @subscriptions = GetSubscriptions( undef, undef, undef, $$subscriptioninformation{bibnum} );
84 isa_ok( \@subscriptions, 'ARRAY' );
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);
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 )} );
106 my $expirationdate = GetExpirationDate($subscriptionid) ;
107 ok( $expirationdate, "expiration date is not NULL" );
109 is(C4::Serials::GetLateIssues(), undef, 'test getting late issues');
111 ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');
113 my ($serials_count, @serials) = GetSerials($subscriptionid);
114 ok($serials_count > 0, 'Subscription has at least one serial');
115 my $serial = $serials[0];
117 ok(C4::Serials::GetSerialStatusFromSerialId($serial->{serialid}), 'test getting Serial Status From Serial Id');
119 isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information');
121 # Delete created frequency
122 if ($old_frequency) {
123 my $freq_to_delete = $subscriptioninformation->{periodicity};
124 $subscriptioninformation->{periodicity} = $old_frequency;
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 )} );
136 DelSubscriptionFrequency($freq_to_delete);
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');
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');
150 is(C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials');
152 is(C4::Serials::GetDistributedTo(), undef, 'test getting distributed when nothing is entered');
154 is(C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing');
156 is(C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing');
158 is(C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered');
160 is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history');
162 is(C4::Serials::ModSerialStatus(),undef, 'test modding serials');
164 is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered');
166 is(C4::Serials::ItemizeSerials(),undef, 'test getting nothing when nothing is entered');
168 is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired');
169 is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired');
171 is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
173 is(C4::Serials::removeMissingIssue(), undef, 'test removing a missing issue');
175 is(C4::Serials::updateClaim(),undef, 'test updating claim');
177 is(C4::Serials::getsupplierbyserialid(),undef, 'test getting supplier idea');
179 is(C4::Serials::check_routing(), undef, 'test checking route');
181 is(C4::Serials::addroutingmember(),undef, 'test adding route member');
183 $dbh->rollback;