-#!/usr/bin/env perl
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
+
+use Test::More;
+use Test::MockModule;
+
use DateTime;
use DateTime::Duration;
-use Test::More tests => 35;
-use Test::MockModule;
-use Koha::Cache;
+use Koha::Caches;
use Koha::DateUtils;
-BEGIN {
- use_ok('Koha::Calendar');
+use t::lib::Mocks;
- # This was the only test C4 had
- # Remove when no longer used
- #use_ok('C4::Calendar'); # not used anymore?
-}
-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 Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+ if ( check_install( module => 'Test::DBIx::Class' ) ) {
+ plan tests => 39;
+ } else {
+ plan skip_all => "Need Test::DBIx::Class"
+ }
}
+use_ok('Koha::Calendar');
+
+use Test::DBIx::Class;
+
my $db = Test::MockModule->new('Koha::Database');
$db->mock(
_new_schema => sub { return Schema(); }
[ 'MPL', 11, 11, 2012, '', '', 1 ], # sunday exception
[ 'MPL', 1, 6, 2011, '', '', 0 ],
[ 'MPL', 4, 7, 2012, '', '', 0 ],
+ [ 'CPL', 6, 8, 2012, '', '', 0 ],
],
], "add fixtures";
-my $cache = Koha::Cache->get_instance();
-$cache->clear_from_cache( 'single_holidays') ;
+my $cache = Koha::Caches->get_instance();
+$cache->clear_from_cache( 'single_holidays' ) ;
+$cache->clear_from_cache( 'exception_holidays' ) ;
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
my $cal = Koha::Calendar->new( branchcode => 'MPL' );
day => 26
); # for testing negative addDate
+my $holiday_for_another_branch = DateTime->new(
+ year => 2012,
+ month => 8,
+ day => 6, # This is a monday
+);
+
{ # 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($single_holiday), 1, 'Single holiday closed day test' );
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' );
}
{ # Bugzilla #8966 - is_holiday truncates referenced date
'==', 40, 'Test parameter order not relevant (Days)' );
}
+
+{
+ $cal = Koha::Calendar->new( branchcode => 'CPL' );
+ is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
+ is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' );
+}
+
+subtest 'days_mode parameter' => sub {
+ plan tests => 2;
+
+ t::lib::Mocks::mock_preference('useDaysMode', 'Days');
+ my $cal = Koha::Calendar->new( branchcode => 'CPL' );
+ is( $cal->{days_mode}, 'Days', q|If not set, days_mode defaults to syspref's value|);
+
+ $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( 'single_holidays' ) ;
+ $cache->clear_from_cache( 'exception_holidays' ) ;
+};