3 # This test deals with GetFictiveIssueNumber (from C4::Serials)
6 use Test::More tests => 5;
10 use C4::Serials::Frequency;
12 my $schema = Koha::Database->new->schema;
13 $schema->storage->txn_begin;
14 my $dbh = C4::Context->dbh;
16 subtest 'Tests for irregular frequency' => sub {
20 my $freq_irr = AddSubscriptionFrequency({
21 description => "Irregular",
27 periodicity => $freq_irr,
28 firstacquidate => '1972-02-07',
30 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), 0, 'Irregular: should be zero' );
31 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), 0, 'Irregular: still zero' );
34 subtest 'Tests for yearly frequencies' => sub {
37 # First add a few frequencies
38 my $freq_1i_1y = AddSubscriptionFrequency({
39 description => "1 issue per year",
44 my $freq_1i_3y = AddSubscriptionFrequency({
45 description => "1 issue per 3 years",
50 my $freq_5i_1y = AddSubscriptionFrequency({
51 description => "5 issues per year",
56 my $freq_366i_1y = AddSubscriptionFrequency({
57 description => "366 issue per year",
63 # TEST CASE - 1 issue per year
65 periodicity => $freq_1i_1y,
66 firstacquidate => '1972-02-10',
67 countissuesperunit => 1,
69 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09'), 1, 'Feb 9 still 1' );
70 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10'), 2, 'Feb 10 goes to 2' );
72 # TEST CASE - 1 issue per 3 years
73 $subscription->{periodicity} = $freq_1i_3y;
74 $subscription->{firstacquidate} = '1972-02-20';
75 is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19'), 1, 'Feb 19, 1975 still 1' );
76 is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20'), 2, 'Feb 20, 1975 goes to 2' );
78 # TEST CASE - 5 issues per year
79 $subscription->{periodicity} = $freq_5i_1y;
80 $subscription->{firstacquidate} = '1972-02-29'; #leap year
81 $subscription->{countissuesperunit} = 1;
82 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11'), 1, 'May 11 still 1' );
83 $subscription->{countissuesperunit} = 2;
84 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12'), 2, 'May 12 goes to 2' );
85 $subscription->{countissuesperunit} = 5;
86 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27'), 5, 'Feb 27 should still be 5' );
87 $subscription->{countissuesperunit} = 1;
88 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 6, 'Feb 28 goes to 6' );
90 # TEST CASE - 366 issues per year (hypothetical example)
91 # Testing prevention of divide by zero
92 $subscription->{periodicity} = $freq_366i_1y;
93 $subscription->{firstacquidate} = '1972-02-29'; #leap year
94 $subscription->{countissuesperunit} = 366;
95 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27'), 366, 'Feb 27 still at 366' );
96 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28'), 732, 'Feb 28 goes to 732' );
100 subtest 'Tests for monthly frequencies' => sub {
103 # First add a few frequencies
104 my $freq_1i_5m = AddSubscriptionFrequency({
105 description => "1 issue per 5 months",
110 my $freq_4i_1m = AddSubscriptionFrequency({
111 description => "4 issue per month",
117 # TEST CASE - 1 issue per 5 months
119 periodicity => $freq_1i_5m,
120 firstacquidate => '1972-02-10',
121 countissuesperunit => 1,
123 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09'), 1, 'Jul 9 still 1' );
124 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10'), 2, 'Jul 10 goes to 2' );
125 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09'), 3, 'May 9 still 3' );
126 is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10'), 4, 'May 10 goes to 4' );
128 # TEST CASE - 4 issue per 1 months
130 periodicity => $freq_4i_1m,
131 firstacquidate => '1972-02-22',
132 countissuesperunit => 1,
134 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28'), 1, 'Feb 28 still 1' );
135 $subscription->{countissuesperunit} = 2;
136 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29'), 2, 'Feb 29 goes to 2' );
137 $subscription->{countissuesperunit} = 4;
138 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21'), 4, 'Mar 21 still 4' );
139 $subscription->{countissuesperunit} = 1;
140 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22'), 5, 'Mar 22 goes to 5' );
144 subtest 'Tests for weekly frequencies' => sub {
147 # First add a few frequencies
148 my $freq_1i_7w = AddSubscriptionFrequency({
149 description => "1 issue per 7 weeks",
154 my $freq_3i_1w = AddSubscriptionFrequency({
155 description => "3 issues per week",
161 # TEST CASE - 1 issue per 7 weeks
163 periodicity => $freq_1i_7w,
164 firstacquidate => '1972-02-10',
165 countissuesperunit => 1,
167 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29'), 1, 'Mar 29 still 1' );
168 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30'), 2, 'Mar 30 goes to 2' );
170 # TEST CASE - 3 issue per 1 week
172 periodicity => $freq_3i_1w,
173 firstacquidate => '1972-02-03',
174 countissuesperunit => 1,
176 $subscription->{countissuesperunit} = 3;
177 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09'), 3, 'Feb 9 still 3' );
178 $subscription->{countissuesperunit} = 1;
179 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10'), 4, 'Feb 10 goes to 4' );
182 subtest 'Tests for dayly frequencies' => sub {
185 # First add a few frequencies
186 my $freq_1i_12d = AddSubscriptionFrequency({
187 description => "1 issue per 12 days",
192 my $freq_3i_1d = AddSubscriptionFrequency({
193 description => "3 issues per day",
199 # TEST CASE - 1 issue per 12 days
201 periodicity => $freq_1i_12d,
202 firstacquidate => '1972-03-16',
203 countissuesperunit => 1,
205 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27'), 1, 'Mar 27 still 1' );
206 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28'), 2, 'Mar 28 goes to 2' );
208 # TEST CASE - 3 issue per day
210 periodicity => $freq_3i_1d,
211 firstacquidate => '1972-04-23',
212 countissuesperunit => 1,
214 $subscription->{countissuesperunit} = 3;
215 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01'), 27, 'May 1 still 27' );
216 $subscription->{countissuesperunit} = 1;
217 is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02'), 28, 'May 2 goes to 28' );
220 $schema->storage->txn_rollback;