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"
}
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(
# 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 {
[ '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' );
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)');
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
{ ## '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'),
{ ## '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');
{ ## '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');
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');
+};