From a781fb8fef5bda5c714f822ca6de82a65dd33478 Mon Sep 17 00:00:00 2001 From: Peter Rundqvist Date: Mon, 6 Sep 2021 09:00:12 +0200 Subject: [PATCH] Added unit test "test_get_sessions" --- tests/externallib_test.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/externallib_test.php b/tests/externallib_test.php index e7262e8..a97c9c3 100644 --- a/tests/externallib_test.php +++ b/tests/externallib_test.php @@ -471,4 +471,40 @@ class mod_attendance_external_testcase extends externallib_advanced_testcase { $this->assertInstanceOf('\core\event\calendar_event_created', $events[0]); $this->assertInstanceOf('\mod_attendance\event\session_added', $events[1]); } + + public function test_get_sessions() { + $this->resetAfterTest(true); + + $courseswithsessions = attendance_handler::get_courses_with_today_sessions($this->teacher->id); + $courseswithsessions = external_api::clean_returnvalue(mod_attendance_external::get_courses_with_today_sessions_returns(), + $courseswithsessions); + + foreach($courseswithsessions as $course) { + + $attendanceinstances = $course['attendance_instances']; + + foreach($attendanceinstances as $attendanceinstance) { + + $sessionsinfo = $attendanceinstance['today_sessions']; + + foreach($sessionsinfo as $sessioninfo) { + + $sessions = attendance_handler::get_sessions($sessioninfo['attendanceid']); + $sessions = external_api::clean_returnvalue(mod_attendance_external::get_sessions_returns(), + $sessions); + + foreach($sessions as $session) { + $sessiontocompareagainst = attendance_handler::get_session($session['id']); + $sessiontocompareagainst = external_api::clean_returnvalue(mod_attendance_external::get_session_returns(), + $sessiontocompareagainst); + + $this->assertEquals($this->attendance->id, $session['attendanceid']); + $this->assertEquals($sessiontocompareagainst['id'], $session['id']); + $this->assertEquals(count($session['users']), count($sessiontocompareagainst['users'])); + } + } + } + } + + } }