Skip to content

Commit

Permalink
MDL-59994 competency: improve user competency unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Sep 18, 2017
1 parent 8c13028 commit 2fc95ec
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion competency/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4564,6 +4564,9 @@ public function test_list_plans_to_review() {
}

public function test_list_user_competencies_to_review() {
global $CFG;
require_once($CFG->dirroot . '/user/lib.php');

$dg = $this->getDataGenerator();
$this->resetAfterTest();
$ccg = $dg->get_plugin_generator('core_competency');
Expand All @@ -4580,6 +4583,7 @@ public function test_list_user_competencies_to_review() {

$u1 = $dg->create_user();
$u2 = $dg->create_user();
$u3 = $dg->create_user();
$f1 = $ccg->create_framework();
$c1 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
$c2 = $ccg->create_competency(['competencyframeworkid' => $f1->get('id')]);
Expand All @@ -4596,14 +4600,23 @@ public function test_list_user_competencies_to_review() {
'status' => user_competency::STATUS_IDLE]);
$uc2c = $ccg->create_user_competency(['userid' => $u2->id, 'competencyid' => $c3->get('id'),
'status' => user_competency::STATUS_IN_REVIEW]);
$uc3a = $ccg->create_user_competency(['userid' => $u3->id, 'competencyid' => $c3->get('id'),
'status' => user_competency::STATUS_WAITING_FOR_REVIEW]);

// The reviewer can review all plans waiting for review, or in review where they are the reviewer.
$this->setUser($reviewer);
$result = api::list_user_competencies_to_review();
$this->assertEquals(3, $result['count']);
$this->assertEquals(4, $result['count']);
$this->assertEquals($uc2a->get('id'), $result['competencies'][0]->usercompetency->get('id'));
$this->assertEquals($uc1b->get('id'), $result['competencies'][1]->usercompetency->get('id'));
$this->assertEquals($uc1c->get('id'), $result['competencies'][2]->usercompetency->get('id'));
$this->assertEquals($uc3a->get('id'), $result['competencies'][3]->usercompetency->get('id'));

// Now, let's delete user 3.
// It should not be listed on user competencies to review any more.
user_delete_user($u3);
$result = api::list_user_competencies_to_review();
$this->assertEquals(3, $result['count']);

// The reviewer cannot view the plans when they do not have the permission in the user's context.
role_assign($roleprohibit, $reviewer->id, context_user::instance($u2->id)->id);
Expand Down

0 comments on commit 2fc95ec

Please sign in to comment.