Lines 17-32
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 10; |
20 |
use Test::More tests => 15; |
21 |
use t::lib::TestBuilder; |
21 |
use DateTime; |
|
|
22 |
use DateTime::TimeZone; |
22 |
|
23 |
|
|
|
24 |
use t::lib::TestBuilder; |
23 |
use C4::Context; |
25 |
use C4::Context; |
24 |
use C4::Branch; |
26 |
use C4::Branch; |
25 |
use Koha::Database; |
27 |
use Koha::Database; |
26 |
use Koha::DateUtils; |
28 |
use Koha::DateUtils; |
27 |
|
29 |
|
28 |
use DateTime; |
|
|
29 |
use DateTime::TimeZone; |
30 |
|
30 |
|
31 |
BEGIN { |
31 |
BEGIN { |
32 |
use_ok('Koha::Calendar'); |
32 |
use_ok('Koha::Calendar'); |
Lines 119-124
C4::Calendar->new( branchcode => $branch_2 )->insert_single_holiday(
Link Here
|
119 |
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_2 )->is_holiday( $today ), 1, "Today is a holiday for $branch_2" ); |
120 |
is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1"); |
120 |
is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1"); |
121 |
|
121 |
|
|
|
122 |
# Few tests for exception holidays |
123 |
my ( $diff, $cal, $special ); |
124 |
$dbh->do("DELETE FROM special_holidays"); |
125 |
_add_exception( $today, $branch_1, 'Today' ); |
126 |
$cal = Koha::Calendar->new( branchcode => $branch_1 ); |
127 |
$special = $cal->exception_holidays; |
128 |
is( $special->count, 1, 'One exception holiday added' ); |
129 |
|
130 |
my $tomorrow= dt_from_string(); |
131 |
$tomorrow->add_duration( DateTime::Duration->new(days => 1) ); |
132 |
_add_exception( $tomorrow, $branch_1, 'Tomorrow' ); |
133 |
$cal = Koha::Calendar->new( branchcode => $branch_1 ); |
134 |
$special = $cal->exception_holidays; |
135 |
is( $special->count, 2, 'Set of exception holidays contains two dates' ); |
136 |
|
137 |
$diff = $today->delta_days( $special->min )->in_units('days'); |
138 |
is( $diff, 0, 'Lowest exception holiday is today' ); |
139 |
$diff = $tomorrow->delta_days( $special->max )->in_units('days'); |
140 |
is( $diff, 0, 'Highest exception holiday is tomorrow' ); |
141 |
|
142 |
C4::Calendar->new( branchcode => $branch_1 )->delete_holiday( |
143 |
weekday => $tomorrow->day_of_week, |
144 |
day => $tomorrow->day, |
145 |
month => $tomorrow->month, |
146 |
year => $tomorrow->year, |
147 |
); |
148 |
$cal = Koha::Calendar->new( branchcode => $branch_1 ); |
149 |
$special = $cal->exception_holidays; |
150 |
is( $special->count, 1, 'Set of exception holidays back to one' ); |
151 |
|
152 |
sub _add_exception { |
153 |
my ( $dt, $branch, $descr ) = @_; |
154 |
C4::Calendar->new( branchcode => $branch )->insert_exception_holiday( |
155 |
day => $dt->day, |
156 |
month => $dt->month, |
157 |
year => $dt->year, |
158 |
title => $descr, |
159 |
description => $descr, |
160 |
); |
161 |
} |
162 |
|
122 |
$schema->storage->txn_rollback; |
163 |
$schema->storage->txn_rollback; |
123 |
|
164 |
|
124 |
1; |
165 |
1; |
125 |
- |
|
|