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

(-)a/t/db_dependent/Calendar.t (-213 / +258 lines)
Lines 34-46 my $schema = Koha::Database->new->schema; Link Here
34
my $builder = t::lib::TestBuilder->new;
34
my $builder = t::lib::TestBuilder->new;
35
$schema->storage->txn_begin;
35
$schema->storage->txn_begin;
36
36
37
my $today = dt_from_string();
37
my $today      = dt_from_string();
38
my $holiday_dt = $today->clone;
38
my $holiday_dt = $today->clone;
39
$holiday_dt->add(days => 3);
39
$holiday_dt->add( days => 3 );
40
40
41
Koha::Caches->get_instance()->flush_all();
41
Koha::Caches->get_instance()->flush_all();
42
42
43
subtest 'Original tests from t' => sub {
43
subtest 'Original tests from t' => sub {
44
44
    # We need to mock the C4::Context->preference method for
45
    # We need to mock the C4::Context->preference method for
45
    # simplicity and re-usability of the session definition. Any
46
    # simplicity and re-usability of the session definition. Any
46
    # syspref fits for syspref-agnostic tests.
47
    # syspref fits for syspref-agnostic tests.
Lines 52-82 subtest 'Original tests from t' => sub { Link Here
52
        }
53
        }
53
    );
54
    );
54
55
55
    my $mpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
56
    my $mpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
56
    my $cpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
57
    my $cpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
57
    my $rows = [ # add weekly holidays
58
    my $rows = [    # add weekly holidays
58
        { branchcode => $mpl, weekday => 0 }, # sundays
59
        { branchcode => $mpl, weekday => 0 },                  # sundays
59
        { branchcode => $mpl, weekday => 6 }, # saturdays
60
        { branchcode => $mpl, weekday => 6 },                  # saturdays
60
        { branchcode => $mpl, day => 1, month => 1 },      # new year's day
61
        { branchcode => $mpl, day     => 1, month => 1 },      # new year's day
61
        { branchcode => $mpl, day => 25, month => 12 },    # chrismas
62
        { branchcode => $mpl, day     => 25, month => 12 },    # chrismas
62
    ];
63
    ];
63
    $schema->resultset('RepeatableHoliday')->delete_all;
64
    $schema->resultset('RepeatableHoliday')->delete_all;
64
    $schema->resultset('RepeatableHoliday')->create({ %$_, description => q{} }) for @$rows;
65
    $schema->resultset('RepeatableHoliday')->create( { %$_, description => q{} } ) for @$rows;
65
66
66
    $rows = [ # exception holidays
67
    $rows = [                                                  # exception holidays
67
        { branchcode => $mpl, day => 11, month => 11, year => 2012, isexception => 1 },    # sunday exception
68
        { 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 => 1,  month => 6,  year => 2011, isexception => 0 },
69
        { branchcode => $mpl, day => 4,  month => 7,  year => 2012, isexception => 0 },
70
        { branchcode => $mpl, day => 4,  month => 7,  year => 2012, isexception => 0 },
70
        { branchcode => $cpl, day => 6,  month => 8,  year => 2012, isexception => 0 },
71
        { 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 => 1 },    # holiday exception
72
        { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 0 }, # holiday
73
        { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 0 },    # holiday
73
    ];
74
    ];
74
    $schema->resultset('SpecialHoliday')->delete_all;
75
    $schema->resultset('SpecialHoliday')->delete_all;
75
    $schema->resultset('SpecialHoliday')->create({ %$_, description => q{} }) for @$rows;
76
    $schema->resultset('SpecialHoliday')->create( { %$_, description => q{} } ) for @$rows;
76
77
77
    my $cache = Koha::Caches->get_instance();
78
    my $cache = Koha::Caches->get_instance();
78
    $cache->clear_from_cache( $mpl.'_holidays' );
79
    $cache->clear_from_cache( $mpl . '_holidays' );
79
    $cache->clear_from_cache( $cpl.'_holidays' );
80
    $cache->clear_from_cache( $cpl . '_holidays' );
80
81
81
    # $mpl branch is arbitrary, is not used at all but is needed for initialization
82
    # $mpl branch is arbitrary, is not used at all but is needed for initialization
82
    my $cal = Koha::Calendar->new( branchcode => $mpl );
83
    my $cal = Koha::Calendar->new( branchcode => $mpl );
