4 use Test
::More tests
=> 102;
8 use C4
::Serials
::Frequency
;
10 my $schema = Koha
::Database
->new->schema;
11 $schema->storage->txn_begin;
12 my $dbh = C4
::Context
->dbh;
15 # TEST CASE - 1 issue per day, no irregularities
17 description
=> "One issue per day",
24 firstacquidate
=> '1970-01-01',
26 countissuesperunit
=> 1,
28 my $publisheddate = $subscription->{firstacquidate
};
30 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
31 is
($publisheddate, '1970-01-02');
32 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
33 is
($publisheddate, '1970-01-03');
34 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
35 is
($publisheddate, '1970-01-04');
37 # TEST CASE - 1 issue per day, irregularities
39 firstacquidate
=> '1970-01-01',
40 irregularity
=> '2;4', # Skip the second and fourth issues
41 countissuesperunit
=> 1,
43 $publisheddate = $subscription->{firstacquidate
};
44 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
45 is
($publisheddate, '1970-01-03');
46 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
47 is
($publisheddate, '1970-01-05');
48 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
49 is
($publisheddate, '1970-01-06');
51 # TEST CASE - 2 issues per day, no irregularity
53 description
=> "Two issues per day",
59 firstacquidate
=> '1970-01-01',
61 countissuesperunit
=> 1,
63 $publisheddate = $subscription->{firstacquidate
};
64 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
65 is
($publisheddate, '1970-01-01');
66 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
67 is
($publisheddate, '1970-01-02');
68 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
69 is
($publisheddate, '1970-01-02');
70 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
71 is
($publisheddate, '1970-01-03');
73 # TEST CASE - 2 issues per day, irregularities
75 firstacquidate
=> '1970-01-01',
76 irregularity
=> '3;5;6',
77 countissuesperunit
=> 1,
79 $publisheddate = $subscription->{firstacquidate
};
80 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
81 is
($publisheddate, '1970-01-01');
82 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
83 is
($publisheddate, '1970-01-02');
84 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
85 is
($publisheddate, '1970-01-04');
86 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
87 is
($publisheddate, '1970-01-04');
88 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
89 is
($publisheddate, '1970-01-05');
91 # TEST CASE - 1 issue every 2 days, no irregularity
93 description
=> "one issue every two days",
99 firstacquidate
=> '1970-01-01',
101 countissuesperunit
=> 1,
103 $publisheddate = $subscription->{firstacquidate
};
104 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
105 is
($publisheddate, '1970-01-03');
106 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
107 is
($publisheddate, '1970-01-05');
109 # TEST CASE - 1 issue every 2 days, irregularities
111 firstacquidate
=> '1970-01-01',
113 countissuesperunit
=> 1,
115 $publisheddate = $subscription->{firstacquidate
};
116 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
117 is
($publisheddate, '1970-01-03');
118 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
119 is
($publisheddate, '1970-01-07');
120 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
121 is
($publisheddate, '1970-01-09');
123 # TEST CASE - 1 issue per week, no irregularity
125 description
=> "one issue per week",
131 firstacquidate
=> '1970-01-01',
133 countissuesperunit
=> 1,
135 $publisheddate = $subscription->{firstacquidate
};
136 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
137 is
($publisheddate, '1970-01-08');
138 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
139 is
($publisheddate, '1970-01-15');
141 # TEST CASE - 1 issue per week, irregularities
143 firstacquidate
=> '1970-01-01',
145 countissuesperunit
=> 1,
147 $publisheddate = $subscription->{firstacquidate
};
148 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
149 is
($publisheddate, '1970-01-08');
150 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
151 is
($publisheddate, '1970-01-22');
152 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
153 is
($publisheddate, '1970-01-29');
155 # TEST CASE - 1 issue every 2 weeks, no irregularity
157 description
=> "one issue every 2 weeks",
163 firstacquidate
=> '1970-01-01',
165 countissuesperunit
=> 1,
167 $publisheddate = $subscription->{firstacquidate
};
168 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
169 is
($publisheddate, '1970-01-15');
170 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
171 is
($publisheddate, '1970-01-29');
172 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
173 is
($publisheddate, '1970-02-12');
175 # TEST CASE - 1 issue every 2 weeks, irregularities
177 firstacquidate
=> '1970-01-01',
179 countissuesperunit
=> 1,
181 $publisheddate = $subscription->{firstacquidate
};
182 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
183 is
($publisheddate, '1970-01-15');
184 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
185 is
($publisheddate, '1970-02-12');
186 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
187 is
($publisheddate, '1970-02-26');
189 # TEST CASE - 2 issues per week, no irregularity
191 description
=> "two issues per week",
197 firstacquidate
=> '1970-01-01',
199 countissuesperunit
=> 1,
201 $publisheddate = $subscription->{firstacquidate
};
202 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
203 is
($publisheddate, '1970-01-04');
204 # when more than 1 issue per week, date is automatically set to the same day of
205 # week as firstacquidate
206 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
207 is
($publisheddate, '1970-01-08');
208 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
209 is
($publisheddate, '1970-01-11');
210 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
211 is
($publisheddate, '1970-01-15');
213 # TEST CASE - 2 issues per week, irregularities
215 firstacquidate
=> '1970-01-01',
216 irregularity
=> '3;5;6',
217 countissuesperunit
=> 1,
219 $publisheddate = $subscription->{firstacquidate
};
220 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
221 is
($publisheddate, '1970-01-04');
222 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
223 is
($publisheddate, '1970-01-11');
224 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
225 is
($publisheddate, '1970-01-22');
226 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
227 is
($publisheddate, '1970-01-25');
228 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
229 is
($publisheddate, '1970-01-29');
231 # TEST CASE - 6 issues per week, no irregularity
233 description
=> "six issues per week",
239 firstacquidate
=> '1970-01-06',
241 countissuesperunit
=> 1,
243 $publisheddate = $subscription->{firstacquidate
};
244 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
245 is
($publisheddate, '1970-01-07');
246 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
247 is
($publisheddate, '1970-01-08');
248 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
249 is
($publisheddate, '1970-01-09');
250 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
251 is
($publisheddate, '1970-01-10');
252 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
253 is
($publisheddate, '1970-01-11');
254 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
255 is
($publisheddate, '1970-01-13');
257 # TEST CASE - 6 issues per week, irregularities
259 firstacquidate
=> '1970-01-06',
260 irregularity
=> '3;5;6',
261 countissuesperunit
=> 1,
263 $publisheddate = $subscription->{firstacquidate
};
264 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
265 is
($publisheddate, '1970-01-07');
266 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
267 is
($publisheddate, '1970-01-09');
268 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
269 is
($publisheddate, '1970-01-13');
270 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
271 is
($publisheddate, '1970-01-14');
273 # TEST CASE - 1 issue per month, no irregularity
275 description
=> "1 issue per month",
281 firstacquidate
=> '1970-01-01',
283 countissuesperunit
=> 1,
285 $publisheddate = $subscription->{firstacquidate
};
286 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
287 is
($publisheddate, '1970-02-01');
288 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
289 is
($publisheddate, '1970-03-01');
290 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
291 is
($publisheddate, '1970-04-01');
293 # TEST CASE - 1 issue per month, irregularities
295 firstacquidate
=> '1970-01-01',
296 irregularity
=> '2;4',
297 countissuesperunit
=> 1,
299 $publisheddate = $subscription->{firstacquidate
};
300 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
301 is
($publisheddate, '1970-03-01');
302 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
303 is
($publisheddate, '1970-05-01');
304 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
305 is
($publisheddate, '1970-06-01');
307 # TEST CASE - 1 issue every 2 months, no irregularity
309 description
=> "1 issue every 2 months",
315 firstacquidate
=> '1970-01-01',
317 countissuesperunit
=> 1,
319 $publisheddate = $subscription->{firstacquidate
};
320 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
321 is
($publisheddate, '1970-03-01');
322 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
323 is
($publisheddate, '1970-05-01');
324 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
325 is
($publisheddate, '1970-07-01');
327 # TEST CASE - 1 issue every 2 months, irregularities
329 firstacquidate
=> '1970-01-01',
330 irregularity
=> '2;3',
331 countissuesperunit
=> 1,
333 $publisheddate = $subscription->{firstacquidate
};
334 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
335 is
($publisheddate, '1970-07-01');
336 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
337 is
($publisheddate, '1970-09-01');
338 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
339 is
($publisheddate, '1970-11-01');
341 # TEST CASE - 2 issues per month, no irregularity
343 description
=> "2 issues per month",
349 firstacquidate
=> '1970-01-01',
351 countissuesperunit
=> 1,
353 $publisheddate = $subscription->{firstacquidate
};
354 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
355 is
($publisheddate, '1970-01-16', 'January has 31 days');
356 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
357 is
($publisheddate, '1970-02-01');
358 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
359 is
($publisheddate, '1970-02-16', 'February has only 28 days');
360 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
361 is
($publisheddate, '1970-03-01');
363 # TEST CASE - 2 issues per month, irregularities
365 firstacquidate
=> '1970-01-01',
366 irregularity
=> '3;5;6',
367 countissuesperunit
=> 1,
369 $publisheddate = $subscription->{firstacquidate
};
370 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
371 is
($publisheddate, '1970-01-16', 'January has 31 days');
372 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
373 is
($publisheddate, '1970-02-16', 'February has only 28 days');
374 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
375 is
($publisheddate, '1970-04-01');
376 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
377 is
($publisheddate, '1970-04-16', 'April has 30 days');
378 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
379 is
($publisheddate, '1970-05-01');
381 # TEST CASE - 1 issue per year, no irregularity
383 description
=> "1 issue per year",
389 firstacquidate
=> '1970-01-01',
391 countissuesperunit
=> 1,
393 $publisheddate = $subscription->{firstacquidate
};
394 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
395 is
($publisheddate, '1971-01-01');
396 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
397 is
($publisheddate, '1972-01-01');
398 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
399 is
($publisheddate, '1973-01-01');
401 # TEST CASE - 1 issue per year, irregularities
403 firstacquidate
=> '1970-01-01',
404 irregularity
=> '2;4',
405 countissuesperunit
=> 1,
407 $publisheddate = $subscription->{firstacquidate
};
408 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
409 is
($publisheddate, '1972-01-01');
410 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
411 is
($publisheddate, '1974-01-01');
412 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
413 is
($publisheddate, '1975-01-01');
415 # TEST CASE - 1 issue every 2 years, no irregularity
417 description
=> "1 issue every 2 years",
423 firstacquidate
=> '1970-01-01',
425 countissuesperunit
=> 1,
427 $publisheddate = $subscription->{firstacquidate
};
428 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
429 is
($publisheddate, '1972-01-01');
430 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
431 is
($publisheddate, '1974-01-01');
432 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
433 is
($publisheddate, '1976-01-01');
435 # TEST CASE - 1 issue every 2 years, irregularities
437 firstacquidate
=> '1970-01-01',
438 irregularity
=> '2;4',
439 countissuesperunit
=> 1,
441 $publisheddate = $subscription->{firstacquidate
};
442 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
443 is
($publisheddate, '1974-01-01');
444 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
445 is
($publisheddate, '1978-01-01');
446 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
447 is
($publisheddate, '1980-01-01');
448 # Move publisheddate to Feb 29 (leap year 1980)
449 $publisheddate = '1980-02-29';
450 $publisheddate = GetNextDate
( $subscription, $publisheddate, $frequency );
451 is
( $publisheddate, '1982-02-28', 'Test +2 year from Feb 29' );
453 # TEST CASE - 2 issues per year, no irregularity
455 description
=> "1 issue every 2 years",
461 firstacquidate
=> '1970-01-01',
463 countissuesperunit
=> 1,
465 $publisheddate = $subscription->{firstacquidate
};
466 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
467 is
($publisheddate, '1970-07-02');
468 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
469 is
($publisheddate, '1971-01-01');
470 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
471 is
($publisheddate, '1971-07-02');
472 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
473 is
($publisheddate, '1972-01-01');
475 # TEST CASE - 2 issues per year, irregularities
477 firstacquidate
=> '1970-01-01',
478 irregularity
=> '3;5;6',
479 countissuesperunit
=> 1,
481 $publisheddate = $subscription->{firstacquidate
};
482 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
483 is
($publisheddate, '1970-07-02');
484 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
485 is
($publisheddate, '1971-07-02');
486 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
487 is
($publisheddate, '1973-01-01');
488 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
489 is
($publisheddate, '1973-07-02');
490 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
491 is
($publisheddate, '1974-01-01');
493 # TEST CASE - 9 issues per year, dates spread throughout month
495 description
=> "9 issues per year",
501 firstacquidate
=> '1970-08-10',
503 countissuesperunit
=> 1,
505 my @dates = ( $subscription->{firstacquidate
} );
507 push @dates, GetNextDate
( $subscription, $dates[-1], $frequency );
509 is
( $dates[9], '1971-08-10', 'Freq 9/yr, 1 year passed' );
510 is
( $dates[18], '1972-08-10', 'Freq 9/yr, 2 years passed (leap year)' );
511 is
( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' );
512 # Keep (first) position in cycle, but shift back 9 days
513 is
( GetNextDate
( $subscription, '1973-08-01', $frequency ), '1973-09-10', 'Back 9 days, without annual correction' );
514 # Set position to last in cycle, and shift back 9 days; annual correction
515 $subscription->{countissuesperunit
} = 9;
516 is
( GetNextDate
( $subscription, '1973-08-01', $frequency ), '1973-09-15', 'Last in cycle, back 9 days, expect annual correction' );
518 # TEST CASE - Irregular
520 description
=> "Irregular",
526 firstacquidate
=> '1970-01-01',
528 countissuesperunit
=> 1,
530 $publisheddate = $subscription->{firstacquidate
};
531 # GetNextDate always return undef if subscription is irregular
532 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
533 is
($publisheddate, undef);
535 # GetNextDate returns undef if one of two first parameters is undef
536 $publisheddate = GetNextDate
($subscription, undef, $frequency);
537 is
($publisheddate, undef);
538 $publisheddate = GetNextDate
(undef, $subscription->{firstacquidate
}, $frequency);
539 is
($publisheddate, undef);
540 $publisheddate = GetNextDate
(undef, undef, $frequency);
541 is
($publisheddate, undef);
543 $schema->storage->txn_rollback;