예제 #1
0
 /**
  * Test update course competency settings.
  */
 public function test_update_course_competency_settings()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $course = $dg->create_course();
     $roleid = $dg->create_role();
     $noobroleid = $dg->create_role();
     $context = context_course::instance($course->id);
     $compmanager = $this->getDataGenerator()->create_user();
     $compnoob = $this->getDataGenerator()->create_user();
     assign_capability('moodle/competency:coursecompetencyconfigure', CAP_ALLOW, $roleid, $context->id, true);
     assign_capability('moodle/competency:coursecompetencyview', CAP_ALLOW, $roleid, $context->id, true);
     assign_capability('moodle/competency:coursecompetencyview', CAP_ALLOW, $noobroleid, $context->id, true);
     role_assign($roleid, $compmanager->id, $context->id);
     role_assign($noobroleid, $compnoob->id, $context->id);
     $dg->enrol_user($compmanager->id, $course->id, $roleid);
     $dg->enrol_user($compnoob->id, $course->id, $noobroleid);
     $this->setUser($compmanager);
     // Start the test.
     $result = external::update_course_competency_settings($course->id, array('pushratingstouserplans' => true));
     $settings = course_competency_settings::get_by_courseid($course->id);
     $this->assertTrue((bool) $settings->get_pushratingstouserplans());
     $result = external::update_course_competency_settings($course->id, array('pushratingstouserplans' => false));
     $settings = course_competency_settings::get_by_courseid($course->id);
     $this->assertFalse((bool) $settings->get_pushratingstouserplans());
     $this->setUser($compnoob);
     $this->setExpectedException('required_capability_exception');
     $result = external::update_course_competency_settings($course->id, array('pushratingstouserplans' => true));
 }
예제 #2
0
 public function test_data_for_user_competency_summary_in_plan()
 {
     global $CFG;
     $this->setUser($this->creator);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $tpl = $lpg->create_template();
     $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $c1->get_id()));
     $plan = $lpg->create_plan(array('userid' => $this->user->id, 'templateid' => $tpl->get_id(), 'name' => 'Evil'));
     $uc = $lpg->create_user_competency(array('userid' => $this->user->id, 'competencyid' => $c1->get_id()));
     $evidence = \core_competency\external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 1, true);
     $evidence = \core_competency\external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 2, true);
     $summary = external::data_for_user_competency_summary_in_plan($c1->get_id(), $plan->get_id());
     $this->assertTrue($summary->usercompetencysummary->cangrade);
     $this->assertEquals('Evil', $summary->plan->name);
     $this->assertEquals('B', $summary->usercompetencysummary->usercompetency->gradename);
     $this->assertEquals('B', $summary->usercompetencysummary->evidence[0]->gradename);
     $this->assertEquals('A', $summary->usercompetencysummary->evidence[1]->gradename);
 }