View | Details | Raw Unified | Return to bug 33727
Collapse All | Expand All

(-)a/t/Calendar.t (-312 lines)
Lines 1-312 Link Here
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 => 38;
21
use Test::MockModule;
22
23
use DateTime;
24
use DateTime::Duration;
25
use Koha::Caches;
26
use Koha::Calendar;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
29
30
use t::lib::Mocks;
31
use t::lib::TestBuilder;
32
33
my $builder = t::lib::TestBuilder->new;
34
my $schema = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
36
37
# We need to mock the C4::Context->preference method for
38
# simplicity and re-usability of the session definition. Any
39
# syspref fits for syspref-agnostic tests.
40
my $module_context = Test::MockModule->new('C4::Context');
41
$module_context->mock(
42
    'preference',
43
    sub {
44
        return 'Calendar';
45
    }
46
);
47
48
my $mpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
49
my $cpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
50
my $rows = [ # add weekly holidays
51
    { branchcode => $mpl, weekday => 0 }, # sundays
52
    { branchcode => $mpl, weekday => 6 }, # saturdays
53
    { branchcode => $mpl, day => 1, month => 1 },      # new year's day
54
    { branchcode => $mpl, day => 25, month => 12 },    # chrismas
55
];
56
$schema->resultset('RepeatableHoliday')->delete_all;
57
$schema->resultset('RepeatableHoliday')->create({ %$_, description => q{} }) for @$rows;
58
59
$rows = [ # exception holidays
60
    { branchcode => $mpl, day => 11, month => 11, year => 2012, isexception => 1 },    # sunday exception
61
    { branchcode => $mpl, day => 1,  month => 6,  year => 2011, isexception => 0 },
62
    { branchcode => $mpl, day => 4,  month => 7,  year => 2012, isexception => 0 },
63
    { branchcode => $cpl, day => 6,  month => 8,  year => 2012, isexception => 0 },
64
    { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 1 }, # holiday exception
65
    { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 0 }, # holiday
66
];
67
$schema->resultset('SpecialHoliday')->delete_all;
68
$schema->resultset('SpecialHoliday')->create({ %$_, description => q{} }) for @$rows;
69
70
my $cache = Koha::Caches->get_instance();
71
$cache->clear_from_cache('MPL_holidays');
72
$cache->clear_from_cache('CPL_holidays');
73
74
# $mpl branch is arbitrary, is not used at all but is needed for initialization
75
my $cal = Koha::Calendar->new( branchcode => $mpl );
76
77
isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
78
79
my $saturday = DateTime->new(
80
    year      => 2012,
81
    month     => 11,
82
    day       => 24,
83
);
84
85
my $sunday = DateTime->new(
86
    year      => 2012,
87
    month     => 11,
88
    day       => 25,
89
);
90
91
my $monday = DateTime->new(
92
    year      => 2012,
93
    month     => 11,
94
    day       => 26,
95
);
96
97
my $new_year = DateTime->new(
98
    year        => 2013,
99
    month       => 1,
100
    day         => 1,
101
);
102
103
my $single_holiday = DateTime->new(
104
    year      => 2011,
105
    month     => 6,
106
    day       => 1,
107
);    # should be a holiday
108
109
my $notspecial = DateTime->new(
110
    year      => 2011,
111
    month     => 6,
112
    day       => 2
113
);    # should NOT be a holiday
114
115
my $sunday_exception = DateTime->new(
116
    year      => 2012,
117
    month     => 11,
118
    day       => 11
119
);
120
121
my $day_after_christmas = DateTime->new(
122
    year    => 2012,
123
    month   => 12,
124
    day     => 26
125
);  # for testing negative addDuration
126
127
my $holiday_for_another_branch = DateTime->new(
128
    year => 2012,
129
    month => 8,
130
    day => 6, # This is a monday
131
);
132
133
my $holiday_excepted = DateTime->new(
134
    year => 2012,
135
    month => 7,
136
    day => 7, # Both a holiday and exception
137
);
138
139
{   # Syspref-agnostic tests
140
    is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
141
    is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)');
142
    is ( $monday->day_of_week, 1, '\'$monday\' is actually a monday (1st day of week)');
143
    is ( $cal->is_holiday($saturday), 1, 'Saturday is a closed day' );
144
    is ( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' );
145
    is ( $cal->is_holiday($monday), 0, 'Monday is not a closed day' );
146
    is ( $cal->is_holiday($new_year), 1, 'Month/Day closed day test (New year\'s day)' );
147
    is ( $cal->is_holiday($single_holiday), 1, 'Single holiday closed day test' );
148
    is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' );
149
    is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
150
    is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' );
151
    is ( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' );
152
}
153
154
{   # Bugzilla #8966 - is_holiday truncates referenced date
155
    my $later_dt = DateTime->new(    # Monday
156
        year      => 2012,
157
        month     => 9,
158
        day       => 17,
159
        hour      => 17,
160
        minute    => 30,
161
        time_zone => 'Europe/London',
162
    );
163
164
165
    is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' );
166
    cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
167
}
168
169
{   # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
170
    my $single_holiday_time = DateTime->new(
171
        year  => 2011,
172
        month => 6,
173
        day   => 1,
174
        hour  => 11,
175
        minute  => 2
176
    );
177
178
    is( $cal->is_holiday($single_holiday_time),
179
        $cal->is_holiday($single_holiday) ,
180
        'bz-8800 is_holiday should truncate the date for holiday validation' );
181
}
182
183
    my $one_day_dur = DateTime::Duration->new( days => 1 );
184
    my $two_day_dur = DateTime::Duration->new( days => 2 );
185
    my $seven_day_dur = DateTime::Duration->new( days => 7 );
186
187
    my $dt = dt_from_string( '2012-07-03','iso' ); #tuesday
188
189
    my $test_dt = DateTime->new(    # Monday
190
        year      => 2012,
191
        month     => 7,
192
        day       => 23,
193
        hour      => 11,
194
        minute    => 53,
195
    );
196
197
    my $later_dt = DateTime->new(    # Monday
198
        year      => 2012,
199
        month     => 9,
200
        day       => 17,
201
        hour      => 17,
202
        minute    => 30,
203
        time_zone => 'Europe/London',
204
    );
205
206
{    ## 'Datedue' tests
207
208
    $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Datedue' );
209
210
    is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
211
        dt_from_string('2012-07-05','iso'),
212
        'Single day add (Datedue, matches holiday, shift)' );
213
214
    is($cal->addDuration( $dt, $two_day_dur, 'days' ),
215
        dt_from_string('2012-07-05','iso'),
216
        'Two days add, skips holiday (Datedue)' );
217
218
    cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
219
        '2012-07-30T11:53:00',
220
        'Add 7 days (Datedue)' );
221
222
    is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
223
        'addDuration skips closed Sunday (Datedue)' );
224
225
    is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
226
        'Negative call to addDuration (Datedue)' );
227
228
    ## Note that the days_between API says closed days are not considered.
229
    ## This tests are here as an API test.
230
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
231
                '==', 40, 'days_between calculates correctly (Days)' );
232
233
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
234
                '==', 40, 'Test parameter order not relevant (Days)' );
235
}
236
237
{   ## 'Calendar' tests'
238
239
    $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Calendar' );
240
241
    $dt = dt_from_string('2012-07-03','iso');
242
243
    is($cal->addDuration( $dt, $one_day_dur, 'days' ),
244
        dt_from_string('2012-07-05','iso'),
245
        'Single day add (Calendar)' );
246
247
    cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
248
       '2012-08-01T11:53:00',
249
       'Add 7 days (Calendar)' );
250
251
    is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
252
            'addDuration skips closed Sunday (Calendar)' );
253
254
    is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
255
            'Negative call to addDuration (Calendar)' );
256
257
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
258
                '==', 40, 'days_between calculates correctly (Calendar)' );
259
260
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
261
                '==', 40, 'Test parameter order not relevant (Calendar)' );
262
}
263
264
265
{   ## 'Days' tests
266
267
    $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Days' );
268
269
    $dt = dt_from_string('2012-07-03','iso');
270
271
    is($cal->addDuration( $dt, $one_day_dur, 'days' ),
272
        dt_from_string('2012-07-04','iso'),
273
        'Single day add (Days)' );
274
275
    cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ),'eq',
