Bug 20434: Update UNIMARC framework - auth (TM)
[koha.git] / t / db_dependent / Serials / GetNextSeq.t
blob53fbbe1a88eb36f5f22dc54f4a43cf4e4eef3fee
1 #!/usr/bin/perl
3 use C4::Context;
4 use Test::More tests => 32;
5 use Modern::Perl;
6 use Koha::Database;
8 my $schema = Koha::Database->new->schema;
9 $schema->storage->txn_begin;
10 my $dbh = C4::Context->dbh;
12 use C4::Serials::Frequency;
13 use C4::Serials;
15 my $frequency = {
16 description => "One issue per day",
17 unit => 'day',
18 issuesperunit => 1,
19 unitsperissue => 1,
21 my $id = AddSubscriptionFrequency($frequency);
23 # TEST CASE 1 - 1 variable, from 1 to 4
24 my $pattern = {
25 add1 => 1, add2 => 0, add3 => 0,
26 every1 => 1, every2 => 0, every3 => 0,
27 whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0,
28 setto1 => 1, setto2 => 0, setto3 => 0,
29 numberingmethod => 'X: {X}',
30 numbering1 => '',
31 numbering2 => '',
32 numbering3 => '',
35 my $subscription = {
36 periodicity => $id,
37 firstacquidate => '1970-01-01',
38 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
39 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
40 skip_serialseq => 1,
41 irregularity => '3;5',
42 countissuesperunit => 1,
43 locale => 'en',
45 my $publisheddate = $subscription->{firstacquidate};
47 my $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
48 is($seq, 'X: 2');
49 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
50 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
51 is($seq, 'X: 4');
52 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
53 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
54 is($seq, 'X: 2');
55 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
56 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
57 is($seq, 'X: 3');
59 # TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
60 $subscription = {
61 periodicity => $id,
62 firstacquidate => '1970-01-01',
63 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
64 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
65 skip_serialseq => 1,
66 irregularity => '3;4;6',
67 countissuesperunit => 1,
68 locale => 'C',
70 $pattern = {
71 add1 => 1, add2 => 0, add3 => 0,
72 every1 => 1, every2 => 0, every3 => 0,
73 whenmorethan1 => 7, whenmorethan2 => 0, whenmorethan3 => 0,
74 setto1 => 1, setto2 => 0, setto3 => 0,
75 numberingmethod => 'X: {X}',
76 numbering1 => 'dayname',
77 numbering2 => '',
78 numbering3 => '',
81 $publisheddate = $subscription->{firstacquidate};
83 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
84 is($seq, 'X: Tuesday');
85 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
86 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
87 is($seq, 'X: Friday');
88 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
89 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
90 is($seq, 'X: Sunday');
91 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
92 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
93 is($seq, 'X: Monday');
94 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
95 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
96 is($seq, 'X: Tuesday');
98 # TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
99 $subscription = {
100 periodicity => $id,
101 firstacquidate => '1970-01-01',
102 lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1,
103 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
104 skip_serialseq => 1,
105 irregularity => '3;4;6',
106 countissuesperunit => 1,
107 locale => 'C',
109 $pattern = {
110 add1 => 2, add2 => 0, add3 => 0,
111 every1 => 1, every2 => 0, every3 => 0,
112 whenmorethan1 => 11, whenmorethan2 => 0, whenmorethan3 => 0,
113 setto1 => 0, setto2 => 0, setto3 => 0,
114 numberingmethod => 'X: {X}',
115 numbering1 => 'monthname',
116 numbering2 => '',
117 numbering3 => '',
120 $publisheddate = $subscription->{firstacquidate};
122 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
123 is($seq, 'X: March');
124 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
125 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
126 is($seq, 'X: September');
127 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
128 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
129 is($seq, 'X: January');
130 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
131 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
132 is($seq, 'X: March');
133 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
134 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
135 is($seq, 'X: May');
137 # TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
138 $subscription = {
139 periodicity => $id,
140 firstacquidate => '1970-01-01',
141 lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1,
142 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
143 skip_serialseq => 1,
144 irregularity => '3;4;6',
145 countissuesperunit => 1,
146 locale => 'C',
148 $pattern = {
149 add1 => 1, add2 => 0, add3 => 0,
150 every1 => 1, every2 => 0, every3 => 0,
151 whenmorethan1 => 3, whenmorethan2 => 0, whenmorethan3 => 0,
152 setto1 => 0, setto2 => 0, setto3 => 0,
153 numberingmethod => 'X: {X}',
154 numbering1 => 'season',
155 numbering2 => '',
156 numbering3 => '',
159 $publisheddate = $subscription->{firstacquidate};
161 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
162 is($seq, 'X: Summer');
163 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
164 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
165 is($seq, 'X: Spring');
166 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
167 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
168 is($seq, 'X: Fall');
169 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
170 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
171 is($seq, 'X: Winter');
172 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
173 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
174 is($seq, 'X: Spring');
176 # TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
177 $subscription = {
178 periodicity => $id,
179 firstacquidate => '1970-01-01',
180 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
181 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
182 skip_serialseq => 1,
183 irregularity => '3;4;6',
184 countissuesperunit => 1,
185 locale => 'C',
187 $pattern = {
188 add1 => 1, add2 => 1, add3 => 0,
189 every1 => 1, every2 => 4, every3 => 0,
190 whenmorethan1 => 4, whenmorethan2 => 12, whenmorethan3 => 0,
191 setto1 => 1, setto2 => 1, setto3 => 0,
192 numberingmethod => 'Y: {Y}, X: {X}',
193 numbering1 => '',
194 numbering2 => '',
195 numbering3 => '',
198 $publisheddate = $subscription->{firstacquidate};
200 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
201 is($seq, 'Y: 1, X: 2');
202 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
203 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
204 is($seq, 'Y: 2, X: 1');
205 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
206 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
207 is($seq, 'Y: 2, X: 3');
208 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
209 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
210 is($seq, 'Y: 2, X: 4');
211 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
212 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
213 is($seq, 'Y: 3, X: 1');
215 # TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
216 $subscription = {
217 periodicity => $id,
218 firstacquidate => '1970-01-01',
219 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
220 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
221 skip_serialseq => 1,
222 irregularity => '3;4;6;110',
223 countissuesperunit => 1,
224 locale => 'C',
226 $pattern = {
227 add1 => 1, add2 => 1, add3 => 1,
228 every1 => 1, every2 => 4, every3 => 32,
229 whenmorethan1 => 4, whenmorethan2 => 8, whenmorethan3 => 12,
230 setto1 => 1, setto2 => 1, setto3 => 1,
231 numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}',
232 numbering1 => '',
233 numbering2 => '',
234 numbering3 => '',
237 $publisheddate = $subscription->{firstacquidate};
239 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
240 is($seq, 'Z: 1, Y: 1, X: 2');
241 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
242 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
243 is($seq, 'Z: 1, Y: 2, X: 1');
244 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
245 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
246 is($seq, 'Z: 1, Y: 2, X: 3');
247 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
248 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
249 is($seq, 'Z: 1, Y: 2, X: 4');
250 for (1..100) {
251 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
252 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
254 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
255 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
256 is($seq, 'Z: 4, Y: 4, X: 1');
257 # 110th is here
258 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
259 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
260 is($seq, 'Z: 4, Y: 4, X: 3');
261 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
262 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
263 is($seq, 'Z: 4, Y: 4, X: 4');
264 $publisheddate = GetNextDate($subscription, $publisheddate, $frequency);
265 $seq = _next_seq($subscription, $pattern, $frequency, $publisheddate);
266 is($seq, 'Z: 4, Y: 5, X: 1');
268 sub _next_seq {
269 my ($subscription, $pattern, $frequency, $publisheddate) = @_;
270 my $seq;
271 ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
272 $subscription->{lastvalue3}, $subscription->{innerloop1},
273 $subscription->{innerloop2}, $subscription->{innerloop3}) =
274 GetNextSeq($subscription, $pattern, $frequency, $publisheddate);
275 return $seq;