Lines 84-164 subtest 'Original tests from t' => sub { Link Here
84
    isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
85
    isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
85
86
86
    my $saturday = DateTime->new(
87
    my $saturday = DateTime->new(
87
        year      => 2012,
88
        year  => 2012,
88
        month     => 11,
89
        month => 11,
89
        day       => 24,
90
        day   => 24,
90
    );
91
    );
91
92
92
    my $sunday = DateTime->new(
93
    my $sunday = DateTime->new(
93
        year      => 2012,
94
        year  => 2012,
94
        month     => 11,
95
        month => 11,
95
        day       => 25,
96
        day   => 25,
96
    );
97
    );
97
98
98
    my $monday = DateTime->new(
99
    my $monday = DateTime->new(
99
        year      => 2012,
100
        year  => 2012,
100
        month     => 11,
101
        month => 11,
101
        day       => 26,
102
        day   => 26,
102
    );
103
    );
103
104
104
    my $new_year = DateTime->new(
105
    my $new_year = DateTime->new(
105
        year        => 2013,
106
        year  => 2013,
106
        month       => 1,
107
        month => 1,
107
        day         => 1,
108
        day   => 1,
108
    );
109
    );
109
110
110
    my $single_holiday = DateTime->new(
111
    my $single_holiday = DateTime->new(
111
        year      => 2011,
112
        year  => 2011,
112
        month     => 6,
113
        month => 6,
113
        day       => 1,
114
        day   => 1,
114
    );    # should be a holiday
115
    );    # should be a holiday
115
116
116
    my $notspecial = DateTime->new(
117
    my $notspecial = DateTime->new(
117
        year      => 2011,
118
        year  => 2011,
118
        month     => 6,
119
        month => 6,
119
        day       => 2
120
        day   => 2
120
    );    # should NOT be a holiday
121
    );    # should NOT be a holiday
121
122
122
    my $sunday_exception = DateTime->new(
123
    my $sunday_exception = DateTime->new(
123
        year      => 2012,
124
        year  => 2012,
124
        month     => 11,
125
        month => 11,
125
        day       => 11
126
        day   => 11
126
    );
127
    );
127
128
128
    my $day_after_christmas = DateTime->new(
129
    my $day_after_christmas = DateTime->new(
129
        year    => 2012,
130
        year  => 2012,
130
        month   => 12,
131
        month => 12,
131
        day     => 26
132
        day   => 26
132
    );  # for testing negative addDuration
133
    );    # for testing negative addDuration
133
134
134
    my $holiday_for_another_branch = DateTime->new(
135
    my $holiday_for_another_branch = DateTime->new(
135
        year => 2012,
136
        year  => 2012,
136
        month => 8,
137
        month => 8,
137
        day => 6, # This is a monday
138
        day   => 6,      # This is a monday
138
    );
139
    );
139
140
140
    my $holiday_excepted = DateTime->new(
141
    my $holiday_excepted = DateTime->new(
141
        year => 2012,
142
        year  => 2012,
142
        month => 7,
143
        month => 7,
143
        day => 7, # Both a holiday and exception
144
        day   => 7,      # Both a holiday and exception
144
    );
145
    );
145
146
146
    {   # Syspref-agnostic tests
147
    {                    # Syspref-agnostic tests
147
        is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
148
        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( $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( $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($saturday),         1, 'Saturday is a closed day' );
151
        is ( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' );
152
        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($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($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($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($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($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(
158
        is ( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' );
159
            $cal->is_holiday($holiday_for_another_branch), 0,
160
            'Holiday defined for another branch should not be defined as an holiday'
161
        );
162
        is( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' );
159
    }
163
    }
160
164
161
    {   # Bugzilla #8966 - is_holiday truncates referenced date
165
    {    # Bugzilla #8966 - is_holiday truncates referenced date
162
        my $later_dt = DateTime->new(    # Monday
166
        my $later_dt = DateTime->new(    # Monday
163
            year      => 2012,
167
            year      => 2012,
164
            month     => 9,
168
            month     => 9,
Lines 168-326 subtest 'Original tests from t' => sub { Link Here
168
            time_zone => 'Europe/London',
172
            time_zone => 'Europe/London',
169
        );
173
        );
170
174
171
172
        is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' );
175
        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' );
176
        cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
174
    }
177
    }
175
178
176
    {   # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
179
    {    # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
177
        my $single_holiday_time = DateTime->new(
180
        my $single_holiday_time = DateTime->new(
178
            year  => 2011,
181
            year   => 2011,
179
            month => 6,
182
            month  => 6,
180
            day   => 1,
183
            day    => 1,
181
            hour  => 11,
184
            hour   => 11,
182
            minute  => 2
185
            minute => 2
183
        );
186
        );
184
187
185
        is( $cal->is_holiday($single_holiday_time),
188
        is(
186
            $cal->is_holiday($single_holiday) ,
189
            $cal->is_holiday($single_holiday_time),
187
            'bz-8800 is_holiday should truncate the date for holiday validation' );
190
            $cal->is_holiday($single_holiday),
191
            'bz-8800 is_holiday should truncate the date for holiday validation'
192
        );
188
    }
193
    }
189
194
190
        my $one_day_dur = DateTime::Duration->new( days => 1 );
195
    my $one_day_dur   = DateTime::Duration->new( days => 1 );
191
        my $two_day_dur = DateTime::Duration->new( days => 2 );
196
    my $two_day_dur   = DateTime::Duration->new( days => 2 );
192
        my $seven_day_dur = DateTime::Duration->new( days => 7 );
197
    my $seven_day_dur = DateTime::Duration->new( days => 7 );
193
198
194
        my $dt = dt_from_string( '2012-07-03','iso' ); #tuesday
199
    my $dt = dt_from_string( '2012-07-03', 'iso' );    #tuesday
195
200
196
        my $test_dt = DateTime->new(    # Monday
201
    my $test_dt = DateTime->new(                       # Monday
197
            year      => 2012,
202
        year   => 2012,
198
            month     => 7,
203
        month  => 7,
199
            day       => 23,
204
        day    => 23,
200
            hour      => 11,
205
        hour   => 11,
201
            minute    => 53,
206
        minute => 53,
202
        );
207
    );
203
208
204
        my $later_dt = DateTime->new(    # Monday
209
    my $later_dt = DateTime->new(                      # Monday
205
            year      => 2012,
210
        year      => 2012,
206
            month     => 9,
211
        month     => 9,
207
            day       => 17,
212
        day       => 17,
208
            hour      => 17,
213
        hour      => 17,
209
            minute    => 30,
214
        minute    => 30,
210
            time_zone => 'Europe/London',
215
        time_zone => 'Europe/London',
211
        );
216
    );
212
217
213
    {    ## 'Datedue' tests
218
    {                                                  ## 'Datedue' tests
214
219
215
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Datedue' );
220
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Datedue' );
216
221
217
        is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
222
        is(
218
            dt_from_string('2012-07-05','iso'),
223
            $cal->addDuration( $dt, $one_day_dur, 'days' ),    # tuesday
219
            'Single day add (Datedue, matches holiday, shift)' );
224
            dt_from_string( '2012-07-05', 'iso' ),
225
            'Single day add (Datedue, matches holiday, shift)'
226
        );
220
227
221
        is($cal->addDuration( $dt, $two_day_dur, 'days' ),
228
        is(
222
            dt_from_string('2012-07-05','iso'),
229
            $cal->addDuration( $dt, $two_day_dur, 'days' ),
223
            'Two days add, skips holiday (Datedue)' );
230
            dt_from_string( '2012-07-05', 'iso' ),
231
            'Two days add, skips holiday (Datedue)'
232
        );
224
233
225
        cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
234
        cmp_ok(
235
            $cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
226
            '2012-07-30T11:53:00',
236
            '2012-07-30T11:53:00',
227
            'Add 7 days (Datedue)' );
237
            'Add 7 days (Datedue)'
238
        );
228
239
229
        is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
240
        is(
230
            'addDuration skips closed Sunday (Datedue)' );
241
            $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
242
            'addDuration skips closed Sunday (Datedue)'
243
        );
231
244
232
        is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
245
        is(
233
            'Negative call to addDuration (Datedue)' );
246
            $cal->addDuration( $day_after_christmas, -1, 'days' )->ymd(), '2012-12-24',
247
            'Negative call to addDuration (Datedue)'
248
        );
234
249
235
        ## Note that the days_between API says closed days are not considered.
250
        ## Note that the days_between API says closed days are not considered.
236
        ## This tests are here as an API test.
251
        ## This tests are here as an API test.
237
        cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
252
        cmp_ok(
238
                    '==', 40, 'days_between calculates correctly (Days)' );
253
            $cal->days_between( $test_dt, $later_dt )->in_units('days'),
254
            '==', 40, 'days_between calculates correctly (Days)'
255
        );
239
256
240
        cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
257
        cmp_ok(
241
                    '==', 40, 'Test parameter order not relevant (Days)' );
258
            $cal->days_between( $later_dt, $test_dt )->in_units('days'),
259
            '==', 40, 'Test parameter order not relevant (Days)'
260
        );
242
    }
261
    }
243
262
244
    {   ## 'Calendar' tests'
263
    {    ## 'Calendar' tests'
245
264
246
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Calendar' );
265
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Calendar' );
247
266
248
        $dt = dt_from_string('2012-07-03','iso');
267
        $dt = dt_from_string( '2012-07-03', 'iso' );
249
268
250
        is($cal->addDuration( $dt, $one_day_dur, 'days' ),
269
        is(
251
            dt_from_string('2012-07-05','iso'),
270
            $cal->addDuration( $dt, $one_day_dur, 'days' ),
252
            'Single day add (Calendar)' );
271
            dt_from_string( '2012-07-05', 'iso' ),
272
            'Single day add (Calendar)'
273
        );
253
274
254
        cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
275
        cmp_ok(
255
           '2012-08-01T11:53:00',
276
            $cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
256
           'Add 7 days (Calendar)' );
277
            '2012-08-01T11:53:00',
278
            'Add 7 days (Calendar)'
279
        );
257
280
258
        is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
281
        is(
259
                'addDuration skips closed Sunday (Calendar)' );
282
            $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
283
            'addDuration skips closed Sunday (Calendar)'
284
        );
260
285
261
        is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
286
        is(
262
                'Negative call to addDuration (Calendar)' );
287
            $cal->addDuration( $day_after_christmas, -1, 'days' )->ymd(), '2012-12-24',
288
            'Negative call to addDuration (Calendar)'
289
        );
263
290
264
        cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
291
        cmp_ok(
265
                    '==', 40, 'days_between calculates correctly (Calendar)' );
292
            $cal->days_between( $test_dt, $later_dt )->in_units('days'),
293
            '==', 40, 'days_between calculates correctly (Calendar)'
294
        );
266
295
267
        cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
296
        cmp_ok(
268
                    '==', 40, 'Test parameter order not relevant (Calendar)' );
297
            $cal->days_between( $later_dt, $test_dt )->in_units('days'),
298
            '==', 40, 'Test parameter order not relevant (Calendar)'
299
        );
269
    }
300
    }
