Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
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. |
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 => 5; |
21 |
use t::lib::TestBuilder; |
22 |
|
23 |
use DateTime; |
24 |
use Koha::Caches; |
25 |
use Koha::DateUtils; |
26 |
|
27 |
use_ok('Koha::Calendar'); |
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
30 |
$schema->storage->txn_begin; |
31 |
|
32 |
my $today = dt_from_string(); |
33 |
my $holiday_dt = $today->clone; |
34 |
$holiday_dt->add(days => 15); |
35 |
|
36 |
Koha::Caches->get_instance()->flush_all(); |
37 |
|
38 |
my $builder = t::lib::TestBuilder->new(); |
39 |
my $holiday = $builder->build({ |
40 |
source => 'SpecialHoliday', |
41 |
value => { |
42 |
branchcode => 'LIB1', |
43 |
day => $holiday_dt->day, |
44 |
month => $holiday_dt->month, |
45 |
year => $holiday_dt->year, |
46 |
title => 'My holiday', |
47 |
isexception => 0 |
48 |
}, |
49 |
}); |
50 |
|
51 |
my $calendar = Koha::Calendar->new( branchcode => 'LIB1'); |
52 |
my $forwarded_dt = $calendar->days_forward($today, 10); |
53 |
|
54 |
my $expected = $today->clone; |
55 |
$expected->add(days => 10); |
56 |
is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days'); |
57 |
|
58 |
$forwarded_dt = $calendar->days_forward($today, 20); |
59 |
|
60 |
$expected->add(days => 11); |
61 |
is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday'); |
62 |
|
63 |
$forwarded_dt = $calendar->days_forward($today, 0); |
64 |
is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt'); |
65 |
|
66 |
$forwarded_dt = $calendar->days_forward($today, -2); |
67 |
is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt'); |
68 |
|
69 |
$schema->storage->txn_rollback(); |