Bugzilla – Attachment 193660 Details for
Bug 17015
New Koha Calendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17015: Tests for DiscreteCalendar
Bug-17015-Tests-for-DiscreteCalendar.patch (text/plain), 54.99 KB, created by
Hammat wele
on 2026-02-23 17:45:41 UTC
(
hide
)
Description:
Bug 17015: Tests for DiscreteCalendar
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2026-02-23 17:45:41 UTC
Size:
54.99 KB
patch
obsolete
>From 4ffc36c2db531f0a983149c5867c1654087f92b9 Mon Sep 17 00:00:00 2001 >From: Charles Farmer <charles.farmer@inLibro.com> >Date: Wed, 4 Sep 2019 14:58:02 -0400 >Subject: [PATCH] Bug 17015: Tests for DiscreteCalendar > >TEST PLAN: >1- Apply the patch >2- Run installer/data/mysql/updatedatabase.pl >3- Run misc/cronjobs/add_days_discrete_calendar.pl >4- Check that the max date is today + 1 day >5- Run t/db_dependent/DiscreteCalendar.t (All tests should pass) > >Signed-off-by: Michal Denar <black23@gmail.com> >Signed-off-by: Amaury GAU <amaurygau@gmail.com> >--- > t/db_dependent/Circulation.t | 93 ++-- > t/db_dependent/Circulation/CalcDateDue.t | 281 ++++++----- > t/db_dependent/Circulation/CalcFine.t | 1 + > .../Circulation/maxsuspensiondays.t | 15 +- > t/db_dependent/DiscreteCalendar.t | 464 ++++++++++++++++++ > t/db_dependent/Fines.t | 6 + > t/db_dependent/Hold.t | 22 +- > t/db_dependent/Holds.t | 1 - > t/db_dependent/Holds/WaitingReserves.t | 44 +- > t/db_dependent/HoldsQueue.t | 19 +- > t/db_dependent/Koha/Charges/Fees.t | 51 +- > t/db_dependent/Koha/CurbsidePickups.t | 24 +- > t/db_dependent/Koha/ItemTypes.t | 1 - > .../Reserves/CancelExpiredReserves.t | 20 +- > t/lib/TestBuilder.pm | 32 +- > 15 files changed, 836 insertions(+), 238 deletions(-) > create mode 100755 t/db_dependent/DiscreteCalendar.t > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index 983f63adc7f..cd5f15a56e7 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -34,7 +34,6 @@ use t::lib::Mocks; > use t::lib::TestBuilder; > > use C4::Accounts; >-use C4::Calendar; > use C4::Circulation > qw( AddIssue AddReturn CanBookBeRenewed GetIssuingCharges AddRenewal GetSoonestRenewDate GetLatestAutoRenewDate LostItem GetUpcomingDueIssues CanBookBeIssued AddIssuingCharge MarkIssueReturned ProcessOfflinePayment transferbook ); > use C4::Biblio; >@@ -59,6 +58,7 @@ use Koha::Account::Offsets; > use Koha::ActionLogs; > use Koha::Notice::Messages; > use Koha::Cache::Memory::Lite; >+use Koha::DiscreteCalendar; > > my $builder = t::lib::TestBuilder->new; > >@@ -121,8 +121,7 @@ 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 discrete_calendar|); > my $branches = Koha::Libraries->search(); > for my $branch ( $branches->next ) { > my $key = $branch->branchcode . "_holidays"; >@@ -3758,15 +3757,16 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { > t::lib::Mocks::mock_preference( 'SuspensionsCalendar', 'noSuspensionsWhenClosed' ); > > # Adding a holiday 2 days ago >- my $calendar = C4::Calendar->new( branchcode => $library->{branchcode} ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->{branchcode} }); > my $two_days_ago = $now->clone->subtract( days => 2 ); >- $calendar->insert_single_holiday( >- day => $two_days_ago->day, >- month => $two_days_ago->month, >- year => $two_days_ago->year, >- title => 'holidayTest-2d', >- description => 'holidayDesc 2 days ago' >- ); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $two_days_ago, >+ end_date => $two_days_ago, >+ title => 'holidayTest-2d', >+ description => 'holidayDesc 2 days ago' >+ }); > > # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday) > $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) ); >@@ -3782,13 +3782,13 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { > > # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped > my $two_days_ahead = $now->clone->add( days => 2 ); >- $calendar->insert_single_holiday( >- day => $two_days_ahead->day, >- month => $two_days_ahead->month, >- year => $two_days_ahead->year, >- title => 'holidayTest+2d', >- description => 'holidayDesc 2 days ahead' >- ); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $two_days_ahead, >+ end_date => $two_days_ahead, >+ title => 'holidayTest+2d', >+ description => 'holidayDesc 2 days ahead' >+ }); > > # Same as above, but we should skip D+2 > $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 ); >@@ -3804,13 +3804,13 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { > > # Adding another holiday, day of expiration date > my $expected_expiration_dt = dt_from_string($expected_expiration); >- $calendar->insert_single_holiday( >- day => $expected_expiration_dt->day, >- month => $expected_expiration_dt->month, >- year => $expected_expiration_dt->year, >- title => 'holidayTest_exp', >- description => 'holidayDesc on expiration date' >- ); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $expected_expiration_dt, >+ end_date => $expected_expiration_dt, >+ title => 'holidayTest_exp', >+ description => 'holidayDesc on expiration date' >+ }); > > # Expiration date will be the day after > test_debarment_on_checkout( >@@ -3892,6 +3892,15 @@ subtest 'AddReturn + suspension_chargeperiod' => sub { > $message->{WasReturned} && exists $message->{PrevDebarred}, 1, > 'Previously debarred message for Addreturn when overdue' > ); >+ >+ # delete holidays >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date => $two_days_ago, >+ end_date => $expected_expiration_dt, >+ title => '', >+ description => '' >+ }); > }; > > subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { >@@ -6095,19 +6104,21 @@ subtest 'Incremented fee tests' => sub { > $accountline->delete(); > $issue->delete(); > >- my $calendar = C4::Calendar->new( branchcode => $library->id ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->id }); > >- # DateTime 1..7 (Mon..Sun), C4::Calendar 0..6 (Sun..Sat) >+ # DateTime 1..7 (Mon..Sun), Koha::DiscreteCalender 1..7 (Sun..Sat) > my $closed_day = >- ( $dt_from->day_of_week == 6 ) ? 0 >- : ( $dt_from->day_of_week == 7 ) ? 1 >- : $dt_from->day_of_week + 1; >+ ( $dt_from->day_of_week == 7 ) ? 1 >+ : $dt_from->day_of_week + 1; > my $closed_day_name = $dt_from->clone->add( days => 1 )->day_name; >- $calendar->insert_week_day_holiday( >- weekday => $closed_day, >- title => 'Test holiday', >- description => 'Test holiday' >- ); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ weekday => $closed_day, >+ start_date => $dt_from, >+ end_date => $dt_from, >+ title => 'Test holiday', >+ description => 'Test holiday' >+ }); > $issue = AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from ); > $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); > is( >@@ -6227,7 +6238,17 @@ subtest 'Incremented fee tests' => sub { > $accountline->delete(); > $issue->delete(); > >- $calendar->delete_holiday( weekday => $closed_day ); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ delete_type => 1, >+ override => 1, >+ weekday => $closed_day, >+ start_date => $dt_from, >+ end_date => $dt_from, >+ title => '', >+ description => '', >+ }); >+ > $issue = AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from ); > $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } ); > is( >diff --git a/t/db_dependent/Circulation/CalcDateDue.t b/t/db_dependent/Circulation/CalcDateDue.t >index 485b15b8181..ad11879f617 100755 >--- a/t/db_dependent/Circulation/CalcDateDue.t >+++ b/t/db_dependent/Circulation/CalcDateDue.t >@@ -9,7 +9,7 @@ use DBI; > use DateTime; > use t::lib::Mocks; > use t::lib::TestBuilder; >-use C4::Calendar; >+use Koha::DiscreteCalendar; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Library::Hours; > use Koha::CirculationRules; >@@ -40,6 +40,8 @@ my $issuelength = 10; > my $renewalperiod = 5; > my $lengthunit = 'days'; > >+$builder->fill_discrete_calendar({ branchcode => $library->branchcode, start_date => $dateexpiry, days => 365 }); >+ > Koha::CirculationRules->search()->delete(); > Koha::CirculationRules->set_rules( > { >@@ -79,23 +81,25 @@ is( $date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays' ) > > # Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and > # useDaysMode different from 'Days', return should forward the dateexpiry. >-my $calendar = C4::Calendar->new( branchcode => $branchcode ); >-$calendar->insert_single_holiday( >- day => 1, >- month => 1, >- year => 2013, >- title => 'holidayTest', >- description => 'holidayDesc' >-); >+my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode }); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => dt_from_string($dateexpiry, 'iso'), >+ end_date => dt_from_string($dateexpiry, 'iso'), >+ title => 'holidayTest', >+ description => 'holidayDesc' >+}); > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower ); > is( $date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day' ); >-$calendar->insert_single_holiday( >- day => 31, >- month => 12, >- year => 2012, >- title => 'holidayTest', >- description => 'holidayDesc' >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => dt_from_string('2012-12-31', 'iso'), >+ end_date => dt_from_string('2012-12-31', 'iso'), >+ title => 'holidayTest', >+ description => 'holidayDesc' >+}); > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower ); > is( $date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day' ); > >@@ -137,13 +141,15 @@ is( > # Now let's add a closed day on the expected renewal date, it should > # roll forward as per Datedue (i.e. one day at a time) > # For issues... >-$calendar->insert_single_holiday( >- day => 9 + $issuelength, >- month => 2, >- year => 2013, >- title => 'DayweekTest1', >- description => 'DayweekTest1' >-); >+my $issue_date = dt_from_string('2013-02-' . (9 + $issuelength), 'iso'); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $issue_date, >+ end_date => $issue_date, >+ title => 'DayweekTest1', >+ description => 'DayweekTest1' >+}); > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower ); > is( > $date, '2013-02-' . ( 9 + $issuelength + 1 ) . 'T23:59:00', >@@ -151,20 +157,25 @@ is( > ); > > # Remove the holiday we just created >-$calendar->delete_holiday( >- day => 9 + $issuelength, >- month => 2, >- year => 2013 >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $issue_date, >+ end_date => $issue_date, >+ title => '', >+ description => '', >+}); > > # ...and for renewals... >-$calendar->insert_single_holiday( >- day => 9 + $renewalperiod, >- month => 2, >- year => 2013, >- title => 'DayweekTest2', >- description => 'DayweekTest2' >-); >+my $renewal_date = dt_from_string('2013-02-' . (9 + $renewalperiod), 'iso'); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $renewal_date, >+ end_date => $renewal_date, >+ title => 'DayweekTest2', >+ description => 'DayweekTest2' >+}); > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 ); > is( > $date, '2013-02-' . ( 9 + $renewalperiod + 1 ) . 'T23:59:00', >@@ -172,11 +183,14 @@ is( > ); > > # Remove the holiday we just created >-$calendar->delete_holiday( >- day => 9 + $renewalperiod, >- month => 2, >- year => 2013, >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $renewal_date, >+ end_date => $renewal_date, >+ title => '', >+ description => '', >+}); > > # Now we test it does the right thing if the loan and renewal periods > # are a multiple of 7 days >@@ -212,13 +226,16 @@ my $dayweek_borrower = $builder->build_object( > > # For issues... > $start_date = DateTime->new( { year => 2013, month => 2, day => 9 } ); >-$calendar->insert_single_holiday( >- day => 9 + $dayweek_issuelength, >- month => 2, >- year => 2013, >- title => 'DayweekTest3', >- description => 'DayweekTest3' >-); >+my $holiday_date = $start_date->clone(); >+$holiday_date->add(days => $dayweek_issuelength); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $holiday_date, >+ end_date => $holiday_date, >+ title => 'DayweekTest3', >+ description => 'DayweekTest3' >+}); > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower ); > my $issue_should_add = $dayweek_issuelength + 7; > my $dayweek_issue_expected = $start_date->add( days => $issue_should_add ); >@@ -228,21 +245,27 @@ is( > ); > > # Remove the holiday we just created >-$calendar->delete_holiday( >- day => 9 + $dayweek_issuelength, >- month => 2, >- year => 2013, >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $holiday_date, >+ end_date => $holiday_date, >+ title => '', >+ description => '', >+}); > > # ...and for renewals... > $start_date = DateTime->new( { year => 2013, month => 2, day => 9 } ); >-$calendar->insert_single_holiday( >- day => 9 + $dayweek_renewalperiod, >- month => 2, >- year => 2013, >- title => 'DayweekTest4', >- description => 'DayweekTest4' >-); >+$holiday_date = $start_date->clone(); >+$holiday_date->add(days => $dayweek_renewalperiod); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $holiday_date, >+ end_date => $holiday_date, >+ title => 'DayweekTest4', >+ description => 'DayweekTest4' >+}); > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 ); > my $renewal_should_add = $dayweek_renewalperiod + 7; > my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add ); >@@ -252,11 +275,14 @@ is( > ); > > # Remove the holiday we just created >-$calendar->delete_holiday( >- day => 9 + $dayweek_renewalperiod, >- month => 2, >- year => 2013, >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $holiday_date, >+ end_date => $holiday_date, >+ title => '', >+ description => '', >+}); > > # Now test it continues to roll forward by 7 days until it finds > # an open day, so we create a 3 week period of closed Saturdays >@@ -264,30 +290,32 @@ $start_date = DateTime->new( { year => 2013, month => 2, day => 9 } ); > my $expected_rolled_date = DateTime->new( { year => 2013, month => 3, day => 9 } ); > my $holiday = $start_date->clone(); > $holiday->add( days => 7 ); >-$calendar->insert_single_holiday( >- day => $holiday->day, >- month => $holiday->month, >- year => 2013, >- title => 'DayweekTest5', >- description => 'DayweekTest5' >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $holiday, >+ end_date => $holiday, >+ title => 'DayweekTest5', >+ description => 'DayweekTest5' >+}); > $holiday->add( days => 7 ); >-$calendar->insert_single_holiday( >- day => $holiday->day, >- month => $holiday->month, >- year => 2013, >- title => 'DayweekTest6', >- description => 'DayweekTest6' >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $holiday, >+ end_date => $holiday, >+ title => 'DayweekTest6', >+ description => 'DayweekTest6' >+}); > $holiday->add( days => 7 ); >-$calendar->insert_single_holiday( >- day => $holiday->day, >- month => $holiday->month, >- year => 2013, >- title => 'DayweekTest7', >- description => 'DayweekTest7' >-); >- >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $holiday, >+ end_date => $holiday, >+ title => 'DayweekTest7', >+ description => 'DayweekTest7' >+}); > # For issues... > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower ); > $dayweek_issue_expected = $start_date->add( days => $issue_should_add ); >@@ -309,34 +337,47 @@ is( > $start_date = DateTime->new( { year => 2013, month => 2, day => 9 } ); > my $del_holiday = $start_date->clone(); > $del_holiday->add( days => 7 ); >-$calendar->delete_holiday( >- day => $del_holiday->day, >- month => $del_holiday->month, >- year => 2013 >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $del_holiday, >+ end_date => $del_holiday, >+ title => '', >+ description => '', >+}); > $del_holiday->add( days => 7 ); >-$calendar->delete_holiday( >- day => $del_holiday->day, >- month => $del_holiday->month, >- year => 2013 >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $del_holiday, >+ end_date => $del_holiday, >+ title => '', >+ description => '', >+}); > $del_holiday->add( days => 7 ); >-$calendar->delete_holiday( >- day => $del_holiday->day, >- month => $del_holiday->month, >- year => 2013 >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ override => 1, >+ start_date => $del_holiday, >+ end_date => $del_holiday, >+ title => '', >+ description => '', >+}); > > # Now test that useDaysMode "Dayweek" doesn't try to roll forward onto > # a permanently closed day and instead rolls forward just one day > $start_date = DateTime->new( { year => 2013, month => 2, day => 9 } ); > > # Our tests are concerned with Saturdays, so let's close on Saturdays >-$calendar->insert_week_day_holiday( >- weekday => 6, >- title => "Saturday closure", >- description => "Closed on Saturdays" >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ weekday => 7, >+ override => 1, >+ start_date => $start_date, >+ end_date => $start_date, >+ title => "Saturday closure", >+ description => "Closed on Saturdays" >+}); > > # For issues... > $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower ); >@@ -356,7 +397,16 @@ is( > ); > > # Remove the holiday we just created >-$calendar->delete_holiday( weekday => 6 ); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ weekday => 7, >+ override => 1, >+ delete_type => 1, >+ start_date => $start_date, >+ end_date => $start_date, >+ title => '', >+ description => '', >+}); > > # Renewal period of 0 is valid > Koha::CirculationRules->search()->delete(); >@@ -415,6 +465,8 @@ my $open = DateTime->new( year => 2023, month => 5, day => 1, hour => 10 )->hms > my $close = DateTime->new( year => 2023, month => 5, day => 1, hour => 16 )->hms; > my $now = DateTime->new( year => 2023, month => 5, day => 1, hour => 14 ); > >+$builder->fill_discrete_calendar({ branchcode => $library1->{branchcode}, start_date => $now }); >+ > foreach ( 0 .. 6 ) { > > # library opened 4 hours ago and closes in 2 hours. >@@ -449,14 +501,15 @@ is( > my $holiday_tomorrow = $now->clone->add( days => 1 ); > > # consider calendar >-my $library1_calendar = C4::Calendar->new( branchcode => $library1->{branchcode} ); >-$library1_calendar->insert_single_holiday( >- day => $holiday_tomorrow->day, >- month => $holiday_tomorrow->month, >- year => $holiday_tomorrow->year, >+my $library1_calendar = Koha::DiscreteCalendar->new({ branchcode => $library1->{branchcode} }); >+$library1_calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $holiday_tomorrow, >+ end_date => $holiday_tomorrow, > title => 'testholiday', >- description => 'testholiday' >-); >+ description => 'testholiday', >+ override => 1, >+}); > Koha::CirculationRules->set_rules( > { > categorycode => $patron_category->categorycode, >diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t >index 3fd1bd5f9a6..42041814fe0 100755 >--- a/t/db_dependent/Circulation/CalcFine.t >+++ b/t/db_dependent/Circulation/CalcFine.t >@@ -29,6 +29,7 @@ my $branch = $builder->build( > source => 'Branch', > } > ); >+$builder->fill_discrete_calendar({ branchcode => $branch->{branchcode}, start_date => '2000-01-01' }); > > my $category = $builder->build( > { >diff --git a/t/db_dependent/Circulation/maxsuspensiondays.t b/t/db_dependent/Circulation/maxsuspensiondays.t >index 0bee50f8adf..dba7cdc0f12 100755 >--- a/t/db_dependent/Circulation/maxsuspensiondays.t >+++ b/t/db_dependent/Circulation/maxsuspensiondays.t >@@ -21,6 +21,10 @@ $schema->storage->txn_begin; > my $builder = t::lib::TestBuilder->new; > my $dbh = C4::Context->dbh; > >+# clear any holidays to avoid throwing off the suspension day >+# calculations >+$dbh->do('DELETE FROM discrete_calendar'); >+ > my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; > my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; > my $patron_category = $builder->build( { source => 'Category' } ); >@@ -70,11 +74,6 @@ my $itemnumber = Koha::Item->new( > } > )->store->itemnumber; > >-# clear any holidays to avoid throwing off the suspension day >-# calculations >-$dbh->do('DELETE FROM special_holidays'); >-$dbh->do('DELETE FROM repeatable_holidays'); >- > my $daysago20 = dt_from_string->add_duration( DateTime::Duration->new( days => -20 ) ); > my $daysafter40 = dt_from_string->add_duration( DateTime::Duration->new( days => 40 ) ); > >@@ -131,6 +130,9 @@ subtest "suspension_chargeperiod" => sub { > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > my $item = $builder->build_sample_item; > >+ $builder->fill_discrete_calendar({ branchcode => $patron->{branchcode}, days => 365 }); >+ $builder->fill_discrete_calendar({ branchcode => $item->homebranch, days => 365 }); >+ > my $last_year = dt_from_string->clone->subtract( years => 1 ); > my $today = dt_from_string; > my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today ); >@@ -159,6 +161,9 @@ subtest "maxsuspensiondays" => sub { > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > my $item = $builder->build_sample_item; > >+ $builder->fill_discrete_calendar({ branchcode => $patron->{branchcode}, days => 365 }); >+ $builder->fill_discrete_calendar({ branchcode => $item->homebranch, days => 365 }); >+ > my $last_year = dt_from_string->clone->subtract( years => 1 ); > my $today = dt_from_string; > my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today ); >diff --git a/t/db_dependent/DiscreteCalendar.t b/t/db_dependent/DiscreteCalendar.t >new file mode 100755 >index 00000000000..7c717c1cb4b >--- /dev/null >+++ b/t/db_dependent/DiscreteCalendar.t >@@ -0,0 +1,464 @@ >+#!/usr/bin/perl >+ >+# Copyright 2015 Koha Development team >+# >+# 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 => 50; >+use Test::MockModule; >+ >+use t::lib::TestBuilder; >+ >+use C4::Context; >+use C4::Output; >+use Koha::DateUtils qw ( dt_from_string ); >+use Koha::DiscreteCalendar; >+ >+ >+my $module_context = Test::MockModule->new('C4::Context'); >+my $today = DateTime->today; >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+my $branch1 = $builder->build( { source => 'Branch' } )->{branchcode}; >+my $branch2 = $builder->build( { source => 'Branch' } )->{branchcode}; >+ >+$builder->fill_discrete_calendar({ branchcode => $branch1, days => 365 }); >+ >+$schema->resultset('DiscreteCalendar')->search({ >+ branchcode => $branch1 >+})->update_all({ >+ is_opened => 1, >+ holiday_type => '', >+ note => '', >+ open_hour => '08:00:00', >+ close_hour => '16:00:00' >+}); >+ >+isnt($branch1,'', "First branch to do tests. BranchCode => $branch1"); >+isnt($branch2,'', "Second branch to do tests. BranchCode => $branch2"); >+ >+#2 Calendars to make sure branches are treated separately. >+my $calendar = Koha::DiscreteCalendar->new({branchcode => $branch1}); >+my $calendar2 = Koha::DiscreteCalendar->new({branchcode => $branch2}); >+ >+my $unique_holiday = DateTime->today; >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date=>$unique_holiday, >+ end_date=>$unique_holiday >+}); >+is($calendar->is_opened($unique_holiday), 0, "Branch closed today : $unique_holiday"); >+ >+my @unique_holidays = $calendar->get_unique_holidays(); >+is(scalar @unique_holidays, 1, "Set of exception holidays at 1"); >+ >+my $yesterday = DateTime->today->subtract(days => 1); >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $yesterday, >+ end_date => $yesterday >+}); >+is($calendar->is_opened($yesterday), 1, "Cannot edit dates in the past without override : $yesterday is not a holiday"); >+ >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $yesterday, >+ end_date => $yesterday, >+ override => 1 >+}); >+is($calendar->is_opened($yesterday), 0, "Can edit dates in the past without override : $yesterday is a holiday"); >+ >+ >+my $days_between_start = DateTime->today; >+my $days_between_end = DateTime->today->add(days => 6); >+my $days_between = $calendar->days_between($days_between_start, $days_between_end)->in_units('days'); >+is($days_between, 5, "Days between skips holiday"); >+ >+my $repeatable_holiday = DateTime->today->add(days => 1); >+$calendar->edit_holiday({ >+ title => "repeatable", >+ holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE}, >+ start_date=>$repeatable_holiday, >+ end_date=>$repeatable_holiday >+}); >+is($calendar->is_opened($repeatable_holiday), 0, "Branch not opened on $repeatable_holiday"); >+ >+my @repeatable_holidays = $calendar->get_repeatable_holidays(); >+is(scalar @repeatable_holidays, 1, "Set of repeatable holidays at 1"); >+ >+# 1 being mysql DAYOFWEEK() for Sunday >+$calendar->edit_holiday({ >+ title => "Weekly", >+ weekday=>1, >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ start_date=>$today, >+ end_date=>$today >+}); >+my @weekly_holidays = $calendar->get_week_days_holidays(); >+is(scalar @weekly_holidays, 1, "Set of weekly holidays at 1"); >+ >+my $sunday = DateTime->today->add(days =>( 7 - $today->day_of_week)); >+is($calendar->is_opened($sunday), 0, "Branch not opened on " . $sunday->day_name ."s"); >+ >+my $unique_holiday_range_start = DateTime->today->add(days => 2); >+my $unique_holiday_range_end = DateTime->today->add(days => 7); >+$calendar->edit_holiday({ >+ title => "Single holiday range", >+ holiday_type=>"E", >+ start_date=>$unique_holiday_range_start, >+ end_date=>$unique_holiday_range_end >+}); >+@unique_holidays = $calendar->get_unique_holidays(); >+is(scalar @unique_holidays, 7, "Set of exception holidays at 7"); >+ >+my $repeatable_holiday_range_start = DateTime->today->add(days => 8); >+my $repeatable_holiday_range_end = DateTime->today->add(days => 13); >+$calendar->edit_holiday({ >+ title => "Repeatable holiday range", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE}, >+ start_date=>$repeatable_holiday_range_start, >+ end_date=>$repeatable_holiday_range_end >+}); >+@repeatable_holidays = $calendar->get_repeatable_holidays(); >+is(scalar @repeatable_holidays, 7, "Set of repeatable holidays at 7"); >+ >+#Hourly loan >+# ex : >+# item due : 2017-01-24 11:00:00 >+# item returned : 2017-01-26 10:00:00 >+# Branch closed : 2017-01-25 >+# Open/close hours : 08:00 to 16:00 (8h day) >+# Hours due : 5 hours on 2017-01-24 + 2 hours on 2017-01-26 = 7hours >+ >+my $open_hours_since_start = dt_from_string->truncate(to => 'day')->add(days => 40, hours => 11); >+my $open_hours_since_end = dt_from_string->truncate(to => 'day')->add(days => 42, hours => 10); >+my $holiday_between = dt_from_string->truncate(to => 'day')->add(days => 41); >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$open_hours_since_start, >+ end_date=>$open_hours_since_end >+}); >+ >+$calendar->edit_holiday({ >+ title => "Single holiday", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date=> $holiday_between, >+ end_date=>$holiday_between >+}); >+my $open_hours_between = $calendar->open_hours_between($open_hours_since_start, $open_hours_since_end); >+is($open_hours_between, 7, "7 Hours open between $open_hours_since_start and $open_hours_since_end"); >+ >+my $christmas = DateTime->new( >+ year => $today->year(), >+ month => 12, >+ day => 25, >+); >+$calendar->edit_holiday({ >+ title => "Christmas", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE}, >+ start_date=>$christmas, >+ end_date=>$christmas, >+ override => 1, # necessary if unit tests are run between Christmas and the first of the year >+}); >+is($calendar->is_opened($christmas), 0, "Branch closed on Christmas : $christmas"); >+ >+my $newyear = DateTime->new( >+ year => $today->year() +1, >+ month => 1, >+ day => 1, >+); >+ >+$calendar->edit_holiday({ >+ title => "New Year", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE}, >+ start_date=>$newyear, >+ end_date=>$newyear >+}); >+is($calendar->is_opened($newyear), 0, "Branch closed on New Year : $newyear"); >+ >+#Hours between : >+my $date_due = DateTime->today->add(days => 1); >+my $date_returned = DateTime->today->add(hours => 8); >+my $hours_between = $calendar->hours_between($date_due, $date_returned); >+ >+is($hours_between->in_units('hours'), 16, "Date due $date_due, returned $date_returned, 16 hours in advance"); >+ >+$date_due = DateTime->today->add(days => 1); >+$date_returned = DateTime->today->add(days => 1, hours => 16); >+$hours_between = $calendar->hours_between($date_due, $date_returned); >+ >+is($hours_between->in_units('hours'), 16, "Date due $date_due, returned $date_returned, 16 hours late"); >+ >+ >+#delete holidays >+is($calendar->is_opened($today), 0, "Today is closed"); >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$unique_holiday, >+ end_date=>$unique_holiday >+}); >+is($calendar->is_opened($today), 1, "Today's holiday was removed"); >+ >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date => $yesterday, >+ end_date => $yesterday, >+ override => 1 >+}); >+is($calendar->is_opened($yesterday), 1, "Yesterdays's holiday was removed with override"); >+ >+my $new_open_hours = '08:00'; >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ open_hour=>$new_open_hours, >+ close_hour=>'', >+ start_date=>$today, >+ end_date=>$today >+}); >+is($calendar->get_date_info($today, $branch1)->{open_hour}, '08:00:00', "Open hour changed to 08:00:00"); >+ >+isnt($calendar->get_date_info($today, $branch1)->{close_hour}, '', "Close hour not removed"); >+ >+my $delete_range_end = DateTime->today->add(days => 30); >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$today, >+ end_date=>$delete_range_end >+}); >+ >+ >+is($calendar->is_opened($today), 1, "Today's holiday was already removed"); >+is($calendar->is_opened(DateTime->today->add(days => 1)), 1, "Tomorrow's holiday was removed"); >+is($calendar->is_opened($delete_range_end), 1, "End of range holiday was removed"); >+ >+#Check if other branch was affected >+my @unique_holidays_branch2 = $calendar2->get_unique_holidays(); >+is(scalar @unique_holidays_branch2, 0, "Set of exception holidays at 0 for branch => $branch2"); >+my @repeatable_holidays_branch2 = $calendar2->get_repeatable_holidays(); >+is(scalar @repeatable_holidays_branch2, 0, "Set of repeatable holidays at 0 for branch => $branch2"); >+my @weekly_holidays_branch2 = $calendar2->get_week_days_holidays(); >+is(scalar @weekly_holidays_branch2, 0, "Set of weekly holidays at 0 for branch => $branch2"); >+ >+ >+#Tests for addDate() >+ >+my $one_day_dur = DateTime::Duration->new( days => 1 ); >+my $negative_one_day_dur = DateTime::Duration->new( days => - 1 ); >+my $two_day_dur = DateTime::Duration->new( days => 2 ); >+my $seven_day_dur = DateTime::Duration->new( days => 7 ); >+ >+#Preference useDaysMode Calendar >+$calendar->{days_mode} = 'Calendar'; >+$unique_holiday->add(days => 1); >+my $tomorrow = DateTime->today->add(days => 1); >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date=>$tomorrow, >+ end_date=>$tomorrow >+}); >+ >+is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(), >+ $today->add(days => 2)->ymd(), >+ 'Single day add (Calendar)' ); >+ >+is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(), >+ $today->add(days => 2)->ymd(), >+ 'Two days add, skips holiday (Calendar)' ); >+ >+cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq', >+ $today->add(days => 7)->ymd(), >+ 'Add 7 days (Calendar)' ); >+#Closed Sunday >+$calendar->edit_holiday({ >+ title => "Weekly", >+ weekday=>1, >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ start_date=>$today, >+ end_date=>$today >+}); >+is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1, >+ 'addDate skips closed Sunday (Calendar)' ); >+#to remove the closed sundays >+$today = DateTime->today; >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$today, >+ end_date=>$delete_range_end >+}); >+ >+is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(), >+ $today->add(days => - 1)->ymd(), >+ 'Negative call to addDate (Calendar)' ); >+ >+#Preference useDaysMode DateDue >+$calendar->{days_mode} = 'Datedue'; >+#clean everything >+$today = DateTime->today; >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$today, >+ end_date=>$delete_range_end >+}); >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date=>$tomorrow, >+ end_date=>$tomorrow >+}); >+ >+is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(), >+ $today->add(days => 2)->ymd(), >+ 'Single day add' ); >+ >+is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(), >+ $today->add(days => 2)->ymd(), >+ 'Two days add, skips holiday (Datedue)' ); >+ >+cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq', >+ $today->add(days => 7)->ymd(), >+ 'Add 7 days (Datedue)' ); >+#Closed Sunday >+$calendar->edit_holiday({ >+ title => "Weekly", >+ weekday=>1, >+ holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ start_date=>$today, >+ end_date=>$today >+}); >+is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1, >+ 'addDate skips closed Sunday (Datedue)' ); >+#to remove the closed sundays >+$today = DateTime->today; >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$today, >+ end_date=>$delete_range_end >+}); >+ >+is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(), >+ $today->add(days => - 1)->ymd(), >+ 'Negative call to addDate (Datedue)' ); >+ >+#Preference useDaysMode Days >+$calendar->{days_mode} = 'Days'; >+#clean everything >+$today = DateTime->today; >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date=>$today, >+ end_date=>$delete_range_end >+}); >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date=>$tomorrow, >+ end_date=>$tomorrow >+}); >+is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(), >+ $today->add(days => 1)->ymd(), >+ 'Single day add' ); >+ >+is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(), >+ $today->add(days => 2)->ymd(), >+ 'Two days add, skips holiday (Days)' ); >+ >+cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq', >+ $today->add(days => 7)->ymd(), >+ 'Add 7 days (Days)' ); >+#Closed Sunday >+$calendar->edit_holiday({ >+ title => "Weekly", >+ weekday => 1, >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ start_date => $today, >+ end_date => $today >+}); >+is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1, >+ 'addDate skips closed Sunday (Days)' ); >+ >+is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(), >+ $today->add(days => - 1)->ymd(), >+ 'Negative call to addDate (Days)' ); >+ >+#Days_forward >+ >+#clean the range >+$today = DateTime->today; >+$calendar->edit_holiday({ >+ title => '', >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ start_date => $today, >+ end_date => DateTime->today->add(days => 20) >+}); >+my $forwarded_dt = $calendar->days_forward($today, 10); >+ >+my $expected = $today->clone; >+$expected->add(days => 10); >+is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days'); >+ >+#Added a holiday >+$unique_holiday = DateTime->today->add(days => 15); >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $unique_holiday, >+ end_date => $unique_holiday >+}); >+$forwarded_dt = $calendar->days_forward($today, 20); >+ >+$expected->add(days => 11); >+is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday'); >+ >+$forwarded_dt = $calendar->days_forward($today, 0); >+is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt'); >+ >+$forwarded_dt = $calendar->days_forward($today, -2); >+is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt'); >+ >+#copying a branch to an other >+is($calendar2->is_opened($tomorrow), 1, "$branch2 opened tomorrow"); >+#Added a goliday tomorrow for branch1 >+$calendar->edit_holiday({ >+ title => "Single holiday Today", >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $tomorrow, >+ end_date => $tomorrow >+}); >+#Copy dates from branch1 to branch2 >+$calendar->copy_to_branch($branch2); >+#Check if branch2 is also closed tomorrow after copying from branch1 >+is($calendar2->is_opened($tomorrow), 0, "$branch2 close tomorrow after copying from $branch1"); >+ >+$schema->storage->txn_rollback; >+ >+1; >diff --git a/t/db_dependent/Fines.t b/t/db_dependent/Fines.t >index 9ae973403b6..c8025de7b72 100755 >--- a/t/db_dependent/Fines.t >+++ b/t/db_dependent/Fines.t >@@ -10,6 +10,8 @@ use Koha::DateUtils qw( dt_from_string ); > use Test::NoWarnings; > use Test::More tests => 6; > >+use t::lib::TestBuilder; >+ > my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; > my $dbh = C4::Context->dbh; >@@ -32,6 +34,10 @@ my $issuingrule = Koha::CirculationRules->set_rules( > } > ); > >+my $builder = t::lib::TestBuilder->new(); >+$builder->fill_discrete_calendar({ branchcode => '' }); >+$builder->fill_discrete_calendar({ branchcode => '', start_date => '2000-01-01' }); >+ > ok( $issuingrule, 'Issuing rule created' ); > > my $period_start = dt_from_string('2000-01-01'); >diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t >index f7f831f7799..d3db9ccbb9c 100755 >--- a/t/db_dependent/Hold.t >+++ b/t/db_dependent/Hold.t >@@ -22,7 +22,7 @@ use C4::Context; > use C4::Biblio qw( AddBiblio ); > use Koha::Database; > use Koha::Libraries; >-use C4::Calendar; >+use Koha::DiscreteCalendar; > use Koha::Patrons; > use Koha::Holds; > use Koha::Item; >@@ -78,9 +78,23 @@ my $hold = Koha::Hold->new( > ); > $hold->store(); > >-my $b1_cal = C4::Calendar->new( branchcode => $branches[1]->{branchcode} ); >-$b1_cal->insert_single_holiday( day => 2, month => 1, year => 2017, title => "Morty Day", description => "Rick" ) >- ; #Add a holiday >+$builder->fill_discrete_calendar({ >+ branchcode => $branches[1]->{branchcode}, >+ start_date => '2017-01-01', >+ days => dt_from_string->delta_days( dt_from_string( '2017-01-01' ) )->in_units( 'days'), >+}); >+my $b1_cal = Koha::DiscreteCalendar->new({ branchcode => $branches[1]->{branchcode} }); >+ >+my $holiday = dt_from_string('2017-01-02', 'iso'); >+$b1_cal->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ override => 1, >+ start_date => $holiday, >+ end_date => $holiday, >+ title => "Morty Day", >+ description => "Rick" >+}); #Add a holiday >+ > my $today = dt_from_string; > is( > $hold->age(), $today->delta_days( dt_from_string('2017-01-01') )->in_units('days'), >diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t >index 10e2597d8fc..63ee9ef54f8 100755 >--- a/t/db_dependent/Holds.t >+++ b/t/db_dependent/Holds.t >@@ -14,7 +14,6 @@ use Test::Exception; > use MARC::Record; > > use C4::Biblio; >-use C4::Calendar; > use C4::Items; > use C4::Reserves > qw( AddReserve CalculatePriority ModReserve AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve ); >diff --git a/t/db_dependent/Holds/WaitingReserves.t b/t/db_dependent/Holds/WaitingReserves.t >index 616145d2154..23b5ffd8a7b 100755 >--- a/t/db_dependent/Holds/WaitingReserves.t >+++ b/t/db_dependent/Holds/WaitingReserves.t >@@ -17,8 +17,7 @@ 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 discrete_calendar}); > $dbh->do("DELETE FROM reserves"); > > my $builder = t::lib::TestBuilder->new(); >@@ -41,6 +40,9 @@ $builder->build( > } > ); > >+$builder->fill_discrete_calendar({ branchcode => 'LIB1' }); >+my $calendar = Koha::DiscreteCalendar->new({ branchcode => 'LIB1' }); >+ > $builder->build( > { > source => 'Branch', >@@ -170,36 +172,22 @@ my $reserve3 = $builder->build( > my $special_holiday1_dt = $today->clone; > $special_holiday1_dt->add( days => 2 ); > >-my $holiday = $builder->build( >- { >- 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 >- }, >- } >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $special_holiday1_dt, >+ end_date => $special_holiday1_dt, >+ title => 'My special holiday', >+}); > > my $special_holiday2_dt = $today->clone; > $special_holiday2_dt->add( days => 4 ); > >-my $holiday2 = $builder->build( >- { >- 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 >- }, >- } >-); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $special_holiday2_dt, >+ end_date => $special_holiday2_dt, >+ title => 'My special holiday 2', >+}); > > Koha::Caches->get_instance->flush_all; > >diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t >index b4db63abfe3..7d1039535a1 100755 >--- a/t/db_dependent/HoldsQueue.t >+++ b/t/db_dependent/HoldsQueue.t >@@ -12,7 +12,7 @@ use Test::NoWarnings; > use Test::More tests => 65; > use Data::Dumper; > >-use C4::Calendar; >+use Koha::DiscreteCalendar; > use C4::Context; > use C4::Members; > use C4::Circulation qw( AddIssue AddReturn ); >@@ -392,18 +392,19 @@ is( > # have 1 row in the holds queue > t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 1 ); > my $today = dt_from_string(); >-C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday( >- day => $today->day(), >- month => $today->month(), >- year => $today->year(), >- title => "$today", >- description => "$today", >-); >+my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcodes[0] }); >+$calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $today, >+ end_date => $today, >+ title => "$today", >+ description => "$today", >+}); > > # If the test below is removed, another tests using the holiday will fail. For some reason if we call is_holiday now > # the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead. > is( >- Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday($today), 1, >+ $calendar->is_holiday($today), 1, > 'Is today a holiday for pickup branch' > ); > C4::HoldsQueue::CreateQueue(); >diff --git a/t/db_dependent/Koha/Charges/Fees.t b/t/db_dependent/Koha/Charges/Fees.t >index 8d01c2a38bc..cf988c591cd 100755 >--- a/t/db_dependent/Koha/Charges/Fees.t >+++ b/t/db_dependent/Koha/Charges/Fees.t >@@ -29,7 +29,7 @@ use t::lib::TestBuilder; > use t::lib::Dates; > > use Time::Fake; >-use C4::Calendar; >+use Koha::DiscreteCalendar; > use Koha::DateUtils qw(dt_from_string); > > BEGIN { >@@ -363,27 +363,30 @@ subtest 'accumulate_rentalcharge tests' => sub { > ); > $itemtype->rentalcharge_daily_calendar(1)->store(); > >- my $calendar = C4::Calendar->new( branchcode => $library->id ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->id }); > >- # DateTime 1..7 (Mon..Sun), C4::Calendar 0..6 (Sun..Sat) >+ # DateTime 1..7 (Mon..Sun), Koha::DiscreteCalendar 1..7 (Sun..Sat) > my $closed_day = >- ( $dt_from->day_of_week == 6 ) ? 0 >- : ( $dt_from->day_of_week == 7 ) ? 1 >- : $dt_from->day_of_week + 1; >- $calendar->insert_week_day_holiday( >- weekday => $closed_day, >- title => 'Test holiday', >- description => 'Test holiday' >- ); >+ ( $dt_from->day_of_week == 7 ) ? 1 >+ : $dt_from->day_of_week + 1; >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ weekday => $closed_day, >+ override => 1, >+ start_date => $dt_from, >+ end_date => $dt_from, >+ title => 'Test holiday', >+ description => 'Test holiday' >+ }); > $charge = $fees->accumulate_rentalcharge(); > my $day_names = { >- 0 => 'Sunday', >- 1 => 'Monday', >- 2 => 'Tuesday', >- 3 => 'Wednesday', >- 4 => 'Thursday', >- 5 => 'Friday', >- 6 => 'Saturday' >+ 1 => 'Sunday', >+ 2 => 'Monday', >+ 3 => 'Tuesday', >+ 4 => 'Wednesday', >+ 5 => 'Thursday', >+ 6 => 'Friday', >+ 7 => 'Saturday' > }; > my $dayname = $day_names->{$closed_day}; > is( >@@ -437,7 +440,17 @@ subtest 'accumulate_rentalcharge tests' => sub { > ); > > $itemtype->rentalcharge_hourly_calendar(1)->store(); >- $calendar->delete_holiday( weekday => $closed_day ); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ weekday => $closed_day, >+ override => 1, >+ today => $dt_from, # To override past date when deleting holiday type >+ delete_type => 1, >+ start_date => $dt_from, >+ end_date => $dt_from, >+ title => '', >+ description => '', >+ }); > $charge = $fees->accumulate_rentalcharge(); > is( > $charge, 24.00, >diff --git a/t/db_dependent/Koha/CurbsidePickups.t b/t/db_dependent/Koha/CurbsidePickups.t >index 1490d745a29..e6a62b53dd6 100755 >--- a/t/db_dependent/Koha/CurbsidePickups.t >+++ b/t/db_dependent/Koha/CurbsidePickups.t >@@ -21,10 +21,9 @@ use Test::NoWarnings; > use Test::More tests => 5; > use Test::Exception; > >-use C4::Calendar; > use Koha::CurbsidePickups; > use Koha::CurbsidePickupPolicies; >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); > >@@ -152,19 +151,30 @@ subtest 'Create a pickup' => sub { > > # Day is a holiday > Koha::Caches->get_instance->flush_all; >- C4::Calendar->new( branchcode => $library->branchcode )->insert_week_day_holiday( >- weekday => 1, >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->branchcode }); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY}, >+ weekday => 2, >+ start_date => $schedule_dt, >+ end_date => $schedule_dt, > title => '', > description => 'Mondays', >- ); >- my $calendar = Koha::Calendar->new( branchcode => $library->branchcode ); >+ }); > throws_ok { > Koha::CurbsidePickup->new( { %$params, scheduled_pickup_datetime => $schedule_dt } )->store; > } > 'Koha::Exceptions::CurbsidePickup::LibraryIsClosed', > 'Cannot create a pickup on a holiday'; > >- C4::Context->dbh->do(q{DELETE FROM repeatable_holidays}); >+ $calendar->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE}, >+ weekday => 2, >+ delete_type => 1, >+ start_date => $schedule_dt, >+ end_date => $schedule_dt, >+ description => '', >+ }); >+ > Koha::Caches->get_instance->flush_all; > }; > >diff --git a/t/db_dependent/Koha/ItemTypes.t b/t/db_dependent/Koha/ItemTypes.t >index 0970ab62008..a86ca3990f3 100755 >--- a/t/db_dependent/Koha/ItemTypes.t >+++ b/t/db_dependent/Koha/ItemTypes.t >@@ -25,7 +25,6 @@ use Test::More tests => 19; > use t::lib::Mocks; > use t::lib::TestBuilder; > >-use C4::Calendar; > use Koha::Biblioitems; > use Koha::Libraries; > use Koha::Database; >diff --git a/t/db_dependent/Reserves/CancelExpiredReserves.t b/t/db_dependent/Reserves/CancelExpiredReserves.t >index 03b377c8faa..c6d63cfb96f 100755 >--- a/t/db_dependent/Reserves/CancelExpiredReserves.t >+++ b/t/db_dependent/Reserves/CancelExpiredReserves.t >@@ -91,19 +91,13 @@ subtest 'CancelExpiredReserves tests incl. holidays' => sub { > ); > > Koha::Caches->get_instance()->flush_all(); >- my $holiday = $builder->build( >- { >- source => 'SpecialHoliday', >- value => { >- branchcode => 'LIB1', >- day => $today->day, >- month => $today->month, >- year => $today->year, >- title => 'My holiday', >- isexception => 0 >- }, >- } >- ); >+ $builder->fill_discrete_calendar({ branchcode => 'LIB1 '}); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => 'LIB1' })->edit_holiday({ >+ holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION}, >+ start_date => $today, >+ end_date => $today, >+ title => 'My holiday', >+ }); > > CancelExpiredReserves(); > my $r3 = Koha::Holds->find( $reserve3->{reserve_id} ); >diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm >index 674d6ca07f4..51875beafaf 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -6,7 +6,7 @@ use Koha::Database; > use C4::Biblio qw( AddBiblio ); > use Koha::Biblios; > use Koha::Items; >-use Koha::DateUtils qw( dt_from_string ); >+use Koha::DateUtils qw( dt_from_string output_pref ); > > use Bytes::Random::Secure; > use Carp qw( carp ); >@@ -152,6 +152,10 @@ sub build { > if scalar @{ $fk->{keys} } == 1; > } > >+ if ($source eq 'Branch') { >+ $self->fill_discrete_calendar({ branchcode => $col_values->{branchcode} }); >+ } >+ > # store this record and return hashref > return $self->_storeColumnValues( > { >@@ -230,6 +234,32 @@ sub build_sample_ill_request { > )->store->get_from_storage; > } > >+sub fill_discrete_calendar { >+ my ( $self, $args ) = @_; >+ >+ my $branchcode = $args->{branchcode} || ''; >+ my $start_date = ($args->{start_date}) ? dt_from_string($args->{start_date}) : DateTime->today(); >+ my $days = $args->{days} || 60; >+ >+ my $end_date = $start_date->clone(); >+ $start_date->add(days => 0 - $days); >+ $end_date->add(days => $days); >+ >+ for (1; $start_date <= $end_date; $start_date->add(days => 1)) { >+ my $data = { >+ date => output_pref( { dt => $start_date, dateformat => 'iso', dateonly => 1 }), >+ branchcode => $branchcode, >+ is_opened => 1, >+ open_hour => "08:00:00", >+ close_hour => "17:00:00", >+ }; >+ >+ $self->schema->resultset( "DiscreteCalendar" )->update_or_create( $data ); >+ } >+ >+ return >+} >+ > # ------------------------------------------------------------------------------ > # Internal helper routines > >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17015
:
53859
|
54318
|
54419
|
59166
|
59167
|
59168
|
59169
|
59170
|
59171
|
59267
|
59268
|
59269
|
59270
|
59271
|
59463
|
59516
|
59517
|
59518
|
59519
|
59520
|
59561
|
59562
|
59586
|
59587
|
59888
|
59889
|
60902
|
60903
|
60904
|
60905
|
60906
|
60986
|
61737
|
62375
|
62376
|
62380
|
63257
|
63282
|
63362
|
63363
|
63364
|
63365
|
63366
|
63367
|
64235
|
65073
|
65074
|
65075
|
65076
|
65077
|
67721
|
67722
|
67723
|
67724
|
67725
|
67879
|
67929
|
67930
|
67931
|
67932
|
67933
|
67934
|
68392
|
68393
|
68394
|
68395
|
68396
|
68397
|
71634
|
71635
|
71636
|
71637
|
71638
|
72890
|
73145
|
74859
|
74860
|
74861
|
74862
|
74863
|
74864
|
74865
|
74866
|
75444
|
75479
|
76594
|
77249
|
77250
|
77607
|
77608
|
77609
|
77610
|
77611
|
77612
|
77613
|
77770
|
77771
|
77772
|
77773
|
77774
|
79035
|
80523
|
80524
|
80525
|
80526
|
80527
|
80528
|
80529
|
80530
|
80531
|
80532
|
80533
|
80534
|
80535
|
83547
|
85394
|
85677
|
85678
|
85679
|
85680
|
85681
|
85682
|
85683
|
85684
|
85685
|
85686
|
85687
|
85688
|
85689
|
85690
|
85691
|
92595
|
92596
|
92597
|
92598
|
100079
|
110383
|
110384
|
110386
|
110387
|
110388
|
110389
|
113541
|
113905
|
115501
|
115502
|
115503
|
115504
|
115505
|
115506
|
115507
|
115508
|
115509
|
115510
|
115511
|
118554
|
118555
|
118556
|
118557
|
118558
|
118559
|
119095
|
119097
|
119099
|
119100
|
119101
|
119102
|
131619
|
131620
|
131621
|
131622
|
131623
|
131624
|
131625
|
131626
|
131634
|
131635
|
131636
|
131637
|
131638
|
131639
|
131640
|
131641
|
131667
|
132199
|
133596
|
133597
|
133598
|
133599
|
133600
|
133601
|
133602
|
133603
|
133604
|
133605
|
133678
|
137219
|
137220
|
137221
|
137222
|
137223
|
137224
|
137225
|
137226
|
137227
|
137228
|
137229
|
139378
|
139379
|
139380
|
139381
|
139382
|
139599
|
139600
|
139601
|
139602
|
139603
|
139851
|
140150
|
141176
|
144257
|
144258
|
144259
|
144260
|
144261
|
144262
|
144264
|
144268
|
144269
|
144270
|
144271
|
144272
|
144273
|
151438
|
151439
|
151440
|
151441
|
151442
|
151443
|
151444
|
151445
|
151446
|
151447
|
151448
|
151449
|
151450
|
156340
|
156341
|
156342
|
156343
|
156344
|
156345
|
156346
|
156347
|
156348
|
156349
|
156350
|
156351
|
156352
|
156353
|
156354
|
156355
|
157656
|
157657
|
157658
|
157659
|
157660
|
157661
|
157662
|
157663
|
157664
|
157665
|
157666
|
157667
|
157668
|
157669
|
157670
|
157671
|
157672
|
167805
|
167806
|
167807
|
167808
|
167809
|
180312
|
180313
|
180314
|
180315
|
180316
|
180552
|
180962
|
181466
|
183006
|
185569
|
185570
|
185571
|
185572
|
185573
|
185574
|
185575
|
185576
|
185577
|
193656
|
193657
|
193658
|
193659
| 193660 |
193661
|
193662
|
193663
|
193664
|
193665