276
        '2012-07-30T11:53:00',
277
        'Add 7 days (Days)' );
278
279
    is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
280
        'addDuration doesn\'t skip closed Sunday (Days)' );
281
282
    is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
283
        'Negative call to addDuration (Days)' );
284
285
    ## Note that the days_between API says closed days are not considered.
286
    ## This tests are here as an API test.
287
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
288
                '==', 40, 'days_between calculates correctly (Days)' );
289
290
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
291
                '==', 40, 'Test parameter order not relevant (Days)' );
292
293
}
294
295
{
296
    $cal = Koha::Calendar->new( branchcode => $cpl );
297
    is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
298
    is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' );
299
}
300
301
subtest 'days_mode parameter' => sub {
302
    plan tests => 1;
303
304
    t::lib::Mocks::mock_preference('useDaysMode', 'Days');
305
306
    $cal = Koha::Calendar->new( branchcode => $cpl, days_mode => 'Calendar' );
307
    is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|);
308
};
309
310
$cache->clear_from_cache('MPL_holidays');
311
$cache->clear_from_cache('CPL_holidays');
312
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Calendar.t (-7 / +284 lines)
Lines 24-35 use t::lib::Mocks; Link Here
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
26
use DateTime;
26
use DateTime;
27
use DateTime::Duration;
27
use Koha::Caches;
28
use Koha::Caches;
29
use Koha::Calendar;
30
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
31
use Koha::DateUtils qw( dt_from_string );
29
32
30
use_ok('Koha::Calendar');
31
32
my $schema  = Koha::Database->new->schema;
33
my $schema  = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
33
$schema->storage->txn_begin;
35
$schema->storage->txn_begin;
34
36
35
my $today = dt_from_string();
37
my $today = dt_from_string();
Lines 38-45 $holiday_dt->add(days => 3); Link Here
38
40
39
Koha::Caches->get_instance()->flush_all();
41
Koha::Caches->get_instance()->flush_all();
40
42
41
my $builder = t::lib::TestBuilder->new();
43
subtest 'Original tests from t' => sub {
44
    # We need to mock the C4::Context->preference method for
45
    # simplicity and re-usability of the session definition. Any
46
    # syspref fits for syspref-agnostic tests.
47
    my $module_context = Test::MockModule->new('C4::Context');
48
    $module_context->mock(
49
        'preference',
50
        sub {
51
            return 'Calendar';
52
        }
53
    );
54
55
    my $mpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
56
    my $cpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
57
    my $rows = [ # add weekly holidays
58
        { branchcode => $mpl, weekday => 0 }, # sundays
59
        { branchcode => $mpl, weekday => 6 }, # saturdays
60
        { branchcode => $mpl, day => 1, month => 1 },      # new year's day
61
        { branchcode => $mpl, day => 25, month => 12 },    # chrismas
62
    ];
63
    $schema->resultset('RepeatableHoliday')->delete_all;
64
    $schema->resultset('RepeatableHoliday')->create({ %$_, description => q{} }) for @$rows;
65
66
    $rows = [ # exception holidays
67
        { branchcode => $mpl, day => 11, month => 11, year => 2012, isexception => 1 },    # sunday exception
68
        { branchcode => $mpl, day => 1,  month => 6,  year => 2011, isexception => 0 },
69
        { branchcode => $mpl, day => 4,  month => 7,  year => 2012, isexception => 0 },
70
        { branchcode => $cpl, day => 6,  month => 8,  year => 2012, isexception => 0 },
71
        { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 1 }, # holiday exception
72
        { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 0 }, # holiday
73
    ];
74
    $schema->resultset('SpecialHoliday')->delete_all;
75
    $schema->resultset('SpecialHoliday')->create({ %$_, description => q{} }) for @$rows;
76
77
    my $cache = Koha::Caches->get_instance();
78
    $cache->clear_from_cache( $mpl.'_holidays' );
79
    $cache->clear_from_cache( $cpl.'_holidays' );
80
81
    # $mpl branch is arbitrary, is not used at all but is needed for initialization
82
    my $cal = Koha::Calendar->new( branchcode => $mpl );
83
84
    isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
85
86
    my $saturday = DateTime->new(
87
        year      => 2012,
88
        month     => 11,
89
        day       => 24,
90
    );
91
92
    my $sunday = DateTime->new(
93
        year      => 2012,
94
        month     => 11,
95
        day       => 25,
96
    );
97
98
    my $monday = DateTime->new(
99
        year      => 2012,
100
        month     => 11,
101
        day       => 26,
102
    );
103
104
    my $new_year = DateTime->new(
105
        year        => 2013,
106
        month       => 1,
107
        day         => 1,
108
    );
109
110
    my $single_holiday = DateTime->new(
111
        year      => 2011,
112
        month     => 6,
113
        day       => 1,
114
    );    # should be a holiday
115
116
    my $notspecial = DateTime->new(
117
        year      => 2011,
118
        month     => 6,
119
        day       => 2
120
    );    # should NOT be a holiday
121
122
    my $sunday_exception = DateTime->new(
123
        year      => 2012,
124
        month     => 11,
125
        day       => 11
126
    );
127
128
    my $day_after_christmas = DateTime->new(
129
        year    => 2012,
130
        month   => 12,
131
        day     => 26
132
    );  # for testing negative addDuration
133
134
    my $holiday_for_another_branch = DateTime->new(
135
        year => 2012,
136
        month => 8,
137
        day => 6, # This is a monday
138
    );
139
140
    my $holiday_excepted = DateTime->new(
141
        year => 2012,
142
        month => 7,
143
        day => 7, # Both a holiday and exception
144
    );
145
146
    {   # Syspref-agnostic tests
147
        is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
148
        is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)');
149
        is ( $monday->day_of_week, 1, '\'$monday\' is actually a monday (1st day of week)');
150
        is ( $cal->is_holiday($saturday), 1, 'Saturday is a closed day' );
151
        is ( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' );
152
        is ( $cal->is_holiday($monday), 0, 'Monday is not a closed day' );
153
        is ( $cal->is_holiday($new_year), 1, 'Month/Day closed day test (New year\'s day)' );
154
        is ( $cal->is_holiday($single_holiday), 1, 'Single holiday closed day test' );
155
        is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' );
156
        is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
157
        is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' );
158
        is ( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' );
159
    }
160
161
    {   # Bugzilla #8966 - is_holiday truncates referenced date
162
        my $later_dt = DateTime->new(    # Monday
163
            year      => 2012,
164
            month     => 9,
165
            day       => 17,
166
            hour      => 17,
167
            minute    => 30,
168
            time_zone => 'Europe/London',
169
        );
170
171
172
        is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' );
173
        cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
174
    }
175
176
    {   # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
177
        my $single_holiday_time = DateTime->new(
178
            year  => 2011,
179
            month => 6,
180
            day   => 1,
181
            hour  => 11,
182
            minute  => 2
183
        );
184
185
        is( $cal->is_holiday($single_holiday_time),
186
            $cal->is_holiday($single_holiday) ,
187
            'bz-8800 is_holiday should truncate the date for holiday validation' );
188
    }
189
190
        my $one_day_dur = DateTime::Duration->new( days => 1 );
191
        my $two_day_dur = DateTime::Duration->new( days => 2 );
192
        my $seven_day_dur = DateTime::Duration->new( days => 7 );
193
194
        my $dt = dt_from_string( '2012-07-03','iso' ); #tuesday
195
196
        my $test_dt = DateTime->new(    # Monday
197
            year      => 2012,
198
            month     => 7,
199
            day       => 23,
200
            hour      => 11,
201
            minute    => 53,
202
        );
203
204
        my $later_dt = DateTime->new(    # Monday
205
            year      => 2012,
206
            month     => 9,
207
            day       => 17,
208
            hour      => 17,
209
            minute    => 30,
210
            time_zone => 'Europe/London',
211
        );
212
213
    {    ## 'Datedue' tests
214
215
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Datedue' );
216
217
        is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
218
            dt_from_string('2012-07-05','iso'),
219
            'Single day add (Datedue, matches holiday, shift)' );
220
221
        is($cal->addDuration( $dt, $two_day_dur, 'days' ),
222
            dt_from_string('2012-07-05','iso'),
223
            'Two days add, skips holiday (Datedue)' );
224
225
        cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
226
            '2012-07-30T11:53:00',
227
            'Add 7 days (Datedue)' );
228
229
        is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
230
            'addDuration skips closed Sunday (Datedue)' );
231
232
        is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
233
            'Negative call to addDuration (Datedue)' );
234
235
        ## Note that the days_between API says closed days are not considered.
236
        ## This tests are here as an API test.
237
        cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
238
                    '==', 40, 'days_between calculates correctly (Days)' );
239
240
        cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
241
                    '==', 40, 'Test parameter order not relevant (Days)' );
242
    }
243
244
    {   ## 'Calendar' tests'
245
246
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Calendar' );
247
248
        $dt = dt_from_string('2012-07-03','iso');
249
250
        is($cal->addDuration( $dt, $one_day_dur, 'days' ),
251
            dt_from_string('2012-07-05','iso'),
252
            'Single day add (Calendar)' );
253
254
        cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
255
           '2012-08-01T11:53:00',
256
           'Add 7 days (Calendar)' );
257
258
        is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
259
                'addDuration skips closed Sunday (Calendar)' );
260
261
        is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
262
                'Negative call to addDuration (Calendar)' );
263
264
        cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
265
                    '==', 40, 'days_between calculates correctly (Calendar)' );
266
267
        cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
268
                    '==', 40, 'Test parameter order not relevant (Calendar)' );
269
    }
270
271
272
    {   ## 'Days' tests
273
274
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Days' );
275
276
        $dt = dt_from_string('2012-07-03','iso');
277
278
        is($cal->addDuration( $dt, $one_day_dur, 'days' ),
279
            dt_from_string('2012-07-04','iso'),
280
            'Single day add (Days)' );
281
282
        cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ),'eq',
