Permalink
Browse files

Merge branch 'w22_MDL-39676_m25_whereparam' of git://github.com/skoda…

…k/moodle into MOODLE_25_STABLE
  • Loading branch information...
2 parents f407557 + 644b1df commit 4bc4844d5bf1f1885454bf7854ab935b0184daa9 @stronk7 stronk7 committed May 28, 2013
Showing with 30 additions and 17 deletions.
  1. +30 −17 lib/tests/accesslib_test.php
@@ -1222,8 +1222,7 @@ public function test_get_default_enrol_roles() {
* @return void
*/
public function test_get_role_users() {
- global $DB, $CFG;
- require_once("$CFG->dirroot/group/lib.php");
+ global $DB;
$this->resetAfterTest();
@@ -1238,37 +1237,51 @@ public function test_get_role_users() {
$otherrename = (object)array('roleid'=>$otherid, 'name'=>'Ostatní', 'contextid'=>$coursecontext->id);
$DB->insert_record('role_names', $otherrename);
- $user1 = $this->getDataGenerator()->create_user();
+ $user1 = $this->getDataGenerator()->create_user(array('firstname'=>'John', 'lastname'=>'Smith'));
role_assign($teacherrole->id, $user1->id, $coursecontext->id);
- $user2 = $this->getDataGenerator()->create_user();
+ $user2 = $this->getDataGenerator()->create_user(array('firstname'=>'Jan', 'lastname'=>'Kovar'));
role_assign($teacherrole->id, $user2->id, $systemcontext->id);
$user3 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user3->id, $course->id, $teacherrole->id);
$user4 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user4->id, $course->id, $studentrole->id);
$group = $this->getDataGenerator()->create_group(array('courseid'=>$course->id));
- groups_add_member($group->id, $user3->id);
+ groups_add_member($group, $user3);
$users = get_role_users($teacherrole->id, $coursecontext);
- $this->assertEquals(array($user1->id, $user3->id), array_keys($users), '', 0, 10, true);
- $user = $users[$user1->id];
- $this->assertEquals($teacherrole->id, $user->roleid);
- $this->assertEquals($teacherrole->name, $user->rolename);
- $this->assertEquals($teacherrole->shortname, $user->roleshortname);
- $this->assertEquals($teacherrename->name, $user->rolecoursealias);
+ $this->assertCount(2, $users);
+ $this->assertArrayHasKey($user1->id, $users);
+ $this->assertEquals($users[$user1->id]->id, $user1->id);
+ $this->assertEquals($users[$user1->id]->roleid, $teacherrole->id);
+ $this->assertEquals($users[$user1->id]->rolename, $teacherrole->name);
+ $this->assertEquals($users[$user1->id]->roleshortname, $teacherrole->shortname);
+ $this->assertEquals($users[$user1->id]->rolecoursealias, $teacherrename->name);
+ $this->assertArrayHasKey($user3->id, $users);
+ $this->assertEquals($users[$user3->id]->id, $user3->id);
+ $this->assertEquals($users[$user3->id]->roleid, $teacherrole->id);
+ $this->assertEquals($users[$user3->id]->rolename, $teacherrole->name);
+ $this->assertEquals($users[$user3->id]->roleshortname, $teacherrole->shortname);
+ $this->assertEquals($users[$user3->id]->rolecoursealias, $teacherrename->name);
$users = get_role_users($teacherrole->id, $coursecontext, true);
- $this->assertEquals(array($user1->id, $user2->id, $user3->id), array_keys($users), '', 0, 10, true);
+ $this->assertCount(3, $users);
- $users = get_role_users($teacherrole->id, $coursecontext, false, '', null, false);
- $this->assertEquals(array($user3->id), array_keys($users), '', 0, 10, true);
+ $users = get_role_users($teacherrole->id, $coursecontext, true, '', null, null, '', 2, 1);
+ $this->assertCount(1, $users);
- $users = get_role_users($teacherrole->id, $coursecontext, false, '', null, null);
+ $users = get_role_users($teacherrole->id, $coursecontext, false, 'u.id, u.email, u.idnumber', 'u.idnumber');
$this->assertCount(2, $users);
+ $this->assertArrayHasKey($user1->id, $users);
+ $this->assertArrayHasKey($user3->id, $users);
+
+ $users = get_role_users($teacherrole->id, $coursecontext, false, 'u.id, u.email, u.idnumber', 'u.idnumber', null, $group->id);
+ $this->assertCount(1, $users);
+ $this->assertArrayHasKey($user3->id, $users);
- $users = get_role_users($teacherrole->id, $coursecontext, false, 'u.id, u.email, u.idnumber', 'u.idnumber', true, $group->id, 0, 10, 'u.deleted = 0');
- $this->assertEquals(array($user3->id), array_keys($users), '', 0, 10, true);
+ $users = get_role_users($teacherrole->id, $coursecontext, true, 'u.id, u.email, u.idnumber, u.firstname', 'u.idnumber', null, '', '', '', 'u.firstname = :xfirstname', array('xfirstname'=>'John'));
+ $this->assertCount(1, $users);
+ $this->assertArrayHasKey($user1->id, $users);
}
/**

0 comments on commit 4bc4844

Please sign in to comment.