forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-83921 competency: Update unit tests with latest changes
- Loading branch information
1 parent
17552d4
commit 0f7c41d
Showing
1 changed file
with
10 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,17 +142,14 @@ public function test_search_users_by_capability(): void { | |
'email' => '[email protected]', 'phone1' => '123456', 'phone2' => '78910', 'department' => 'Marketing', | ||
'institution' => 'HQ')); | ||
|
||
// First we search with no capability assigned. | ||
// Assign capability required to perform the search. | ||
$this->setUser($ux); | ||
$result = external::search_users('yyylan', 'moodle/competency:planmanage'); | ||
$result = external_api::clean_returnvalue(external::search_users_returns(), $result); | ||
$this->assertCount(0, $result['users']); | ||
$this->assertEquals(0, $result['count']); | ||
$systemcontext = \context_system::instance(); | ||
$customrole = $this->assignUserCapability('moodle/competency:templatemanage', $systemcontext->id); | ||
|
||
// Now we assign a different capability. | ||
$usercontext = \context_user::instance($u1->id); | ||
$systemcontext = \context_system::instance(); | ||
$customrole = $this->assignUserCapability('moodle/competency:planview', $usercontext->id); | ||
$this->assignUserCapability('moodle/competency:templatemanage', $usercontext->id, $customrole); | ||
|
||
$result = external::search_users('yyylan', 'moodle/competency:planmanage'); | ||
$result = external_api::clean_returnvalue(external::search_users_returns(), $result); | ||
|
@@ -188,6 +185,8 @@ public function test_search_users_by_capability(): void { | |
$ux3 = $dg->create_user(); | ||
role_assign($this->creatorrole, $ux3->id, $usercontext->id); | ||
$this->setUser($ux3); | ||
$systemcontext = \context_system::instance(); | ||
$customrole = $this->assignUserCapability('moodle/competency:templatemanage', $systemcontext->id, $customrole); | ||
$result = external::search_users('yyylan', 'moodle/competency:planmanage'); | ||
$result = external_api::clean_returnvalue(external::search_users_returns(), $result); | ||
$this->assertCount(1, $result['users']); | ||
|
@@ -263,13 +262,15 @@ public function test_search_users_by_capability_the_comeback(): void { | |
|
||
// Now do the test. | ||
$this->setUser($master); | ||
$dummyrole = $this->assignUserCapability('moodle/competency:templatemanage', $syscontext->id); | ||
$result = external::search_users('MOODLER', 'moodle/site:config'); | ||
$this->assertCount(2, $result['users']); | ||
$this->assertEquals(2, $result['count']); | ||
$this->assertArrayHasKey($slave1->id, $result['users']); | ||
$this->assertArrayHasKey($slave3->id, $result['users']); | ||
|
||
$this->setUser($manager); | ||
$this->assignUserCapability('moodle/competency:templatemanage', $syscontext->id, $dummyrole); | ||
$result = external::search_users('MOODLER', 'moodle/site:config'); | ||
$this->assertCount(1, $result['users']); | ||
$this->assertEquals(1, $result['count']); | ||
|
@@ -378,6 +379,8 @@ public function test_search_users(): void { | |
|
||
// Switch to a user that cannot view identity fields. | ||
$this->setUser($ux); | ||
$systemcontext = \context_system::instance(); | ||
$this->assignUserCapability('moodle/competency:templatemanage', $systemcontext->id, $dummyrole); | ||
$CFG->showuseridentity = 'idnumber,email,phone1,phone2,department,institution'; | ||
|
||
// Only names are included. | ||
|