Bug 25723: (QA follow-up) Handle holiday and exception on same day
authorNick Clemens <nick@bywatersolutions.com>
Fri, 17 Jul 2020 12:34:18 +0000 (12:34 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 20 Jul 2020 15:45:31 +0000 (17:45 +0200)
When a holiday is entered, then exceptions generated on a range, there exists both a holiday and exception in
the special holidays table. We should cache the exception over the holiday instead of both

Also, !1 in perl returns '' rather than 0, so we should explicitly set the value

Add blank line to clear pod error from qa tools

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Re-introduce the blank line mentioned in the commit message, it was accidentally removed by automatic formatting
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Calendar.pm
Koha/Calendar.pm
t/Calendar.t

index 7b94537..6a5d8a7 100644 (file)
@@ -733,3 +733,4 @@ __END__
 Koha Physics Library UNLP <matias_veleda@hotmail.com>
 
 =cut
+
index c0dcd8e..c3210d4 100644 (file)
@@ -71,7 +71,7 @@ sub _holidays {
 
         # Add holidays for each branch
         my $holidays_sth = $dbh->prepare(
-'SELECT day, month, year, isexception FROM special_holidays WHERE branchcode = ?'
+'SELECT day, month, year, MAX(isexception) FROM special_holidays WHERE branchcode = ? GROUP BY day, month, year'
         );
         $holidays_sth->execute($self->{branchcode});
 
@@ -83,11 +83,10 @@ sub _holidays {
               . sprintf( "%02d", $month )
               . sprintf( "%02d", $day );
 
-            $holidays->{$datestring} = !$exception;
+            $holidays->{$datestring} = $exception ? 0 : 1;
         }
         $cache->set_in_cache( $key, $holidays, { expiry => 76800 } );
     }
-
     return $holidays // {};
 }
 
index 8657bc4..b4b94bf 100755 (executable)
@@ -31,7 +31,7 @@ use Module::Load::Conditional qw/check_install/;
 
 BEGIN {
     if ( check_install( module => 'Test::DBIx::Class' ) ) {
-        plan tests => 39;
+        plan tests => 40;
     } else {
         plan skip_all => "Need Test::DBIx::Class"
     }
@@ -73,6 +73,8 @@ fixtures_ok [
         [ 'MPL', 1,  6,  2011, '', '', 0 ],
         [ 'MPL', 4,  7,  2012, '', '', 0 ],
         [ 'CPL', 6,  8,  2012, '', '', 0 ],
+        [ 'MPL', 7,  7,  2012, '', '', 1 ], # holiday exception
+        [ 'MPL', 7,  7,  2012, '', '', 0 ], # holiday
       ],
 ], "add fixtures";
 
@@ -139,6 +141,12 @@ my $holiday_for_another_branch = DateTime->new(
     day => 6, # This is a monday
 );
 
+my $holiday_excepted = DateTime->new(
+    year => 2012,
+    month => 7,
+    day => 7, # Both a holiday and exception
+);
+
 {   # Syspref-agnostic tests
     is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
     is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)');
@@ -151,6 +159,7 @@ my $holiday_for_another_branch = DateTime->new(
     is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' );
     is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
     is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' );
+    is ( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' );
 }
 
 {   # Bugzilla #8966 - is_holiday truncates referenced date