270
301
271
302
    {    ## 'Days' tests
272
    {   ## 'Days' tests
273
303
274
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Days' );
304
        $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Days' );
275
305
276
        $dt = dt_from_string('2012-07-03','iso');
306
        $dt = dt_from_string( '2012-07-03', 'iso' );
277
307
278
        is($cal->addDuration( $dt, $one_day_dur, 'days' ),
308
        is(
279
            dt_from_string('2012-07-04','iso'),
309
            $cal->addDuration( $dt, $one_day_dur, 'days' ),
280
            'Single day add (Days)' );
310
            dt_from_string( '2012-07-04', 'iso' ),
311
            'Single day add (Days)'
312
        );
281
313
282
        cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ),'eq',
314
        cmp_ok(
315
            $cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
283
            '2012-07-30T11:53:00',
316
            '2012-07-30T11:53:00',
284
            'Add 7 days (Days)' );
317
            'Add 7 days (Days)'
318
        );
285
319
286
        is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
320
        is(
287
            'addDuration doesn\'t skip closed Sunday (Days)' );
321
            $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
322
            'addDuration doesn\'t skip closed Sunday (Days)'
323
        );
288
324
289
        is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
325
        is(
290
            'Negative call to addDuration (Days)' );
326
            $cal->addDuration( $day_after_christmas, -1, 'days' )->ymd(), '2012-12-25',
