diff --git a/enrol/lti/classes/helper.php b/enrol/lti/classes/helper.php index 7c80ea9affb..f6a006ad098 100644 --- a/enrol/lti/classes/helper.php +++ b/enrol/lti/classes/helper.php @@ -313,7 +313,7 @@ class helper { $where = "AND"; } } - $sql .= " ORDER BY timecreated"; + $sql .= " ORDER BY elt.timecreated"; return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum); } diff --git a/enrol/lti/tests/helper_test.php b/enrol/lti/tests/helper_test.php index 07342a531be..971fa505bb5 100644 --- a/enrol/lti/tests/helper_test.php +++ b/enrol/lti/tests/helper_test.php @@ -157,6 +157,44 @@ class enrol_lti_helper_testcase extends advanced_testcase { $this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid' => $tool->enrolid))); } + /** + * Test returning the number of available tools. + */ + public function test_count_lti_tools() { + // Create two tools belonging to the same course. + $course1 = $this->getDataGenerator()->create_course(); + $data = new stdClass(); + $data->courseid = $course1->id; + $this->create_tool($data); + $this->create_tool($data); + + // Create two more tools in a separate course. + $course2 = $this->getDataGenerator()->create_course(); + $data = new stdClass(); + $data->courseid = $course2->id; + $this->create_tool($data); + + // Set the next tool to disabled. + $data->status = ENROL_INSTANCE_DISABLED; + $this->create_tool($data); + + // Count all the tools. + $count = \enrol_lti\helper::count_lti_tools(); + $this->assertEquals(4, $count); + + // Count all the tools in course 1. + $count = \enrol_lti\helper::count_lti_tools(array('courseid' => $course1->id)); + $this->assertEquals(2, $count); + + // Count all the tools in course 2 that are disabled. + $count = \enrol_lti\helper::count_lti_tools(array('courseid' => $course2->id, 'status' => ENROL_INSTANCE_DISABLED)); + $this->assertEquals(1, $count); + + // Count all the tools that are enabled. + $count = \enrol_lti\helper::count_lti_tools(array('status' => ENROL_INSTANCE_ENABLED)); + $this->assertEquals(3, $count); + } + /** * Test returning the list of available tools. */