Bug 16376: (regression tests)
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 6 Dec 2016 14:29:08 +0000 (11:29 -0300)
committerJulian Maurice <julian.maurice@biblibre.com>
Mon, 2 Jan 2017 10:50:49 +0000 (11:50 +0100)
This patch introduces a regression test for exception_holidays. This routine
returns a list of datetimes to be used in date comparison and some datetimes don't exist
in some timezones, so floating timezones should be used instead.

To test:
- Apply the patch on master
- Run:
  $ prove t/db_dependent/Holidays.t
=> FAIL: The new test fails

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit c6a0848ff0b7acbec4d7bf817447d7cc84c0615e)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
(cherry picked from commit aa5c67486f297dbdaa1ba7b6665916a3d2cc05f5)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

t/db_dependent/Holidays.t

index 07e54cf..59d2193 100755 (executable)
@@ -17,7 +17,8 @@
 
 use Modern::Perl;
 
-use Test::More tests => 15;
+use Test::More tests => 16;
+
 use DateTime;
 use DateTime::TimeZone;
 
@@ -34,11 +35,50 @@ BEGIN {
 }
 
 my $schema = Koha::Database->new->schema;
-$schema->storage->txn_begin;
+my $dbh = C4::Context->dbh;
+my $builder = t::lib::TestBuilder->new;
+
+subtest 'exception_holidays() tests' => sub {
+
+    plan tests => 1;
+
+    $schema->storage->txn_begin;
+
+    $dbh->do("DELETE FROM special_holidays");
+
+    # Artificially set timezone
+    my $timezone = 'America/Santiago';
+    $ENV{TZ} = $timezone;
+    use POSIX qw(tzset);
+    tzset;
+
+    my $branch = $builder->build( { source => 'Branch' } )->{branchcode};
+    my $calendar = Koha::Calendar->new( branchcode => $branch );
 
-my $dbh = C4::Context->dbh();
+    C4::Calendar->new( branchcode => $branch )->insert_exception_holiday(
+        day         => 6,
+        month       => 9,
+        year        => 2015,
+        title       => 'Invalid date',
+        description => 'Invalid date description',
+    );
+
+    my $exception_holiday = $calendar->exception_holidays->iterator->next;
+    my $now_dt            = DateTime->now;
+
+    my $diff;
+    eval { $diff = $calendar->days_between( $now_dt, $exception_holiday ) };
+    unlike(
+        $@,
+        qr/Invalid local time for date in time zone: America\/Santiago/,
+        'Avoid invalid datetime due to DST'
+    );
+
+    $schema->storage->txn_rollback;
+};
+
+$schema->storage->txn_begin;
 
-my $builder = t::lib::TestBuilder->new();
 # Create two fresh branches for the tests
 my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
 my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode };