Lines 1-40
Link Here
|
1 |
use strict; |
1 |
#!/usr/bin/perl |
2 |
use warnings; |
2 |
|
3 |
use 5.010; |
3 |
# This file is part of Koha. |
4 |
use DateTime; |
4 |
# |
5 |
use DateTime::TimeZone; |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
use Test::More tests => 12; |
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. |
9 |
# |
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. |
14 |
# |
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>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 10; |
21 |
use t::lib::TestBuilder; |
7 |
|
22 |
|
8 |
use C4::Context; |
23 |
use C4::Context; |
9 |
use C4::Branch; |
24 |
use C4::Branch; |
10 |
|
|
|
11 |
use Koha::DateUtils; |
25 |
use Koha::DateUtils; |
12 |
|
26 |
|
13 |
BEGIN { use_ok('Koha::Calendar'); } |
27 |
use DateTime; |
14 |
BEGIN { use_ok('C4::Calendar'); } |
28 |
use DateTime::TimeZone; |
|
|
29 |
|
30 |
BEGIN { |
31 |
use_ok('Koha::Calendar'); |
32 |
use_ok('C4::Calendar'); |
33 |
} |
15 |
|
34 |
|
16 |
my $dbh = C4::Context->dbh(); |
35 |
my $dbh = C4::Context->dbh(); |
17 |
# Start transaction |
36 |
# Start transaction |
18 |
$dbh->{AutoCommit} = 0; |
37 |
$dbh->{AutoCommit} = 0; |
19 |
$dbh->{RaiseError} = 1; |
38 |
$dbh->{RaiseError} = 1; |
20 |
|
39 |
|
21 |
# Add branches if they don't exist |
40 |
my $builder = t::lib::TestBuilder->new(); |
22 |
if (not defined GetBranchDetail('CPL')) { |
41 |
# Create two fresh branches for the tests |
23 |
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'}); |
42 |
my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode }; |
24 |
} |
43 |
my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode }; |
25 |
if (not defined GetBranchDetail('MPL')) { |
|
|
26 |
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'}); |
27 |
} |
28 |
|
44 |
|
29 |
# Make the repeatable_holidays table ONLY the default data. |
45 |
C4::Calendar->new( branchcode => $branch_1 )->insert_week_day_holiday( |
30 |
$dbh->do("DELETE FROM repeatable_holidays"); |
|
|
31 |
C4::Calendar->new( branchcode => 'MPL' )->insert_week_day_holiday( |
32 |
weekday => 0, |
46 |
weekday => 0, |
33 |
title => '', |
47 |
title => '', |
34 |
description => 'Sundays', |
48 |
description => 'Sundays', |
35 |
); |
49 |
); |
|
|
50 |
|
36 |
my $holiday2add = dt_from_string("2015-01-01"); |
51 |
my $holiday2add = dt_from_string("2015-01-01"); |
37 |
C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday( |
52 |
C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday( |
38 |
day => $holiday2add->day(), |
53 |
day => $holiday2add->day(), |
39 |
month => $holiday2add->month(), |
54 |
month => $holiday2add->month(), |
40 |
year => $holiday2add->year(), |
55 |
year => $holiday2add->year(), |
Lines 42-48
C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday(
Link Here
|
42 |
description => "New Year's Day", |
57 |
description => "New Year's Day", |
43 |
); |
58 |
); |
44 |
$holiday2add = dt_from_string("2014-12-25"); |
59 |
$holiday2add = dt_from_string("2014-12-25"); |
45 |
C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday( |
60 |
C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday( |
46 |
day => $holiday2add->day(), |
61 |
day => $holiday2add->day(), |
47 |
month => $holiday2add->month(), |
62 |
month => $holiday2add->month(), |
48 |
year => $holiday2add->year(), |
63 |
year => $holiday2add->year(), |
Lines 50-59
C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday(
Link Here
|
50 |
description => 'Christmas', |
65 |
description => 'Christmas', |
51 |
); |
66 |
); |
52 |
|
67 |
|
53 |
my $branchcode = 'MPL'; |
68 |
my $koha_calendar = Koha::Calendar->new( branchcode => $branch_1 ); |
54 |
|
69 |
my $c4_calendar = C4::Calendar->new( branchcode => $branch_1 ); |
55 |
my $koha_calendar = Koha::Calendar->new( branchcode => $branchcode ); |
|
|
56 |
my $c4_calendar = C4::Calendar->new( branchcode => $branchcode ); |
57 |
|
70 |
|
58 |
isa_ok( $koha_calendar, 'Koha::Calendar', 'Koha::Calendar class returned' ); |
71 |
isa_ok( $koha_calendar, 'Koha::Calendar', 'Koha::Calendar class returned' ); |
59 |
isa_ok( $c4_calendar, 'C4::Calendar', 'C4::Calendar class returned' ); |
72 |
isa_ok( $c4_calendar, 'C4::Calendar', 'C4::Calendar class returned' ); |
Lines 82-91
my $newyear = DateTime->new(
Link Here
|
82 |
is( $koha_calendar->is_holiday($sunday), 1, 'Sunday is a closed day' ); |
95 |
is( $koha_calendar->is_holiday($sunday), 1, 'Sunday is a closed day' ); |
83 |
is( $koha_calendar->is_holiday($monday), 0, 'Monday is not a closed day' ); |
96 |
is( $koha_calendar->is_holiday($monday), 0, 'Monday is not a closed day' ); |
84 |
is( $koha_calendar->is_holiday($christmas), 1, 'Christmas is a closed day' ); |
97 |
is( $koha_calendar->is_holiday($christmas), 1, 'Christmas is a closed day' ); |
85 |
is( $koha_calendar->is_holiday($newyear), 1, 'New Years day is a closed day' ); |
98 |
is( $koha_calendar->is_holiday($newyear), 1, 'New Years day is a closed day' ); |
86 |
|
|
|
87 |
$dbh->do("DELETE FROM repeatable_holidays"); |
88 |
$dbh->do("DELETE FROM special_holidays"); |
89 |
|
99 |
|
90 |
my $custom_holiday = DateTime->new( |
100 |
my $custom_holiday = DateTime->new( |
91 |
year => 2013, |
101 |
year => 2013, |
Lines 93-104
my $custom_holiday = DateTime->new(
Link Here
|
93 |
day => 12, |
103 |
day => 12, |
94 |
); |
104 |
); |
95 |
|
105 |
|
96 |
is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' ); |
|
|
97 |
$koha_calendar->add_dummy_holiday($custom_holiday ); |
98 |
is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' ); |
99 |
|
100 |
my $today = dt_from_string(); |
106 |
my $today = dt_from_string(); |
101 |
C4::Calendar->new( branchcode => 'CPL' )->insert_single_holiday( |
107 |
C4::Calendar->new( branchcode => $branch_2 )->insert_single_holiday( |
102 |
day => $today->day(), |
108 |
day => $today->day(), |
103 |
month => $today->month(), |
109 |
month => $today->month(), |
104 |
year => $today->year(), |
110 |
year => $today->year(), |
Lines 106-112
C4::Calendar->new( branchcode => 'CPL' )->insert_single_holiday(
Link Here
|
106 |
description => "$today", |
112 |
description => "$today", |
107 |
); |
113 |
); |
108 |
|
114 |
|
109 |
is( Koha::Calendar->new( branchcode => 'CPL' )->is_holiday( $today ), 1, "Today is a holiday for CPL" ); |
115 |
is( Koha::Calendar->new( branchcode => $branch_2 )->is_holiday( $today ), 1, "Today is a holiday for $branch_2" ); |
110 |
is( Koha::Calendar->new( branchcode => 'MPL' )->is_holiday( $today ), 0, "Today is not a holiday for MPL"); |
116 |
is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1"); |
111 |
|
117 |
|
112 |
$dbh->rollback; |
118 |
$dbh->rollback; |
113 |
- |
119 |
|
|
|
120 |
1; |