From 2fc95ecf809291c5d801d22aff449c745e284d8a Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 14 Sep 2017 10:02:54 +0800 Subject: [PATCH] MDL-59994 competency: improve user competency unit test --- competency/tests/api_test.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/competency/tests/api_test.php b/competency/tests/api_test.php index e29f9d6a7faa1..56e3ff073f632 100644 --- a/competency/tests/api_test.php +++ b/competency/tests/api_test.php @@ -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'); @@ -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')]); @@ -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);