From 4d89c2373fe24ecd4668df5db247903a57cb6a17 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 29 May 2017 12:08:40 +0200 Subject: [PATCH] Bug 18607: Adjusting unit tests for monthly serial frequencies Content-Type: text/plain; charset=utf-8 The changes in the first patch require some corrections as well as additional test cases. GetNextDate.t: Since the calculation for multiple issues per unit has slightly changed, a few dates (day 15 or day 16) have been changed in the unit test; when we use 2/month, the algorithm now always adds 15 days. Added a few test descriptions in this regard too. GetFictiveIssueNumber.t: Add the monthly subtest with two test cases. In the first case we tests multiple units per issue, and in the second case we test multiple issues per unit (month). Test plan: [1] Run t/db_dependent/Serials/GetFictiveIssueNumber.t [2] Run t/db_dependent/Serials/GetNextDate.t Signed-off-by: Marcel de Rooy --- t/db_dependent/Serials/GetFictiveIssueNumber.t | 44 ++++++++++++++++++++++++-- t/db_dependent/Serials/GetNextDate.t | 18 +++++------ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Serials/GetFictiveIssueNumber.t b/t/db_dependent/Serials/GetFictiveIssueNumber.t index ed79bba..12d9a71 100644 --- a/t/db_dependent/Serials/GetFictiveIssueNumber.t +++ b/t/db_dependent/Serials/GetFictiveIssueNumber.t @@ -3,7 +3,7 @@ # This test deals with GetFictiveIssueNumber (from C4::Serials) use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Koha::Database; use C4::Serials; @@ -92,7 +92,47 @@ subtest 'Tests for yearly frequencies' => sub { }; -# TODO: subtest 'Tests for monthly frequencies' => sub { +subtest 'Tests for monthly frequencies' => sub { + plan tests => 8; + + # First add a few frequencies + my $freq_1i_5m = AddSubscriptionFrequency({ + description => "1 issue per 5 months", + unit => 'month', + issuesperunit => 1, + unitsperissue => 5, + }); + my $freq_4i_1m = AddSubscriptionFrequency({ + description => "4 issue per month", + unit => 'month', + issuesperunit => 4, + unitsperissue => 1, + }); + + # TEST CASE - 1 issue per 5 months + my $subscription = { + periodicity => $freq_1i_5m, + firstacquidate => '1972-02-10', + countissuesperunit => 1, + }; + is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09'), 1, 'Jul 9 still 1' ); + is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10'), 2, 'Jul 10 goes to 2' ); + is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09'), 3, 'May 9 still 3' ); + is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10'), 4, 'May 10 goes to 4' ); + + # TEST CASE - 4 issue per 1 months + $subscription = { + periodicity => $freq_4i_1m, + firstacquidate => '1972-02-22', + countissuesperunit => 1, + }; + is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28'), 1, 'Feb 28 still 1' ); + is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29'), 2, 'Feb 29 goes to 2' ); + is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21'), 4, 'Mar 21 still 4' ); + is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22'), 5, 'Mar 22 goes to 5' ); + +}; + # TODO: subtest 'Tests for weekly frequencies' => sub { # TODO: subtest 'Tests for dayly frequencies' => sub { diff --git a/t/db_dependent/Serials/GetNextDate.t b/t/db_dependent/Serials/GetNextDate.t index 44dd529..7b29e88 100644 --- a/t/db_dependent/Serials/GetNextDate.t +++ b/t/db_dependent/Serials/GetNextDate.t @@ -372,13 +372,13 @@ $subscription = { }; $publisheddate = $subscription->{firstacquidate}; $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-01-16', 'January has 31 days'); +is($publisheddate, '1970-01-16', 'Jan 16'); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-02-01'); +is($publisheddate, '1970-02-01', 'Feb 1'); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-02-15', 'February has only 28 days'); +is($publisheddate, '1970-02-16', 'Feb 16'); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-03-01'); +is($publisheddate, '1970-03-01', 'Mar 1' ); # TEST CASE - 2 issues per month, irregularities $subscription = { @@ -389,15 +389,15 @@ $subscription = { }; $publisheddate = $subscription->{firstacquidate}; $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-01-16', 'January has 31 days'); +is($publisheddate, '1970-01-16', 'Jan 16' ); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-02-15', 'February has only 28 days'); +is($publisheddate, '1970-02-16', 'Feb 16 (skipping Feb 1)' ); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-04-01'); +is($publisheddate, '1970-04-01', 'Apr 1 (skipping Mar 1 and 16)' ); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-04-16', 'April has 30 days'); +is($publisheddate, '1970-04-16', 'Apr 16' ); $publisheddate = GetNextDate($subscription, $publisheddate); -is($publisheddate, '1970-05-01'); +is($publisheddate, '1970-05-01', 'May 1' ); # TEST CASE - 1 issue per year, no irregularity $id = AddSubscriptionFrequency({ -- 2.1.4