327
            'Negative call to addDuration (Days)'
328
        );
291
329
292
        ## Note that the days_between API says closed days are not considered.
330
        ## Note that the days_between API says closed days are not considered.
293
        ## This tests are here as an API test.
331
        ## This tests are here as an API test.
294
        cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
332
        cmp_ok(
295
                    '==', 40, 'days_between calculates correctly (Days)' );
333
            $cal->days_between( $test_dt, $later_dt )->in_units('days'),
334
            '==', 40, 'days_between calculates correctly (Days)'
335
        );
296
336
297
        cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
337
        cmp_ok(
298
                    '==', 40, 'Test parameter order not relevant (Days)' );
338
            $cal->days_between( $later_dt, $test_dt )->in_units('days'),
339
            '==', 40, 'Test parameter order not relevant (Days)'
340
        );
299
341
300
    }
342
    }
301
343
302
    {
344
    {
303
        $cal = Koha::Calendar->new( branchcode => $cpl );
345
        $cal = Koha::Calendar->new( branchcode => $cpl );
304
        is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
346
        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' );
347
        is(
348
            $cal->is_holiday($holiday_for_another_branch), 1,
349
            'Holiday defined for CPL should be defined as an holiday'
350
        );
306
    }
351
    }
307
352
308
    subtest 'days_mode parameter' => sub {
353
    subtest 'days_mode parameter' => sub {
309
        plan tests => 1;
354
        plan tests => 1;
310
355
311
        t::lib::Mocks::mock_preference('useDaysMode', 'Days');
356
        t::lib::Mocks::mock_preference( 'useDaysMode', 'Days' );
312
357
313
        $cal = Koha::Calendar->new( branchcode => $cpl, days_mode => 'Calendar' );
358
        $cal = Koha::Calendar->new( branchcode => $cpl, days_mode => 'Calendar' );
314
        is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|);
359
        is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set| );
315
    };
360
    };
316
361
317
    $cache->clear_from_cache( $mpl.'_holidays' );
362
    $cache->clear_from_cache( $mpl . '_holidays' );
318
    $cache->clear_from_cache( $cpl.'_holidays' );
363
    $cache->clear_from_cache( $cpl . '_holidays' );
