Bug 18697: Adjusting unit tests for weekly serial frequencies
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tue, 30 May 2017 13:56:22 +0000 (15:56 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 19 Jun 2017 18:35:51 +0000 (15:35 -0300)
Corrections and added unit tests following the changes of the first patch.

GetFictiveIssueNumber.t: New subtest for weekly frequencies.

GetNextDate.t: Correcting a few dates one day. If we use 2/week, we will
calculate an interval of 3 days and correct with 4 days at the end of
the cycle. The connection with firstacqui is not relevant anymore.

Test plan:
[1] Run t/db_dependent/Serials/GetFictiveIssueNumber.t
[2] Run t/db_dependent/Serials/GetNextDate.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Serials/GetFictiveIssueNumber.t
t/db_dependent/Serials/GetNextDate.t

index 51cc151..4d72ce8 100644 (file)
@@ -3,7 +3,7 @@
 # This test deals with GetFictiveIssueNumber (from C4::Serials)
 
 use Modern::Perl;
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 use Koha::Database;
 use C4::Serials;
@@ -141,7 +141,44 @@ subtest 'Tests for monthly frequencies' => sub {
 
 };
 
-# TODO: subtest 'Tests for weekly frequencies' => sub {
+subtest 'Tests for weekly frequencies' => sub {
+    plan tests => 4;
+
+    # First add a few frequencies
+    my $freq_1i_7w = AddSubscriptionFrequency({
+        description => "1 issue per 7 weeks",
+        unit => 'week',
+        issuesperunit => 1,
+        unitsperissue => 7,
+    });
+    my $freq_3i_1w = AddSubscriptionFrequency({
+        description => "3 issues per week",
+        unit => 'week',
+        issuesperunit => 3,
+        unitsperissue => 1,
+    });
+
+    # TEST CASE - 1 issue per 7 weeks
+    my $subscription = {
+        periodicity => $freq_1i_7w,
+        firstacquidate => '1972-02-10',
+        countissuesperunit => 1,
+    };
+    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29'), 1, 'Mar 29 still 1' );
+    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30'), 2, 'Mar 30 goes to 2' );
+
+    # TEST CASE - 3 issue per 1 week
+    $subscription = {
+        periodicity => $freq_3i_1w,
+        firstacquidate => '1972-02-03',
+        countissuesperunit => 1,
+    };
+    $subscription->{countissuesperunit} = 3;
+    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09'), 3, 'Feb 9 still 3' );
+    $subscription->{countissuesperunit} = 1;
+    is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10'), 4, 'Feb 10 goes to 4' );
+};
+
 # TODO: subtest 'Tests for dayly frequencies' => sub {
 
 $schema->storage->txn_rollback;
index 7b29e88..a0422d7 100644 (file)
@@ -212,13 +212,11 @@ $subscription = {
 };
 $publisheddate = $subscription->{firstacquidate};
 $publisheddate = GetNextDate($subscription, $publisheddate);
-is($publisheddate, '1970-01-03');
-# when more than 1 issue per week, date is automatically set to the same day of
-# week as firstacquidate
+is($publisheddate, '1970-01-04');
 $publisheddate = GetNextDate($subscription, $publisheddate);
 is($publisheddate, '1970-01-08');
 $publisheddate = GetNextDate($subscription, $publisheddate);
-is($publisheddate, '1970-01-10');
+is($publisheddate, '1970-01-11');
 $publisheddate = GetNextDate($subscription, $publisheddate);
 is($publisheddate, '1970-01-15');
 
@@ -231,13 +229,13 @@ $subscription = {
 };
 $publisheddate = $subscription->{firstacquidate};
 $publisheddate = GetNextDate($subscription, $publisheddate);
-is($publisheddate, '1970-01-03');
+is($publisheddate, '1970-01-04');
 $publisheddate = GetNextDate($subscription, $publisheddate);
-is($publisheddate, '1970-01-10');
+is($publisheddate, '1970-01-11');
 $publisheddate = GetNextDate($subscription, $publisheddate);
 is($publisheddate, '1970-01-22');
 $publisheddate = GetNextDate($subscription, $publisheddate);
-is($publisheddate, '1970-01-24');
+is($publisheddate, '1970-01-25');
 $publisheddate = GetNextDate($subscription, $publisheddate);
 is($publisheddate, '1970-01-29');