Skip to content

Commit

Permalink
MDL-83921 competency: Update unit tests with latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 authored and junpataleta committed Dec 5, 2024
1 parent 17552d4 commit 0f7c41d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions admin/tool/lp/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0f7c41d

Please sign in to comment.