mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 18:36:42 +02:00
MDL-83290 dml: Remove "ORDER BY" from the $sort
This commit is contained in:
parent
269a8a8a1b
commit
a0f57612ee
2 changed files with 46 additions and 0 deletions
|
@ -36,6 +36,8 @@ use stdClass;
|
|||
* @category test
|
||||
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @covers \core_user\table\participants_search
|
||||
*/
|
||||
final class participants_search_test extends advanced_testcase {
|
||||
|
||||
|
@ -3508,4 +3510,44 @@ final class participants_search_test extends advanced_testcase {
|
|||
|
||||
return $finaltests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests sorting of participants in a course.
|
||||
*
|
||||
* This test runs a search for participants twice, first with an "ORDER BY" clause and second without.
|
||||
* The test asserts the correct ordering of participants based on the sorting condition.
|
||||
*/
|
||||
public function test_sort_participants(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
// Generate users with their role.
|
||||
$this->getDataGenerator()->create_and_enrol($course, 'teacher');
|
||||
$this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
|
||||
// Create the basic filter.
|
||||
$filterset = new participants_filterset();
|
||||
$filterset->add_filter(new integer_filter('courseid', null, [(int) $course->id]));
|
||||
|
||||
// Run the search with using ORDER BY.
|
||||
$search = new participants_search($course, $coursecontext, $filterset);
|
||||
$rs = $search->get_participants(
|
||||
sort: 'ORDER BY id', // Adding spaces between "ORDER" and "BY" is intentional.
|
||||
);
|
||||
$records = $this->convert_recordset_to_array($rs);
|
||||
$userids = array_keys($records);
|
||||
$this->assertGreaterThan($userids[0], $userids[1]);
|
||||
|
||||
// Run the search without using ORDER BY.
|
||||
$rs = $search->get_participants(
|
||||
sort: 'id DESC',
|
||||
);
|
||||
$records = $this->convert_recordset_to_array($rs);
|
||||
$userids = array_keys($records);
|
||||
$this->assertGreaterThan($userids[1], $userids[0]);
|
||||
|
||||
$rs->close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue