Bug 14522: (QA followup) tidy tests
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
This commit is contained in:
parent
945e7f5c04
commit
ff693f14fc
|
|
@ -383,28 +383,6 @@ sub clear_weekly_closed_days {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
sub add_dummy_holiday {
|
||||
my ( $self, $new_dt ) = @_;
|
||||
|
||||
my $cache = Koha::Cache->get_instance();
|
||||
my $single_holidays = $cache->get_from_cache('single_holidays');
|
||||
|
||||
# add a dummy holiday to the holiday cache...
|
||||
my $ymd = $new_dt->ymd('');
|
||||
$single_holidays->{'MPL'} = [$ymd];
|
||||
$cache->set_in_cache( 'single_holidays', $single_holidays, 76800 );
|
||||
|
||||
# ...but *dont* reset the cache, as this holiday was not really written to the db
|
||||
# its only used to mock a holiday insert for 1 test in t/db_dependent/Holidays.t
|
||||
|
||||
# is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
|
||||
# $koha_calendar->add_dummy_holiday($custom_holiday );
|
||||
# is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -1,40 +1,55 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use 5.010;
|
||||
use DateTime;
|
||||
use DateTime::TimeZone;
|
||||
use Test::More tests => 12;
|
||||
#!/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 tests => 10;
|
||||
use t::lib::TestBuilder;
|
||||
|
||||
use C4::Context;
|
||||
use C4::Branch;
|
||||
|
||||
use Koha::DateUtils;
|
||||
|
||||
BEGIN { use_ok('Koha::Calendar'); }
|
||||
BEGIN { use_ok('C4::Calendar'); }
|
||||
use DateTime;
|
||||
use DateTime::TimeZone;
|
||||
|
||||
BEGIN {
|
||||
use_ok('Koha::Calendar');
|
||||
use_ok('C4::Calendar');
|
||||
}
|
||||
|
||||
my $dbh = C4::Context->dbh();
|
||||
# Start transaction
|
||||
$dbh->{AutoCommit} = 0;
|
||||
$dbh->{RaiseError} = 1;
|
||||
|
||||
# Add branches if they don't exist
|
||||
if (not defined GetBranchDetail('CPL')) {
|
||||
ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
|
||||
}
|
||||
if (not defined GetBranchDetail('MPL')) {
|
||||
ModBranch({add => 1, branchcode => 'MPL', branchname => 'Midway'});
|
||||
}
|
||||
my $builder = t::lib::TestBuilder->new();
|
||||
# Create two fresh branches for the tests
|
||||
my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
|
||||
my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode };
|
||||
|
||||
# Make the repeatable_holidays table ONLY the default data.
|
||||
$dbh->do("DELETE FROM repeatable_holidays");
|
||||
C4::Calendar->new( branchcode => 'MPL' )->insert_week_day_holiday(
|
||||
C4::Calendar->new( branchcode => $branch_1 )->insert_week_day_holiday(
|
||||
weekday => 0,
|
||||
title => '',
|
||||
description => 'Sundays',
|
||||
);
|
||||
|
||||
my $holiday2add = dt_from_string("2015-01-01");
|
||||
C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday(
|
||||
C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday(
|
||||
day => $holiday2add->day(),
|
||||
month => $holiday2add->month(),
|
||||
year => $holiday2add->year(),
|
||||
|
|
@ -42,7 +57,7 @@ C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday(
|
|||
description => "New Year's Day",
|
||||
);
|
||||
$holiday2add = dt_from_string("2014-12-25");
|
||||
C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday(
|
||||
C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday(
|
||||
day => $holiday2add->day(),
|
||||
month => $holiday2add->month(),
|
||||
year => $holiday2add->year(),
|
||||
|
|
@ -50,10 +65,8 @@ C4::Calendar->new( branchcode => 'MPL' )->insert_day_month_holiday(
|
|||
description => 'Christmas',
|
||||
);
|
||||
|
||||
my $branchcode = 'MPL';
|
||||
|
||||
my $koha_calendar = Koha::Calendar->new( branchcode => $branchcode );
|
||||
my $c4_calendar = C4::Calendar->new( branchcode => $branchcode );
|
||||
my $koha_calendar = Koha::Calendar->new( branchcode => $branch_1 );
|
||||
my $c4_calendar = C4::Calendar->new( branchcode => $branch_1 );
|
||||
|
||||
isa_ok( $koha_calendar, 'Koha::Calendar', 'Koha::Calendar class returned' );
|
||||
isa_ok( $c4_calendar, 'C4::Calendar', 'C4::Calendar class returned' );
|
||||
|
|
@ -82,10 +95,7 @@ my $newyear = DateTime->new(
|
|||
is( $koha_calendar->is_holiday($sunday), 1, 'Sunday is a closed day' );
|
||||
is( $koha_calendar->is_holiday($monday), 0, 'Monday is not a closed day' );
|
||||
is( $koha_calendar->is_holiday($christmas), 1, 'Christmas is a closed day' );
|
||||
is( $koha_calendar->is_holiday($newyear), 1, 'New Years day is a closed day' );
|
||||
|
||||
$dbh->do("DELETE FROM repeatable_holidays");
|
||||
$dbh->do("DELETE FROM special_holidays");
|
||||
is( $koha_calendar->is_holiday($newyear), 1, 'New Years day is a closed day' );
|
||||
|
||||
my $custom_holiday = DateTime->new(
|
||||
year => 2013,
|
||||
|
|
@ -93,12 +103,8 @@ my $custom_holiday = DateTime->new(
|
|||
day => 12,
|
||||
);
|
||||
|
||||
is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
|
||||
$koha_calendar->add_dummy_holiday($custom_holiday );
|
||||
is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
|
||||
|
||||
my $today = dt_from_string();
|
||||
C4::Calendar->new( branchcode => 'CPL' )->insert_single_holiday(
|
||||
C4::Calendar->new( branchcode => $branch_2 )->insert_single_holiday(
|
||||
day => $today->day(),
|
||||
month => $today->month(),
|
||||
year => $today->year(),
|
||||
|
|
@ -106,7 +112,9 @@ C4::Calendar->new( branchcode => 'CPL' )->insert_single_holiday(
|
|||
description => "$today",
|
||||
);
|
||||
|
||||
is( Koha::Calendar->new( branchcode => 'CPL' )->is_holiday( $today ), 1, "Today is a holiday for CPL" );
|
||||
is( Koha::Calendar->new( branchcode => 'MPL' )->is_holiday( $today ), 0, "Today is not a holiday for MPL");
|
||||
is( Koha::Calendar->new( branchcode => $branch_2 )->is_holiday( $today ), 1, "Today is a holiday for $branch_2" );
|
||||
is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1");
|
||||
|
||||
$dbh->rollback;
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue