From c563106c4b08baaf7ef02561d78b3574de91a862 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Tue, 28 May 2019 12:48:29 +1200 Subject: [PATCH] Fix #390 intermittent failure when run over midnight. --- tests/attendance_webservices_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/attendance_webservices_test.php b/tests/attendance_webservices_test.php index b52cfba..c9a137a 100644 --- a/tests/attendance_webservices_test.php +++ b/tests/attendance_webservices_test.php @@ -172,6 +172,7 @@ class attendance_webservices_tests extends advanced_testcase { } // Add a session that's identical to the first, but with a group. + $midnight = usergetmidnight(time()); // Check if this test is running during midnight. $session = clone $this->sessions[0]; $session->groupid = $group->id; $session->sessdate += 3600; // Make sure it appears second in the list. @@ -179,6 +180,13 @@ class attendance_webservices_tests extends advanced_testcase { $courseswithsessions = attendance_handler::get_courses_with_today_sessions($this->teacher->id); + // This test is fragile when running over midnight - check that it is still the same day, if not, run this again. + // This isn't really ideal code, but will hopefully still give a valid test. + if (empty($courseswithsessions) && $midnight !== usergetmidnight(time())) { + $this->attendance->add_sessions([$session]); + $courseswithsessions = attendance_handler::get_courses_with_today_sessions($this->teacher->id); + } + $course = array_pop($courseswithsessions); $attendanceinstance = array_pop($course->attendance_instances); $session = array_pop($attendanceinstance['today_sessions']);