X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=t%2FCalendar.t;h=151e8b1874f573fabcb7b60e080d2960d85fa932;hb=dff16710ae53ebfab8596f27b35a7c8e35f81edf;hp=3082271b0643918951e8b3f38b7b77a9a9d1633c;hpb=658f603511e119fbcfa3d2581c804d0a0edd985f;p=srvgit diff --git a/t/Calendar.t b/t/Calendar.t index 3082271b06..151e8b1874 100755 --- a/t/Calendar.t +++ b/t/Calendar.t @@ -25,11 +25,13 @@ use DateTime::Duration; use Koha::Caches; use Koha::DateUtils; +use t::lib::Mocks; + use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 38; + plan tests => 40; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -37,22 +39,7 @@ BEGIN { use_ok('Koha::Calendar'); -use Test::DBIx::Class { - schema_class => 'Koha::Schema', - connect_info => ['dbi:SQLite:dbname=:memory:','',''], - connect_opts => { name_sep => '.', quote_char => '`', }, - fixture_class => '::Populate', -}, 'Biblio' ; - -sub fixtures { - my ( $data ) = @_; - fixtures_ok [ - Biblio => [ - [ qw/ biblionumber datecreated timestamp / ], - @$data, - ], - ], 'add fixtures'; -} +use Test::DBIx::Class; my $db = Test::MockModule->new('Koha::Database'); $db->mock( @@ -62,7 +49,7 @@ $db->mock( # We need to mock the C4::Context->preference method for # simplicity and re-usability of the session definition. Any # syspref fits for syspref-agnostic tests. -my $module_context = new Test::MockModule('C4::Context'); +my $module_context = Test::MockModule->new('C4::Context'); $module_context->mock( 'preference', sub { @@ -86,11 +73,14 @@ fixtures_ok [ [ 'MPL', 1, 6, 2011, '', '', 0 ], [ 'MPL', 4, 7, 2012, '', '', 0 ], [ 'CPL', 6, 8, 2012, '', '', 0 ], + [ 'MPL', 7, 7, 2012, '', '', 1 ], # holiday exception + [ 'MPL', 7, 7, 2012, '', '', 0 ], # holiday ], ], "add fixtures"; my $cache = Koha::Caches->get_instance(); -$cache->clear_from_cache( 'single_holidays') ; +$cache->clear_from_cache('MPL_holidays'); +$cache->clear_from_cache('CPL_holidays'); # 'MPL' branch is arbitrary, is not used at all but is needed for initialization my $cal = Koha::Calendar->new( branchcode => 'MPL' ); @@ -151,6 +141,12 @@ my $holiday_for_another_branch = DateTime->new( day => 6, # This is a monday ); +my $holiday_excepted = DateTime->new( + year => 2012, + month => 7, + day => 7, # Both a holiday and exception +); + { # Syspref-agnostic tests is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)'); is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)'); @@ -163,6 +159,7 @@ my $holiday_for_another_branch = DateTime->new( is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' ); is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' ); is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' ); + is ( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' ); } { # Bugzilla #8966 - is_holiday truncates referenced date @@ -219,15 +216,7 @@ my $holiday_for_another_branch = DateTime->new( { ## 'Datedue' tests - $module_context->unmock('preference'); - $module_context->mock( - 'preference', - sub { - return 'Datedue'; - } - ); - - $cal = Koha::Calendar->new( branchcode => 'MPL' ); + $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Datedue' ); is($cal->addDate( $dt, $one_day_dur, 'days' ), # tuesday dt_from_string('2012-07-05','iso'), @@ -258,15 +247,7 @@ my $holiday_for_another_branch = DateTime->new( { ## 'Calendar' tests' - $module_context->unmock('preference'); - $module_context->mock( - 'preference', - sub { - return 'Calendar'; - } - ); - - $cal = Koha::Calendar->new( branchcode => 'MPL' ); + $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Calendar' ); $dt = dt_from_string('2012-07-03','iso'); @@ -293,15 +274,8 @@ my $holiday_for_another_branch = DateTime->new( { ## 'Days' tests - $module_context->unmock('preference'); - $module_context->mock( - 'preference', - sub { - return 'Days'; - } - ); - $cal = Koha::Calendar->new( branchcode => 'MPL' ); + $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Days' ); $dt = dt_from_string('2012-07-03','iso'); @@ -335,4 +309,16 @@ my $holiday_for_another_branch = DateTime->new( is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' ); } -1; +subtest 'days_mode parameter' => sub { + plan tests => 1; + + t::lib::Mocks::mock_preference('useDaysMode', 'Days'); + + $cal = Koha::Calendar->new( branchcode => 'CPL', days_mode => 'Calendar' ); + is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|); +}; + +END { + $cache->clear_from_cache('MPL_holidays'); + $cache->clear_from_cache('CPL_holidays'); +};