Bug 42310: (follow-up) Adapt Calendar tests to new schema
Replace all references to the dropped tables (RepeatableHoliday, SpecialHoliday resultsets and raw DBI inserts) with Koha::Object classes: Koha::Calendar::WeeklyClosure, RepeatingClosure, SingleClosure, and Exception. Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
166e9831ea
commit
4d23dff433
|
|
@ -54,27 +54,81 @@ subtest 'Original tests from t' => sub {
|
|||
}
|
||||
);
|
||||
|
||||
my $mpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
|
||||
my $cpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
|
||||
my $rows = [ # add weekly holidays
|
||||
{ branchcode => $mpl, weekday => 0 }, # sundays
|
||||
{ branchcode => $mpl, weekday => 6 }, # saturdays
|
||||
{ branchcode => $mpl, day => 1, month => 1 }, # new year's day
|
||||
{ branchcode => $mpl, day => 25, month => 12 }, # chrismas
|
||||
];
|
||||
$schema->resultset('RepeatableHoliday')->delete_all;
|
||||
$schema->resultset('RepeatableHoliday')->create( { %$_, description => q{} } ) for @$rows;
|
||||
my $mpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
|
||||
my $cpl = $builder->build_object( { class => 'Koha::Libraries' } )->branchcode;
|
||||
|
||||
$rows = [ # exception holidays
|
||||
{ branchcode => $mpl, day => 11, month => 11, year => 2012, isexception => 1 }, # sunday exception
|
||||
{ branchcode => $mpl, day => 1, month => 6, year => 2011, isexception => 0 },
|
||||
{ branchcode => $mpl, day => 4, month => 7, year => 2012, isexception => 0 },
|
||||
{ branchcode => $cpl, day => 6, month => 8, year => 2012, isexception => 0 },
|
||||
{ branchcode => $mpl, day => 7, month => 7, year => 2012, isexception => 1 }, # holiday exception
|
||||
{ branchcode => $mpl, day => 7, month => 7, year => 2012, isexception => 0 }, # holiday
|
||||
];
|
||||
$schema->resultset('SpecialHoliday')->delete_all;
|
||||
$schema->resultset('SpecialHoliday')->create( { %$_, description => q{} } ) for @$rows;
|
||||
Koha::Calendar::WeeklyClosures->search( { library_id => [ $mpl, $cpl ] } )->delete;
|
||||
Koha::Calendar::RepeatingClosures->search( { library_id => [ $mpl, $cpl ] } )->delete;
|
||||
Koha::Calendar::SingleClosures->search( { library_id => [ $mpl, $cpl ] } )->delete;
|
||||
Koha::Calendar::Exceptions->search( { library_id => [ $mpl, $cpl ] } )->delete;
|
||||
|
||||
# Weekly closures
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::WeeklyClosures',
|
||||
value => { library_id => $mpl, weekday => 0, title => '', description => '' }
|
||||
}
|
||||
); # sundays
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::WeeklyClosures',
|
||||
value => { library_id => $mpl, weekday => 6, title => '', description => '' }
|
||||
}
|
||||
); # saturdays
|
||||
|
||||
# Repeating annual closures
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::RepeatingClosures',
|
||||
value => { library_id => $mpl, day => 1, month => 1, title => '', description => '' }
|
||||
}
|
||||
); # new year
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::RepeatingClosures',
|
||||
value => { library_id => $mpl, day => 25, month => 12, title => '', description => '' }
|
||||
}
|
||||
); # christmas
|
||||
|
||||
# Single closures
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => { library_id => $mpl, date => '2011-06-01', title => '', description => '' }
|
||||
}
|
||||
);
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => { library_id => $mpl, date => '2012-07-04', title => '', description => '' }
|
||||
}
|
||||
);
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => { library_id => $cpl, date => '2012-08-06', title => '', description => '' }
|
||||
}
|
||||
);
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => { library_id => $mpl, date => '2012-07-07', title => '', description => '' }
|
||||
}
|
||||
);
|
||||
|
||||
# Exceptions (open overrides)
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::Exceptions',
|
||||
value => { library_id => $mpl, date => '2012-11-11', title => '', description => '' }
|
||||
}
|
||||
); # sunday exception
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::Exceptions',
|
||||
value => { library_id => $mpl, date => '2012-07-07', title => '', description => '' }
|
||||
}
|
||||
); # holiday exception
|
||||
|
||||
my $cache = Koha::Caches->get_instance();
|
||||
$cache->clear_from_cache( $mpl . '_holidays' );
|
||||
|
|
@ -366,17 +420,11 @@ subtest 'Original tests from t' => sub {
|
|||
|
||||
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Calendar' );
|
||||
my $holiday = $builder->build(
|
||||
$builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => $library->branchcode,
|
||||
day => $holiday_dt->day,
|
||||
month => $holiday_dt->month,
|
||||
year => $holiday_dt->year,
|
||||
title => 'My holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value =>
|
||||
{ library_id => $library->branchcode, date => $holiday_dt->ymd, title => 'My holiday', description => '' }
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -518,12 +566,13 @@ subtest 'hours_between | days_between' => sub {
|
|||
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
|
||||
# Wednesdays are closed
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
|
||||
VALUES ( ?, ?, NULL, NULL, ?, '' )
|
||||
|, undef, $library->branchcode, 3, 'Closed on Wednesday'
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::WeeklyClosures',
|
||||
value => {
|
||||
library_id => $library->branchcode, weekday => 3, title => 'Closed on Wednesday', description => '',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
|
||||
|
|
@ -668,16 +717,16 @@ subtest 'is_holiday' => sub {
|
|||
$dow = 0 if $dow == 7;
|
||||
|
||||
# Closed this day of the week
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
|
||||
VALUES ( ?, ?, NULL, NULL, ?, '' )
|
||||
|, undef, $library->branchcode, $dow, "TEST"
|
||||
my $closure = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::WeeklyClosures',
|
||||
value => {
|
||||
library_id => $library->branchcode, weekday => $dow, title => 'TEST', description => '',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# Iterate 7 days
|
||||
my $sth = $dbh->prepare("UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'");
|
||||
for my $i ( 0 .. 6 ) {
|
||||
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
|
||||
|
||||
|
|
@ -687,7 +736,7 @@ subtest 'is_holiday' => sub {
|
|||
$day->add( days => 1 );
|
||||
$dow++;
|
||||
$dow = 0 if $dow == 7;
|
||||
$sth->execute( $dow, $library->branchcode );
|
||||
$closure->weekday($dow)->store;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
@ -707,16 +756,16 @@ subtest 'get_push_amt' => sub {
|
|||
$dow = 0 if $dow == 7;
|
||||
|
||||
# Closed this day of the week
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
q|
|
||||
INSERT INTO repeatable_holidays (branchcode,weekday,day,month,title,description)
|
||||
VALUES ( ?, ?, NULL, NULL, ?, '' )
|
||||
|, undef, $library->branchcode, $dow, "TEST"
|
||||
my $closure = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Calendar::WeeklyClosures',
|
||||
value => {
|
||||
library_id => $library->branchcode, weekday => $dow, title => 'TEST', description => '',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# Iterate 7 days
|
||||
my $sth = $dbh->prepare("UPDATE repeatable_holidays SET weekday = ? WHERE branchcode = ? AND title = 'TEST'");
|
||||
for my $i ( 0 .. 6 ) {
|
||||
my $calendar = Koha::Calendar->new( branchcode => $library->branchcode, days_mode => 'Dayweek' );
|
||||
|
||||
|
|
@ -739,7 +788,7 @@ subtest 'get_push_amt' => sub {
|
|||
$day->add( days => 1 );
|
||||
$dow++;
|
||||
$dow = 0 if $dow == 7;
|
||||
$sth->execute( $dow, $library->branchcode );
|
||||
$closure->weekday($dow)->store;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -122,8 +122,10 @@ my $mocked_datetime = Test::MockModule->new('DateTime');
|
|||
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
|
||||
|
||||
my $cache = Koha::Caches->get_instance();
|
||||
$dbh->do(q|DELETE FROM special_holidays|);
|
||||
$dbh->do(q|DELETE FROM repeatable_holidays|);
|
||||
$dbh->do(q|DELETE FROM library_single_closures|);
|
||||
$dbh->do(q|DELETE FROM library_closure_exceptions|);
|
||||
$dbh->do(q|DELETE FROM library_weekly_closures|);
|
||||
$dbh->do(q|DELETE FROM library_repeating_closures|);
|
||||
my $branches = Koha::Libraries->search();
|
||||
for my $branch ( $branches->next ) {
|
||||
my $key = $branch->branchcode . "_holidays";
|
||||
|
|
|
|||
|
|
@ -72,8 +72,10 @@ my $itemnumber = Koha::Item->new(
|
|||
|
||||
# clear any holidays to avoid throwing off the suspension day
|
||||
# calculations
|
||||
$dbh->do('DELETE FROM special_holidays');
|
||||
$dbh->do('DELETE FROM repeatable_holidays');
|
||||
$dbh->do('DELETE FROM library_single_closures');
|
||||
$dbh->do('DELETE FROM library_closure_exceptions');
|
||||
$dbh->do('DELETE FROM library_weekly_closures');
|
||||
$dbh->do('DELETE FROM library_repeating_closures');
|
||||
|
||||
my $daysago20 = dt_from_string->add_duration( DateTime::Duration->new( days => -20 ) );
|
||||
my $daysafter40 = dt_from_string->add_duration( DateTime::Duration->new( days => 40 ) );
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ my $schema = Koha::Database->new->schema;
|
|||
$schema->storage->txn_begin;
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(q{DELETE FROM special_holidays});
|
||||
$dbh->do(q{DELETE FROM repeatable_holidays});
|
||||
$dbh->do(q{DELETE FROM library_single_closures});
|
||||
$dbh->do(q{DELETE FROM library_closure_exceptions});
|
||||
$dbh->do(q{DELETE FROM library_weekly_closures});
|
||||
$dbh->do(q{DELETE FROM library_repeating_closures});
|
||||
$dbh->do("DELETE FROM reserves");
|
||||
|
||||
my $builder = t::lib::TestBuilder->new();
|
||||
|
|
@ -170,34 +172,24 @@ my $reserve3 = $builder->build(
|
|||
my $special_holiday1_dt = $today->clone;
|
||||
$special_holiday1_dt->add( days => 2 );
|
||||
|
||||
my $holiday = $builder->build(
|
||||
my $holiday = $builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => 'LIB1',
|
||||
day => $special_holiday1_dt->day,
|
||||
month => $special_holiday1_dt->month,
|
||||
year => $special_holiday1_dt->year,
|
||||
title => 'My special holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => {
|
||||
library_id => 'LIB1', date => $special_holiday1_dt->ymd, title => 'My special holiday', description => ''
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
my $special_holiday2_dt = $today->clone;
|
||||
$special_holiday2_dt->add( days => 4 );
|
||||
|
||||
my $holiday2 = $builder->build(
|
||||
my $holiday2 = $builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => 'LIB1',
|
||||
day => $special_holiday2_dt->day,
|
||||
month => $special_holiday2_dt->month,
|
||||
year => $special_holiday2_dt->year,
|
||||
title => 'My special holiday 2',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => {
|
||||
library_id => 'LIB1', date => $special_holiday2_dt->ymd, title => 'My special holiday 2', description => ''
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,46 +53,27 @@ subtest 'has_business_days_between' => sub {
|
|||
my $sunday = dt_from_string('2024-01-07'); # Sunday
|
||||
|
||||
# Make Wednesday a holiday
|
||||
my $wednesday_holiday = $builder->build(
|
||||
$builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => $branchcode,
|
||||
day => $wednesday->day,
|
||||
month => $wednesday->month,
|
||||
year => $wednesday->year,
|
||||
title => 'Wednesday Holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value =>
|
||||
{ library_id => $branchcode, date => $wednesday->ymd, title => 'Wednesday Holiday', description => '' }
|
||||
}
|
||||
);
|
||||
|
||||
# Make Saturday and Sunday holidays (weekend)
|
||||
my $saturday_holiday = $builder->build(
|
||||
$builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => $branchcode,
|
||||
day => $saturday->day,
|
||||
month => $saturday->month,
|
||||
year => $saturday->year,
|
||||
title => 'Saturday Holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value =>
|
||||
{ library_id => $branchcode, date => $saturday->ymd, title => 'Saturday Holiday', description => '' }
|
||||
}
|
||||
);
|
||||
|
||||
my $sunday_holiday = $builder->build(
|
||||
$builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => $branchcode,
|
||||
day => $sunday->day,
|
||||
month => $sunday->month,
|
||||
year => $sunday->year,
|
||||
title => 'Sunday Holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => { library_id => $branchcode, date => $sunday->ymd, title => 'Sunday Holiday', description => '' }
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ subtest 'Create a pickup' => sub {
|
|||
'Koha::Exceptions::CurbsidePickup::LibraryIsClosed',
|
||||
'Cannot create a pickup on a holiday';
|
||||
|
||||
C4::Context->dbh->do(q{DELETE FROM repeatable_holidays});
|
||||
C4::Context->dbh->do(q{DELETE FROM library_weekly_closures});
|
||||
Koha::Caches->get_instance->flush_all;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -91,17 +91,10 @@ subtest 'CancelExpiredReserves tests incl. holidays' => sub {
|
|||
);
|
||||
|
||||
Koha::Caches->get_instance()->flush_all();
|
||||
my $holiday = $builder->build(
|
||||
my $holiday = $builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => 'LIB1',
|
||||
day => $today->day,
|
||||
month => $today->month,
|
||||
year => $today->year,
|
||||
title => 'My holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => { library_id => 'LIB1', date => $today->ymd, title => 'My holiday', description => '' }
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -291,17 +284,13 @@ subtest 'Holiday logic edge cases' => sub {
|
|||
);
|
||||
|
||||
# Make Wednesday a holiday (but Monday and Tuesday are business days)
|
||||
my $wednesday_holiday = $builder->build(
|
||||
my $wednesday_holiday = $builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => $library->branchcode,
|
||||
day => $wednesday->day,
|
||||
month => $wednesday->month,
|
||||
year => $wednesday->year,
|
||||
title => 'Wednesday Holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => {
|
||||
library_id => $library->branchcode, date => $wednesday->ymd, title => 'Wednesday Holiday',
|
||||
description => ''
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -364,17 +353,13 @@ subtest 'Holiday logic edge cases' => sub {
|
|||
);
|
||||
|
||||
# Make Monday a holiday
|
||||
my $monday_holiday = $builder->build(
|
||||
my $monday_holiday = $builder->build_object(
|
||||
{
|
||||
source => 'SpecialHoliday',
|
||||
value => {
|
||||
branchcode => $library->branchcode,
|
||||
day => $monday->day,
|
||||
month => $monday->month,
|
||||
year => $monday->year,
|
||||
title => 'Monday Holiday',
|
||||
isexception => 0
|
||||
},
|
||||
class => 'Koha::Calendar::SingleClosures',
|
||||
value => {
|
||||
library_id => $library->branchcode, date => $monday->ymd, title => 'Monday Holiday',
|
||||
description => ''
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue