|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 12; |
20 |
use Test::More tests => 14; |
|
|
21 |
use Test::Exception; |
| 21 |
|
22 |
|
| 22 |
use DateTime; |
23 |
use DateTime; |
| 23 |
use DateTime::TimeZone; |
24 |
use DateTime::TimeZone; |
|
Lines 277-281
subtest 'copy_to_branch' => sub {
Link Here
|
| 277 |
|
278 |
|
| 278 |
}; |
279 |
}; |
| 279 |
|
280 |
|
|
|
281 |
subtest 'with a library that is never open' => sub { |
| 282 |
plan tests => 2; |
| 283 |
|
| 284 |
$schema->storage->txn_begin; |
| 285 |
|
| 286 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 287 |
my $calendar = C4::Calendar->new( branchcode => $branchcode ); |
| 288 |
foreach my $weekday ( 0 .. 6 ) { |
| 289 |
$calendar->insert_week_day_holiday( weekday => $weekday, title => '', description => '' ); |
| 290 |
} |
| 291 |
|
| 292 |
my $now = DateTime->now; |
| 293 |
|
| 294 |
subtest 'next_open_days should throw an exception' => sub { |
| 295 |
my $kcalendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); |
| 296 |
throws_ok { $kcalendar->next_open_days( $now, 1 ) } 'Koha::Exceptions::Calendar::NoOpenDays'; |
| 297 |
}; |
| 298 |
|
| 299 |
subtest 'prev_open_days should throw an exception' => sub { |
| 300 |
my $kcalendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); |
| 301 |
throws_ok { $kcalendar->prev_open_days( $now, 1 ) } 'Koha::Exceptions::Calendar::NoOpenDays'; |
| 302 |
}; |
| 303 |
|
| 304 |
$schema->storage->txn_rollback; |
| 305 |
}; |
| 306 |
|
| 307 |
subtest 'with a library that is *almost* never open' => sub { |
| 308 |
plan tests => 2; |
| 309 |
|
| 310 |
$schema->storage->txn_begin; |
| 311 |
|
| 312 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 313 |
my $calendar = C4::Calendar->new( branchcode => $branchcode ); |
| 314 |
foreach my $weekday ( 0 .. 6 ) { |
| 315 |
$calendar->insert_week_day_holiday( weekday => $weekday, title => '', description => '' ); |
| 316 |
} |
| 317 |
|
| 318 |
my $now = DateTime->now; |
| 319 |
my $open_day_in_the_future = $now->clone()->add( years => 1 ); |
| 320 |
my $open_day_in_the_past = $now->clone()->subtract( years => 1 ); |
| 321 |
$calendar->insert_exception_holiday( date => $open_day_in_the_future->ymd, title => '', description => '' ); |
| 322 |
$calendar->insert_exception_holiday( date => $open_day_in_the_past->ymd, title => '', description => '' ); |
| 323 |
|
| 324 |
subtest 'next_open_days should find the open day' => sub { |
| 325 |
my $kcalendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); |
| 326 |
my $next_open_day = $kcalendar->next_open_days( $now, 1 ); |
| 327 |
is( $next_open_day->ymd, $open_day_in_the_future->ymd ); |
| 328 |
}; |
| 329 |
|
| 330 |
subtest 'prev_open_days should find the open day' => sub { |
| 331 |
my $kcalendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); |
| 332 |
my $prev_open_day = $kcalendar->prev_open_days( $now, 1 ); |
| 333 |
is( $prev_open_day->ymd, $open_day_in_the_past->ymd ); |
| 334 |
}; |
| 335 |
|
| 336 |
$schema->storage->txn_rollback; |
| 337 |
}; |
| 338 |
|
| 280 |
# Clear cache |
339 |
# Clear cache |
| 281 |
Koha::Caches->get_instance->flush_all; |
340 |
Koha::Caches->get_instance->flush_all; |
| 282 |
- |
|
|