319
};
364
};
320
365
321
my $library = $builder->build_object({ class => 'Koha::Libraries' });
366
my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
322
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Calendar' );
367
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Calendar' );
323
my $holiday = $builder->build(
368
my $holiday  = $builder->build(
324
    {
369
    {
325
        source => 'SpecialHoliday',
370
        source => 'SpecialHoliday',
326
        value  => {
371
        value  => {
Lines 338-349 subtest 'days_forward' => sub { Link Here
338
    plan tests => 4;
383
    plan tests => 4;
339
384
340
    my $forwarded_dt = $calendar->days_forward( $today, 2 );
385
    my $forwarded_dt = $calendar->days_forward( $today, 2 );
341
    my $expected = $today->clone->add( days => 2 );
386
    my $expected     = $today->clone->add( days => 2 );
342
    is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' );
387
    is( $forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 2 days' );
343
388
344
    $forwarded_dt = $calendar->days_forward( $today, 5 );
389
    $forwarded_dt = $calendar->days_forward( $today, 5 );
345
    $expected = $today->clone->add( days => 6 );
390
    $expected     = $today->clone->add( days => 6 );
346
    is( $forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 5 days + 1 day for holiday'
391
    is(
392
        $forwarded_dt->ymd, $expected->ymd,
393
        'With holiday on the perioddays_forward should add 5 days + 1 day for holiday'
347
    );
394
    );
348
395
349
    $forwarded_dt = $calendar->days_forward( $today, 0 );
396
    $forwarded_dt = $calendar->days_forward( $today, 0 );
Lines 357-365 subtest 'crossing_DST' => sub { Link Here
357
404
358
    plan tests => 3;
405
    plan tests => 3;
359
406
360
    my $tz = DateTime::TimeZone->new( name => 'America/New_York' );
407
    my $tz           = DateTime::TimeZone->new( name => 'America/New_York' );
361
    my $start_date = dt_from_string( "2016-03-09 02:29:00", undef, $tz );
408
    my $start_date   = dt_from_string( "2016-03-09 02:29:00", undef, $tz );
362
    my $end_date   = dt_from_string( "2017-01-01 00:00:00", undef, $tz );
409
    my $end_date     = dt_from_string( "2017-01-01 00:00:00", undef, $tz );
363
    my $days_between = $calendar->days_between( $start_date, $end_date );
410
    my $days_between = $calendar->days_between( $start_date, $end_date );
364
    is( $days_between->delta_days, 298, "Days calculated correctly" );
411
    is( $days_between->delta_days, 298, "Days calculated correctly" );
365
    $days_between = $calendar->days_between( $end_date, $start_date );
412
    $days_between = $calendar->days_between( $end_date, $start_date );
Lines 384-402 subtest 'hours_between | days_between' => sub { Link Here
384
    # 17 18 19 20 21 22 23
431
    # 17 18 19 20 21 22 23
385
    # 24 25 26 27 28 29 30
432
    # 24 25 26 27 28 29 30
386
433
387
    my $now    = dt_from_string('2019-11-05 12:34:56'); # Today is 2019 Nov 5th
434
    my $now    = dt_from_string('2019-11-05 12:34:56');    # Today is 2019 Nov 5th
388
    my $nov_6  = dt_from_string('2019-11-06 12:34:56');
435
    my $nov_6  = dt_from_string('2019-11-06 12:34:56');
389
    my $nov_7  = dt_from_string('2019-11-07 12:34:56');
436
    my $nov_7  = dt_from_string('2019-11-07 12:34:56');
390
    my $nov_12 = dt_from_string('2019-11-12 12:34:56');
437
    my $nov_12 = dt_from_string('2019-11-12 12:34:56');
391
    my $nov_13 = dt_from_string('2019-11-13 12:34:56');
438
    my $nov_13 = dt_from_string('2019-11-13 12:34:56');
392
    my $nov_15 = dt_from_string('2019-11-15 12:34:56');
439
    my $nov_15 = dt_from_string('2019-11-15 12:34:56');
393
    Time::Fake->offset($now->epoch);
440
    Time::Fake->offset( $now->epoch );
394
441
395
    subtest 'No holiday' => sub {
442
    subtest 'No holiday' => sub {
396
443
397
        plan tests => 2;
444
        plan tests => 2;
398
445
399
        my $library = $builder->build_object({ class => 'Koha::Libraries' });
446
        my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
400
        my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
447
        my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
401
448
402
        subtest 'Same hours' => sub {
449
        subtest 'Same hours' => sub {
Lines 433-465 subtest 'hours_between | days_between' => sub { Link Here
433
            plan tests => 10;
480
            plan tests => 10;
434
481
435
            # Between 5th and 5th (Same day short hours loan)
482
            # Between 5th and 5th (Same day short hours loan)
436
            my $diff_hours = $calendar->hours_between( $now, $now->clone->add(hours => 3) )->hours;
483
            my $diff_hours = $calendar->hours_between( $now, $now->clone->add( hours => 3 ) )->hours;
437
            is( $diff_hours, 3, 'hours: 3 hours, no holidays' );
484
            is( $diff_hours, 3, 'hours: 3 hours, no holidays' );
438
            my $diff_days = $calendar->days_between( $now, $now->clone->add(hours => 3) )->delta_days;
485
            my $diff_days = $calendar->days_between( $now, $now->clone->add( hours => 3 ) )->delta_days;
439
            is( $diff_days, 0, 'days: 3 hours, no holidays' );
486
            is( $diff_days, 0, 'days: 3 hours, no holidays' );
440
487
441
            # Between 5th and 6th
488
            # Between 5th and 6th
442
            $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours;
489
            $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract( hours => 3 ) )->hours;
443
            is( $diff_hours, 1 * 24 - 3, 'hours: 21 hours, no holidays' );
490
            is( $diff_hours, 1 * 24 - 3, 'hours: 21 hours, no holidays' );
444
            $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days;
491
            $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract( hours => 3 ) )->delta_days;
445
            is( $diff_days, 1, 'days: 21 hours, no holidays' );
492
            is( $diff_days, 1, 'days: 21 hours, no holidays' );
446
493
447
            # Between 5th and 7th
494
            # Between 5th and 7th
448
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours;
495
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract( hours => 3 ) )->hours;
449
            is( $diff_hours, 2 * 24 - 3, 'hours: 45 hours, no holidays' );
496
            is( $diff_hours, 2 * 24 - 3, 'hours: 45 hours, no holidays' );
450
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days;
497
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract( hours => 3 ) )->delta_days;
451
            is( $diff_days, 2, 'days: 45 hours, no holidays' );
498
            is( $diff_days, 2, 'days: 45 hours, no holidays' );
452
499
453
            # Between 5th and 12th
500
            # Between 5th and 12th
454
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours;
501
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract( hours => 3 ) )->hours;
455
            is( $diff_hours, 7 * 24 - 3, 'hours: 165 hours, no holidays' );
502
            is( $diff_hours, 7 * 24 - 3, 'hours: 165 hours, no holidays' );
456
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days;
503
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract( hours => 3 ) )->delta_days;
457
            is( $diff_days, 7, 'days: 165 hours, no holidays' );
504
            is( $diff_days, 7, 'days: 165 hours, no holidays' );
458
505
459
            # Between 5th and 15th
506
            # Between 5th and 15th
460
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours;
507
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract( hours => 3 ) )->hours;
461
            is( $diff_hours, 10 * 24 - 3, 'hours: 237 hours, no holidays' );
508
            is( $diff_hours, 10 * 24 - 3, 'hours: 237 hours, no holidays' );
462
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days;
509
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract( hours => 3 ) )->delta_days;
463
            is( $diff_days, 10, 'days: 237 hours, no holidays' );
510
            is( $diff_days, 10, 'days: 237 hours, no holidays' );
464
        };
511
        };
465
    };
512
    };
Lines 467-480 subtest 'hours_between | days_between' => sub { Link Here
467
    subtest 'With holiday' => sub {
514
    subtest 'With holiday' => sub {
468
        plan tests => 2;
515
        plan tests => 2;
469
516
470
        my $library = $builder->build_object({ class => 'Koha::Libraries' });
517
        my $library = $builder->build_object( { class => 'Koha::Libraries' } );
471
518
472
        # Wednesdays are closed
519
        # Wednesdays are closed
473
        my $dbh = C4::Context->dbh;
520
        my $dbh = C4::Context->dbh;
474
        $dbh->do(q|
521
        $dbh->do(
522
            q|
475
            INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
523
            INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
476
            VALUES ( ?, ?, NULL, NULL, ?, '' )
524
            VALUES ( ?, ?, NULL, NULL, ?, '' )
477
        |, undef, $library->branchcode, 3, 'Closed on Wednesday');
525
        |, undef, $library->branchcode, 3, 'Closed on Wednesday'
526
        );
478
527
479
        my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
528
        my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
480
529
Lines 485-499 subtest 'hours_between | days_between' => sub { Link Here
485
534
486
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
535
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
487
            $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours;
536
            $diff_hours = $calendar->hours_between( $now, $nov_6 )->hours;
488
            is( $diff_hours, 0 * 24, 'hours: 1 day, end_dt = holiday' ); # FIXME Is this really should be 0?
537
            is( $diff_hours, 0 * 24, 'hours: 1 day, end_dt = holiday' );    # FIXME Is this really should be 0?
489
            $diff_days = $calendar->days_between( $now, $nov_6)->delta_days;
538
            $diff_days = $calendar->days_between( $now, $nov_6 )->delta_days;
490
            is( $diff_days, 0, 'days: 1 day, end_dt = holiday' ); # FIXME Is this really should be 0?
539
            is( $diff_days, 0, 'days: 1 day, end_dt = holiday' );           # FIXME Is this really should be 0?
491
540
492
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
541
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
493
            $diff_hours = $calendar->hours_between( $nov_6, $nov_7 )->hours;
542
            $diff_hours = $calendar->hours_between( $nov_6, $nov_7 )->hours;
494
            is( $diff_hours, 0 * 24, 'hours: 1 day, start_dt = holiday' ); # FIXME Is this really should be 0?
543
            is( $diff_hours, 0 * 24, 'hours: 1 day, start_dt = holiday' );    # FIXME Is this really should be 0?
495
            $diff_days = $calendar->days_between( $nov_6, $nov_7 )->delta_days;
544
            $diff_days = $calendar->days_between( $nov_6, $nov_7 )->delta_days;
496
            is( $diff_days, 0, 'days: 1 day, start_dt = holiday' ); # FIXME Is this really should be 0?
545
            is( $diff_days, 0, 'days: 1 day, start_dt = holiday' );           # FIXME Is this really should be 0?
497
546
498
            # Between 5th and 7th
547
            # Between 5th and 7th
499
            $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
548
            $diff_hours = $calendar->hours_between( $now, $nov_7 )->hours;
Lines 504-522 subtest 'hours_between | days_between' => sub { Link Here
504
            # Between 5th and 12th
553
            # Between 5th and 12th
505
            $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
554
            $diff_hours = $calendar->hours_between( $now, $nov_12 )->hours;
506
            is( $diff_hours, 7 * 24 - 1 * 24, 'hours: 7 days, 1 holiday' );
555
            is( $diff_hours, 7 * 24 - 1 * 24, 'hours: 7 days, 1 holiday' );
507
            $diff_days = $calendar->days_between( $now, $nov_12)->delta_days;
556
            $diff_days = $calendar->days_between( $now, $nov_12 )->delta_days;
508
            is( $diff_days, 7 - 1, 'day: 7 days, 1 holiday' );
557
            is( $diff_days, 7 - 1, 'day: 7 days, 1 holiday' );
509
558
510
            # Between 5th and 13th
559
            # Between 5th and 13th
511
            $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours;
560
            $diff_hours = $calendar->hours_between( $now, $nov_13 )->hours;
512
            is( $diff_hours, 8 * 24 - 2 * 24, 'hours: 8 days, 2 holidays' );
561
            is( $diff_hours, 8 * 24 - 2 * 24, 'hours: 8 days, 2 holidays' );
513
            $diff_days = $calendar->days_between( $now, $nov_13)->delta_days;
562
            $diff_days = $calendar->days_between( $now, $nov_13 )->delta_days;
514
            is( $diff_days, 8 - 2, 'days: 8 days, 2 holidays' );
563
            is( $diff_days, 8 - 2, 'days: 8 days, 2 holidays' );
515
564
516
            # Between 5th and 15th
565
            # Between 5th and 15th
517
            $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
566
            $diff_hours = $calendar->hours_between( $now, $nov_15 )->hours;
518
            is( $diff_hours, 10 * 24 - 2 * 24, 'hours: 10 days, 2 holidays' );
567
            is( $diff_hours, 10 * 24 - 2 * 24, 'hours: 10 days, 2 holidays' );
519
            $diff_days = $calendar->days_between( $now, $nov_15)->delta_days;
568
            $diff_days = $calendar->days_between( $now, $nov_15 )->delta_days;
520
            is( $diff_days, 10 - 2, 'days: 10 days, 2 holidays' );
569
            is( $diff_days, 10 - 2, 'days: 10 days, 2 holidays' );
521
        };
570
        };
522
571
Lines 529-569 subtest 'hours_between | days_between' => sub { Link Here
529
            # No test - Tested above as 5th is an open day
578
            # No test - Tested above as 5th is an open day
530
579
531
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
580
            # Between 5th and 6th (This case should never happen in real code, one cannot return on a closed day)
532
            my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) );
581
            my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract( hours => 3 ) );
533
            is( $duration->hours, abs(0 * 24 - 3), 'hours: 21 hours, end_dt = holiday' ); # FIXME $duration->hours always return a abs
582
            is( $duration->hours, abs( 0 * 24 - 3 ), 'hours: 21 hours, end_dt = holiday' )
534
            is( $duration->is_negative, 1, '? is negative ?' ); # FIXME Do really test for that case in our calls to hours_between?
583
                ;    # FIXME $duration->hours always return a abs
535
            $duration = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) );
584
            is( $duration->is_negative, 1, '? is negative ?' )
536
            is( $duration->hours, abs(0), 'days: 21 hours, end_dt = holiday' ); # FIXME Is this correct?
585
                ;    # FIXME Do really test for that case in our calls to hours_between?
586
            $duration = $calendar->days_between( $now, $nov_6->clone->subtract( hours => 3 ) );
587
            is( $duration->hours, abs(0), 'days: 21 hours, end_dt = holiday' );    # FIXME Is this correct?
537
588
538
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
589
            # Between 6th and 7th (This case should never happen in real code, one cannot issue on a closed day)
539
            $duration = $calendar->hours_between( $nov_6, $nov_7->clone->subtract(hours => 3) );
590
            $duration = $calendar->hours_between( $nov_6, $nov_7->clone->subtract( hours => 3 ) );
540
            is( $duration->hours, abs(0 * 24 - 3), 'hours: 21 hours, start_dt = holiday' ); # FIXME $duration->hours always return a abs
591
            is( $duration->hours, abs( 0 * 24 - 3 ), 'hours: 21 hours, start_dt = holiday' )
541
            is( $duration->is_negative, 1, '? is negative ?' ); # FIXME Do really test for that case in our calls to hours_between?
592
                ;    # FIXME $duration->hours always return a abs
542
            $duration = $calendar->days_between( $nov_6, $nov_7->clone->subtract(hours => 3) );
593
            is( $duration->is_negative, 1, '? is negative ?' )
543
            is( $duration->hours, abs(0), 'days: 21 hours, start_dt = holiday' ); # FIXME Is this correct?
594
                ;    # FIXME Do really test for that case in our calls to hours_between?
595
            $duration = $calendar->days_between( $nov_6, $nov_7->clone->subtract( hours => 3 ) );
596
            is( $duration->hours, abs(0), 'days: 21 hours, start_dt = holiday' );    # FIXME Is this correct?
544
597
545
            # Between 5th and 7th
598
            # Between 5th and 7th
546
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract(hours => 3) )->hours;
599
            $diff_hours = $calendar->hours_between( $now, $nov_7->clone->subtract( hours => 3 ) )->hours;
547
            is( $diff_hours, 2 * 24 - 1 * 24 - 3, 'hours: 45 hours, 1 holiday' );
600
            is( $diff_hours, 2 * 24 - 1 * 24 - 3, 'hours: 45 hours, 1 holiday' );
548
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract(hours => 3) )->delta_days;
601
            $diff_days = $calendar->days_between( $now, $nov_7->clone->subtract( hours => 3 ) )->delta_days;
