MDL-63485 core_user: Allow filtering by No groups on participants page
A new optional parameter $context has been added to the core_group::groups_get_members_join() function. Besides, some core_group methods now accept -1 (USERSWITHOUTHGROUP) for the groupid field. Backport of MDL-61967.
This commit is contained in:
@@ -2335,6 +2335,40 @@ class core_accesslib_testcase extends advanced_testcase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that enrolled users SQL does not return any values for users
|
||||
* without a group when $context is not a valid course context.
|
||||
*/
|
||||
public function test_get_enrolled_sql_userswithoutgroup() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||
|
||||
$group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
|
||||
groups_add_member($group, $user1);
|
||||
|
||||
$enrolled = get_enrolled_users($coursecontext);
|
||||
$this->assertCount(2, $enrolled);
|
||||
|
||||
// Get users without any group on the course context.
|
||||
$enrolledwithoutgroup = get_enrolled_users($coursecontext, '', USERSWITHOUTGROUP);
|
||||
$this->assertCount(1, $enrolledwithoutgroup);
|
||||
$this->assertFalse(isset($enrolledwithoutgroup[$user1->id]));
|
||||
|
||||
// Get users without any group on the system context (it should throw an exception).
|
||||
$this->expectException('coding_exception');
|
||||
get_enrolled_users($systemcontext, '', USERSWITHOUTGROUP);
|
||||
}
|
||||
|
||||
public function get_enrolled_sql_provider() {
|
||||
return array(
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user