From f63c82a30f2e9455ce07085f3030d5160658c9f7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 7 Jul 2020 12:05:42 +0000 Subject: [PATCH] Bug 25850: (QA follow-up) use dt_from_string Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit 92970a9abad312a07d9efba46cc57b27469a0509) Signed-off-by: Lucas Gass --- t/db_dependent/Calendar.t | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t index 80991dbe3f..5bddcbe56b 100644 --- a/t/db_dependent/Calendar.t +++ b/t/db_dependent/Calendar.t @@ -291,6 +291,47 @@ subtest 'hours_between | days_between' => sub { }; + Time::Fake->reset; +}; + +subtest 'is_holiday' => sub { + plan tests => 1; + + subtest 'weekday holidays' => sub { + plan tests => 7; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $day = dt_from_string(); + my $dow = scalar $day->day_of_week; + $dow = 0 if $dow == 7; + + # Closed this day of the week + my $dbh = C4::Context->dbh; + $dbh->do( + q| + INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description) + VALUES ( ?, ?, NULL, NULL, ?, '' ) + |, undef, $library->branchcode, $dow, "TEST" + ); + + # Iterate 7 days + my $sth = $dbh->prepare( +"UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'" + ); + for my $i ( 0 .. 6 ) { + my $calendar = + Koha::Calendar->new( branchcode => $library->branchcode ); + + is( $calendar->is_holiday($day), 1, $day->day_name() ." works as a repeatable holiday"); + + # Increment the date and holiday day + $day->add( days => 1 ); + $dow++; + $dow = 0 if $dow == 7; + $sth->execute($dow, $library->branchcode); + } + }; }; subtest 'get_push_amt' => sub { @@ -303,7 +344,7 @@ subtest 'get_push_amt' => sub { my $library = $builder->build_object( { class => 'Koha::Libraries' } ); - my $day = DateTime->now(); + my $day = dt_from_string(); my $dow = scalar $day->day_of_week; $dow = 0 if $dow == 7; -- 2.39.5