549
            is( $diff_days, 2 - 1, 'days: 45 hours, 1 holiday' );
602
            is( $diff_days, 2 - 1, 'days: 45 hours, 1 holiday' );
550
603
551
            # Between 5th and 12th
604
            # Between 5th and 12th
552
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract(hours => 3) )->hours;
605
            $diff_hours = $calendar->hours_between( $now, $nov_12->clone->subtract( hours => 3 ) )->hours;
553
            is( $diff_hours, 7 * 24 - 1 * 24 - 3, 'hours: 165 hours, 1 holiday' );
606
            is( $diff_hours, 7 * 24 - 1 * 24 - 3, 'hours: 165 hours, 1 holiday' );
554
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract(hours => 3) )->delta_days;
607
            $diff_days = $calendar->days_between( $now, $nov_12->clone->subtract( hours => 3 ) )->delta_days;
555
            is( $diff_days, 7 - 1, 'days: 165 hours, 1 holiday' );
608
            is( $diff_days, 7 - 1, 'days: 165 hours, 1 holiday' );
556
609
557
            # Between 5th and 13th
610
            # Between 5th and 13th
558
            $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract(hours => 3) )->hours;
611
            $diff_hours = $calendar->hours_between( $now, $nov_13->clone->subtract( hours => 3 ) )->hours;
