From 4d23dff4339e14a8d527397652edd6c54d4b168e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Wed, 8 Apr 2026 15:48:56 -0300 Subject: [PATCH] Bug 42310: (follow-up) Adapt Calendar tests to new schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Tomás Cohen Arazi Signed-off-by: Pedro Amorim --- t/db_dependent/Calendar.t | 153 ++++++++++++------ t/db_dependent/Circulation.t | 6 +- .../Circulation/maxsuspensiondays.t | 6 +- t/db_dependent/Holds/WaitingReserves.t | 36 ++--- t/db_dependent/Koha/Calendar.t | 41 ++--- t/db_dependent/Koha/CurbsidePickups.t | 2 +- .../Reserves/CancelExpiredReserves.t | 45 ++---- 7 files changed, 150 insertions(+), 139 deletions(-) diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t index 7fd26efdc7..623c2d4dbc 100755 --- a/t/db_dependent/Calendar.t +++ b/t/db_dependent/Calendar.t @@ -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; } }; }; diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 3ad7351987..35767e366a 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -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"; diff --git a/t/db_dependent/Circulation/maxsuspensiondays.t b/t/db_dependent/Circulation/maxsuspensiondays.t index 0bee50f8ad..e056ba515f 100755 --- a/t/db_dependent/Circulation/maxsuspensiondays.t +++ b/t/db_dependent/Circulation/maxsuspensiondays.t @@ -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 ) ); diff --git a/t/db_dependent/Holds/WaitingReserves.t b/t/db_dependent/Holds/WaitingReserves.t index 616145d215..766b2bccba 100755 --- a/t/db_dependent/Holds/WaitingReserves.t +++ b/t/db_dependent/Holds/WaitingReserves.t @@ -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 => '' + } } ); diff --git a/t/db_dependent/Koha/Calendar.t b/t/db_dependent/Koha/Calendar.t index 84a507b884..c22faf7fec 100755 --- a/t/db_dependent/Koha/Calendar.t +++ b/t/db_dependent/Koha/Calendar.t @@ -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 => '' } } ); diff --git a/t/db_dependent/Koha/CurbsidePickups.t b/t/db_dependent/Koha/CurbsidePickups.t index 1490d745a2..0eef295aa2 100755 --- a/t/db_dependent/Koha/CurbsidePickups.t +++ b/t/db_dependent/Koha/CurbsidePickups.t @@ -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; }; diff --git a/t/db_dependent/Reserves/CancelExpiredReserves.t b/t/db_dependent/Reserves/CancelExpiredReserves.t index 03b377c8fa..04aaa42a67 100755 --- a/t/db_dependent/Reserves/CancelExpiredReserves.t +++ b/t/db_dependent/Reserves/CancelExpiredReserves.t @@ -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 => '' + } } );