|
Lines 1-15
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
| 3 |
use C4::Context; |
|
|
| 4 |
use Test::More tests => 96; |
| 5 |
use Modern::Perl; |
3 |
use Modern::Perl; |
|
|
4 |
use Test::More tests => 102; |
| 6 |
|
5 |
|
|
|
6 |
use Koha::Database; |
| 7 |
use C4::Serials; |
| 8 |
use C4::Serials::Frequency; |
| 9 |
|
| 10 |
my $schema = Koha::Database->new->schema; |
| 11 |
$schema->storage->txn_begin; |
| 7 |
my $dbh = C4::Context->dbh; |
12 |
my $dbh = C4::Context->dbh; |
| 8 |
$dbh->{RaiseError} = 1; |
|
|
| 9 |
$dbh->{AutoCommit} = 0; |
| 10 |
|
13 |
|
| 11 |
use C4::Serials::Frequency; |
|
|
| 12 |
use C4::Serials; |
| 13 |
|
14 |
|
| 14 |
# TEST CASE - 1 issue per day, no irregularities |
15 |
# TEST CASE - 1 issue per day, no irregularities |
| 15 |
my $frequency = { |
16 |
my $frequency = { |
|
Lines 469-478
$publisheddate = GetNextDate($subscription, $publisheddate);
Link Here
|
| 469 |
is($publisheddate, '1978-01-01'); |
470 |
is($publisheddate, '1978-01-01'); |
| 470 |
$publisheddate = GetNextDate($subscription, $publisheddate); |
471 |
$publisheddate = GetNextDate($subscription, $publisheddate); |
| 471 |
is($publisheddate, '1980-01-01'); |
472 |
is($publisheddate, '1980-01-01'); |
|
|
473 |
# Move publisheddate to Feb 29 (leap year 1980) |
| 474 |
$publisheddate = '1980-02-29'; |
| 475 |
$publisheddate = GetNextDate( $subscription, $publisheddate ); |
| 476 |
is( $publisheddate, '1982-02-28', 'Test +2 year from Feb 29' ); |
| 472 |
|
477 |
|
| 473 |
# TEST CASE - 2 issues per year, no irregularity |
478 |
# TEST CASE - 2 issues per year, no irregularity |
| 474 |
$id = AddSubscriptionFrequency({ |
479 |
$id = AddSubscriptionFrequency({ |
| 475 |
description => "1 issue every 2 years", |
480 |
description => "2 issues per year", |
| 476 |
unit => 'year', |
481 |
unit => 'year', |
| 477 |
issuesperunit => 2, |
482 |
issuesperunit => 2, |
| 478 |
unitsperissue => 1, |
483 |
unitsperissue => 1, |
|
Lines 512-517
is($publisheddate, '1973-07-02');
Link Here
|
| 512 |
$publisheddate = GetNextDate($subscription, $publisheddate); |
517 |
$publisheddate = GetNextDate($subscription, $publisheddate); |
| 513 |
is($publisheddate, '1974-01-01'); |
518 |
is($publisheddate, '1974-01-01'); |
| 514 |
|
519 |
|
|
|
520 |
# TEST CASE - 9 issues per year, dates spread throughout month |
| 521 |
$id = AddSubscriptionFrequency({ |
| 522 |
description => "9 issues per year", |
| 523 |
unit => 'year', |
| 524 |
issuesperunit => 9, |
| 525 |
unitsperissue => 1, |
| 526 |
}); |
| 527 |
$subscription = { |
| 528 |
periodicity => $id, |
| 529 |
firstacquidate => '1970-08-10', |
| 530 |
irregularity => '', |
| 531 |
countissuesperunit => 1, |
| 532 |
}; |
| 533 |
my @dates = ( $subscription->{firstacquidate} ); |
| 534 |
foreach(1..27) { |
| 535 |
push @dates, GetNextDate( $subscription, $dates[-1] ); |
| 536 |
} |
| 537 |
is( $dates[9], '1971-08-10', 'Freq 9/yr, 1 year passed' ); |
| 538 |
is( $dates[18], '1972-08-10', 'Freq 9/yr, 2 years passed (leap year)' ); |
| 539 |
is( $dates[27], '1973-08-10', 'Freq 9/yr, 3 years passed' ); |
| 540 |
# Now move one back in the cycle and push back 49 days; we expect correction |
| 541 |
# because 40 days are added and the difference (9 days) is <= issues per unit. |
| 542 |
$subscription->{countissuesperunit} = 9; |
| 543 |
$publisheddate = GetNextDate( $subscription, '1973-06-22' ); |
| 544 |
is( $publisheddate, '1973-08-10', 'Freq 9/yr, 3 years passed, corrected' ); |
| 545 |
# Set back again, one day more. Now we do not expect correction. |
| 546 |
$subscription->{countissuesperunit} = 9; |
| 547 |
$publisheddate = GetNextDate( $subscription, '1973-06-21' ); |
| 548 |
is( $publisheddate, '1973-07-31', 'Freq 9/yr, 3 years passed, not corrected' ); |
| 549 |
|
| 515 |
# TEST CASE - Irregular |
550 |
# TEST CASE - Irregular |
| 516 |
$id = AddSubscriptionFrequency({ |
551 |
$id = AddSubscriptionFrequency({ |
| 517 |
description => "Irregular", |
552 |
description => "Irregular", |
|
Lines 538-541
is($publisheddate, undef);
Link Here
|
| 538 |
$publisheddate = GetNextDate(undef, undef); |
573 |
$publisheddate = GetNextDate(undef, undef); |
| 539 |
is($publisheddate, undef); |
574 |
is($publisheddate, undef); |
| 540 |
|
575 |
|
| 541 |
$dbh->rollback; |
576 |
$schema->storage->txn_rollback; |
| 542 |
- |
|
|