559
            is( $diff_hours, 8 * 24 - 2 * 24 - 3, 'hours: 289 hours, 2 holidays ' );
612
            is( $diff_hours, 8 * 24 - 2 * 24 - 3, 'hours: 289 hours, 2 holidays ' );
560
            $diff_days = $calendar->days_between( $now, $nov_13->clone->subtract(hours => 3) )->delta_days;
613
            $diff_days = $calendar->days_between( $now, $nov_13->clone->subtract( hours => 3 ) )->delta_days;
561
            is( $diff_days, 8 - 1, 'days: 289 hours, 2 holidays' );
614
            is( $diff_days, 8 - 1, 'days: 289 hours, 2 holidays' );
562
615
563
            # Between 5th and 15th
616
            # Between 5th and 15th
564
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract(hours => 3) )->hours;
617
            $diff_hours = $calendar->hours_between( $now, $nov_15->clone->subtract( hours => 3 ) )->hours;
565
            is( $diff_hours, 10 * 24 - 2 * 24 - 3, 'hours: 237 hours, 2 holidays' );
618
            is( $diff_hours, 10 * 24 - 2 * 24 - 3, 'hours: 237 hours, 2 holidays' );
566
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract(hours => 3) )->delta_days;
619
            $diff_days = $calendar->days_between( $now, $nov_15->clone->subtract( hours => 3 ) )->delta_days;
567
            is( $diff_days, 10 - 2, 'days: 237 hours, 2 holidays' );
620
            is( $diff_days, 10 - 2, 'days: 237 hours, 2 holidays' );
568
        };
621
        };
569
622
Lines 594-613 subtest 'is_holiday' => sub { Link Here
594
        );
647
        );
595
648
596
        # Iterate 7 days
649
        # Iterate 7 days
597
        my $sth = $dbh->prepare(
650
        my $sth = $dbh->prepare("UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'");
598
"UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'"
599
        );
600
        for my $i ( 0 .. 6 ) {
651
        for my $i ( 0 .. 6 ) {
601
            my $calendar =
652
            my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
602
              Koha::Calendar->new( branchcode => $library->branchcode );
603
653
604
            is( $calendar->is_holiday($day), 1, $day->day_name() ." works as a repeatable holiday");
654
            is( $calendar->is_holiday($day), 1, $day->day_name() . " works as a repeatable holiday" );
605
655
606
            # Increment the date and holiday day
656
            # Increment the date and holiday day
607
            $day->add( days => 1 );
657
            $day->add( days => 1 );
608
            $dow++;
658
            $dow++;
609
            $dow = 0 if $dow == 7;
659
            $dow = 0 if $dow == 7;
610
            $sth->execute($dow, $library->branchcode);
660
            $sth->execute( $dow, $library->branchcode );
611
        }
661
        }
612
    };
662
    };
613
};
663
};
Lines 615-621 subtest 'is_holiday' => sub { Link Here
615
subtest 'get_push_amt' => sub {
665
subtest 'get_push_amt' => sub {
616
    plan tests => 1;
666
    plan tests => 1;
617
667
618
    t::lib::Mocks::mock_preference('useDaysMode', 'Dayweek');
668
    t::lib::Mocks::mock_preference( 'useDaysMode', 'Dayweek' );
619
669
620
    subtest 'weekday holidays' => sub {
670
    subtest 'weekday holidays' => sub {
621
        plan tests => 7;
671
        plan tests => 7;
Lines 636-647 subtest 'get_push_amt' => sub { Link Here
636
        );
686
        );
637
687
638
        # Iterate 7 days
688
        # Iterate 7 days
639
        my $sth = $dbh->prepare(
689
        my $sth = $dbh->prepare("UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'");
640
"UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'"
641
        );
642
        for my $i ( 0 .. 6 ) {
690
        for my $i ( 0 .. 6 ) {
643
            my $calendar =
691
            my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Dayweek' );
644
              Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Dayweek' );
645
692
646
            my $npa;
693
            my $npa;
647
            eval {
694
            eval {
Lines 651-662 subtest 'get_push_amt' => sub { Link Here
651
                alarm 0;
698
                alarm 0;
652
            };
699
            };
653
            if ($@) {
700
            if ($@) {
654
                die unless $@ eq "alarm\n";    # propagate unexpected errors
701
                die unless $@ eq "alarm\n";                  # propagate unexpected errors
655
                # timed out
702
                                                             # timed out
656
                ok(0, "next_push_amt succeeded for ".$day->day_name()." weekday holiday");
703
                ok( 0, "next_push_amt succeeded for " . $day->day_name() . " weekday holiday" );
657
            }
704
            } else {
658
            else {
705
                ok( $npa, "next_push_amt succeeded for " . $day->day_name() . " weekday holiday" );
659
                ok($npa, "next_push_amt succeeded for ".$day->day_name()." weekday holiday");
660
            }
706
            }
661
707
662
            # Increment the date and holiday day
708
            # Increment the date and holiday day
663
- 

Return to bug 33727