From 1823316503331bcfffbf1e96528f53b66a8893b7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 28 Oct 2019 12:18:04 +0000 Subject: [PATCH] Bug 23382: (RM follow-up) Days of the week discrepancies DateTime and C4::Calander have different notions of 'days of the week'. DateTime days go from 1..7 (Mon..Sun) whilst C4::Calendar expects 0..6 (Sun..Sat). This patch adapts the holday setting in the tests to ensure we work when testing Saturdays and Sundays. Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Charges/Fees.t | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Koha/Charges/Fees.t b/t/db_dependent/Koha/Charges/Fees.t index 2a7b7e1b09..544d9050bd 100644 --- a/t/db_dependent/Koha/Charges/Fees.t +++ b/t/db_dependent/Koha/Charges/Fees.t @@ -338,14 +338,27 @@ subtest 'accumulate_rentalcharge tests' => sub { ); my $calendar = C4::Calendar->new( branchcode => $library->id ); - my $day = $dt_from->day_of_week + 1; + # DateTime 1..7 (Mon..Sun), C4::Calender 0..6 (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 => $day, + weekday => $closed_day, title => 'Test holiday', description => 'Test holiday' ); $charge = $fees->accumulate_rentalcharge(); - my $dayname = $dt_from->clone->add( days => 1 )->day_name; + my $day_names = { + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday' + }; + my $dayname = $day_names->{$closed_day}; is( $charge, 5.00, "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed $dayname" ); @@ -384,7 +397,7 @@ subtest 'accumulate_rentalcharge tests' => sub { "Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed $dayname (96h - 24h * 0.25u)" ); - $calendar->delete_holiday( weekday => $day ); + $calendar->delete_holiday( weekday => $closed_day ); $charge = $fees->accumulate_rentalcharge(); is( $charge, 24.00, 'Hourly rental charge calculated correctly with finesCalendar = noFinesWhenClosed (96h - 0h * 0.25u)' ); }; -- 2.20.1