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

(-)a/t/Calendar.t (-51 / +38 lines)
Lines 17-50 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More;
20
use Test::More tests => 38;
21
use Test::MockModule;
21
use Test::MockModule;
22
22
23
use DateTime;
23
use DateTime;
24
use DateTime::Duration;
24
use DateTime::Duration;
25
use Koha::Caches;
25
use Koha::Caches;
26
use Koha::Calendar;
27
use Koha::Database;
26
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
27
29
28
use t::lib::Mocks;
30
use t::lib::Mocks;
31
use t::lib::TestBuilder;
29
32
30
use Module::Load::Conditional qw/check_install/;
33
my $builder = t::lib::TestBuilder->new;
31
34
my $schema = Koha::Database->new->schema;
32
BEGIN {
35
$schema->storage->txn_begin;
33
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
34
        plan tests => 40;
35
    } else {
36
        plan skip_all => "Need Test::DBIx::Class"
37
    }
38
}
39
40
use_ok('Koha::Calendar');
41
42
use Test::DBIx::Class;
43
44
my $db = Test::MockModule->new('Koha::Database');
45
$db->mock(
46
    _new_schema => sub { return Schema(); }
47
);
48
36
49
# We need to mock the C4::Context->preference method for
37
# We need to mock the C4::Context->preference method for
50
# simplicity and re-usability of the session definition. Any
38
# simplicity and re-usability of the session definition. Any
Lines 57-89 $module_context->mock( Link Here
57
    }
45
    }
58
);
46
);
59
47
60
fixtures_ok [
48
my $mpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
61
    # weekly holidays
49
my $cpl = $builder->build_object({ class => 'Koha::Libraries' })->branchcode;
62
    RepeatableHoliday => [
50
my $rows = [ # add weekly holidays
63
        [ qw( branchcode day month weekday title description) ],
51
    { branchcode => $mpl, weekday => 0 }, # sundays
64
        [ 'MPL', undef, undef, 0, '', '' ], # sundays
52
    { branchcode => $mpl, weekday => 6 }, # saturdays
65
        [ 'MPL', undef, undef, 6, '', '' ],# saturdays
53
    { branchcode => $mpl, day => 1, month => 1 },      # new year's day
66
        [ 'MPL', 1, 1, undef, '', ''], # new year's day
54
    { branchcode => $mpl, day => 25, month => 12 },    # chrismas
67
        [ 'MPL', 25, 12, undef, '', ''], # chrismas
55
];
68
    ],
56
$schema->resultset('RepeatableHoliday')->delete_all;
69
    # exception holidays
57
$schema->resultset('RepeatableHoliday')->create({ %$_, description => q{} }) for @$rows;
70
    SpecialHoliday => [
58
71
        [qw( branchcode day month year title description isexception )],
59
$rows = [ # exception holidays
72
        [ 'MPL', 11, 11, 2012, '', '', 1 ],    # sunday exception
60
    { branchcode => $mpl, day => 11, month => 11, year => 2012, isexception => 1 },    # sunday exception
73
        [ 'MPL', 1,  6,  2011, '', '', 0 ],
61
    { branchcode => $mpl, day => 1,  month => 6,  year => 2011, isexception => 0 },
74
        [ 'MPL', 4,  7,  2012, '', '', 0 ],
62
    { branchcode => $mpl, day => 4,  month => 7,  year => 2012, isexception => 0 },
75
        [ 'CPL', 6,  8,  2012, '', '', 0 ],
63
    { branchcode => $cpl, day => 6,  month => 8,  year => 2012, isexception => 0 },
76
        [ 'MPL', 7,  7,  2012, '', '', 1 ], # holiday exception
64
    { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 1 }, # holiday exception
77
        [ 'MPL', 7,  7,  2012, '', '', 0 ], # holiday
65
    { branchcode => $mpl, day => 7,  month => 7,  year => 2012, isexception => 0 }, # holiday
78
      ],
66
];
79
], "add fixtures";
67
$schema->resultset('SpecialHoliday')->delete_all;
68
$schema->resultset('SpecialHoliday')->create({ %$_, description => q{} }) for @$rows;
80
69
81
my $cache = Koha::Caches->get_instance();
70
my $cache = Koha::Caches->get_instance();
82
$cache->clear_from_cache('MPL_holidays');
71
$cache->clear_from_cache('MPL_holidays');
83
$cache->clear_from_cache('CPL_holidays');
72
$cache->clear_from_cache('CPL_holidays');
84
73
85
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
74
# $mpl branch is arbitrary, is not used at all but is needed for initialization
86
my $cal = Koha::Calendar->new( branchcode => 'MPL' );
75
my $cal = Koha::Calendar->new( branchcode => $mpl );
87
76
88
isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
77
isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
89
78
Lines 216-222 my $holiday_excepted = DateTime->new( Link Here
216
205
217
{    ## 'Datedue' tests
206
{    ## 'Datedue' tests
218
207
219
    $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Datedue' );
208
    $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Datedue' );
220
209
221
    is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
210
    is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
222
        dt_from_string('2012-07-05','iso'),
211
        dt_from_string('2012-07-05','iso'),
Lines 247-253 my $holiday_excepted = DateTime->new( Link Here
247
236
248
{   ## 'Calendar' tests'
237
{   ## 'Calendar' tests'
249
238
250
    $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Calendar' );
239
    $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Calendar' );
251
240
252
    $dt = dt_from_string('2012-07-03','iso');
241
    $dt = dt_from_string('2012-07-03','iso');
253
242
Lines 275-281 my $holiday_excepted = DateTime->new( Link Here
275
264
276
{   ## 'Days' tests
265
{   ## 'Days' tests
277
266
278
    $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Days' );
267
    $cal = Koha::Calendar->new( branchcode => $mpl, days_mode => 'Days' );
279
268
280
    $dt = dt_from_string('2012-07-03','iso');
269
    $dt = dt_from_string('2012-07-03','iso');
281
270
Lines 304-310 my $holiday_excepted = DateTime->new( Link Here
304
}
293
}
305
294
306
{
295
{
307
    $cal = Koha::Calendar->new( branchcode => 'CPL' );
296
    $cal = Koha::Calendar->new( branchcode => $cpl );
308
    is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
297
    is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
309
    is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' );
298
    is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' );
310
}
299
}
Lines 314-324 subtest 'days_mode parameter' => sub { Link Here
314
303
315
    t::lib::Mocks::mock_preference('useDaysMode', 'Days');
304
    t::lib::Mocks::mock_preference('useDaysMode', 'Days');
316
305
317
    $cal = Koha::Calendar->new( branchcode => 'CPL', days_mode => 'Calendar' );
306
    $cal = Koha::Calendar->new( branchcode => $cpl, days_mode => 'Calendar' );
318
    is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|);
307
    is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|);
319
};
308
};
320
309
321
END {
310
$cache->clear_from_cache('MPL_holidays');
322
    $cache->clear_from_cache('MPL_holidays');
311
$cache->clear_from_cache('CPL_holidays');
323
    $cache->clear_from_cache('CPL_holidays');
312
$schema->storage->txn_rollback;
324
};
325
- 

Return to bug 33727