3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 10;
21 use t::lib::TestBuilder;
28 use DateTime::TimeZone;
31 use_ok('Koha::Calendar');
32 use_ok('C4::Calendar');
35 my $dbh = C4::Context->dbh();
37 $dbh->{AutoCommit} = 0;
38 $dbh->{RaiseError} = 1;
40 my $builder = t::lib::TestBuilder->new();
41 # Create two fresh branches for the tests
42 my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
43 my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode };
45 C4::Calendar->new( branchcode => $branch_1 )->insert_week_day_holiday(
48 description => 'Sundays',
51 my $holiday2add = dt_from_string("2015-01-01");
52 C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday(
53 day => $holiday2add->day(),
54 month => $holiday2add->month(),
55 year => $holiday2add->year(),
57 description => "New Year's Day",
59 $holiday2add = dt_from_string("2014-12-25");
60 C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday(
61 day => $holiday2add->day(),
62 month => $holiday2add->month(),
63 year => $holiday2add->year(),
65 description => 'Christmas',
68 my $koha_calendar = Koha::Calendar->new( branchcode => $branch_1 );
69 my $c4_calendar = C4::Calendar->new( branchcode => $branch_1 );
71 isa_ok( $koha_calendar, 'Koha::Calendar', 'Koha::Calendar class returned' );
72 isa_ok( $c4_calendar, 'C4::Calendar', 'C4::Calendar class returned' );
74 my $sunday = DateTime->new(
79 my $monday = DateTime->new(
84 my $christmas = DateTime->new(
89 my $newyear = DateTime->new(
95 is( $koha_calendar->is_holiday($sunday), 1, 'Sunday is a closed day' );
96 is( $koha_calendar->is_holiday($monday), 0, 'Monday is not a closed day' );
97 is( $koha_calendar->is_holiday($christmas), 1, 'Christmas is a closed day' );
98 is( $koha_calendar->is_holiday($newyear), 1, 'New Years day is a closed day' );
100 $dbh->do("DELETE FROM repeatable_holidays");
101 $dbh->do("DELETE FROM special_holidays");
103 my $custom_holiday = DateTime->new(
109 my $today = dt_from_string();
110 C4::Calendar->new( branchcode => $branch_2 )->insert_single_holiday(
111 day => $today->day(),
112 month => $today->month(),
113 year => $today->year(),
115 description => "$today",
118 is( Koha::Calendar->new( branchcode => $branch_2 )->is_holiday( $today ), 1, "Today is a holiday for $branch_2" );
119 is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1");