283
            '2012-07-30T11:53:00',
284
            'Add 7 days (Days)' );
285
286
        is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
287
            'addDuration doesn\'t skip closed Sunday (Days)' );
288
289
        is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
290
            'Negative call to addDuration (Days)' );
291
292
        ## Note that the days_between API says closed days are not considered.
293
        ## This tests are here as an API test.
294
        cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
295
                    '==', 40, 'days_between calculates correctly (Days)' );
296
297
        cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
298
                    '==', 40, 'Test parameter order not relevant (Days)' );
299
300
    }
301
302
    {
303
        $cal = Koha::Calendar->new( branchcode => $cpl );
304
        is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
305
        is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' );
306
    }
307
308
    subtest 'days_mode parameter' => sub {
309
        plan tests => 1;
310
311
        t::lib::Mocks::mock_preference('useDaysMode', 'Days');
312
313
        $cal = Koha::Calendar->new( branchcode => $cpl, days_mode => 'Calendar' );
314
        is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|);
315
    };
316
317
    $cache->clear_from_cache( $mpl.'_holidays' );
318
    $cache->clear_from_cache( $cpl.'_holidays' );
319
};
320
42
my $library = $builder->build_object({ class => 'Koha::Libraries' });
321
my $library = $builder->build_object({ class => 'Koha::Libraries' });
322
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Calendar' );
43
my $holiday = $builder->build(
323
my $holiday = $builder->build(
44
    {
324
    {
45
        source => 'SpecialHoliday',
325
        source => 'SpecialHoliday',
Lines 54-64 my $holiday = $builder->build( Link Here
54
    }
334
    }
55
);
335
);
56
336
57
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Calendar' );
58
59
subtest 'days_forward' => sub {
337
subtest 'days_forward' => sub {
60
61
    plan tests => 4;
338
    plan tests => 4;
339
62
    my $forwarded_dt = $calendar->days_forward( $today, 2 );
340
    my $forwarded_dt = $calendar->days_forward( $today, 2 );
63
    my $expected = $today->clone->add( days => 2 );
341
    my $expected = $today->clone->add( days => 2 );
64
    is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' );
342
    is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' );
65
- 

Return to bug 33727