Пример #1
0
 public function test_import_framework()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $importer = new framework_importer(file_get_contents(__DIR__ . '/fixtures/example.csv'));
     $this->assertEquals('', $importer->get_error());
     $framework = $importer->import();
     $this->assertEmpty('', $importer->get_error());
     $this->assertGreaterThan(0, $framework->get_id());
     $filters = ['competencyframeworkid' => $framework->get_id()];
     $count = api::count_competencies($filters);
     $this->assertEquals(64, $count);
     // We can't test the exporter because it sends force-download headers.
 }
Пример #2
0
 /**
  * Test duplicate a framework.
  */
 public function test_duplicate_framework()
 {
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $syscontext = context_system::instance();
     $params = array('shortname' => 'shortname_a', 'idnumber' => 'idnumber_c', 'description' => 'description', 'descriptionformat' => FORMAT_HTML, 'visible' => true, 'contextid' => $syscontext->id);
     $framework = $lpg->create_framework($params);
     $competency1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $competency2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $competency3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $competency4 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $competency41 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $competency4->get_id()));
     $competency42 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $competency4->get_id()));
     $competencyidnumbers = array($competency1->get_idnumber(), $competency2->get_idnumber(), $competency3->get_idnumber(), $competency4->get_idnumber(), $competency41->get_idnumber(), $competency42->get_idnumber());
     $config = json_encode(array('base' => array('points' => 4), 'competencies' => array(array('id' => $competency41->get_id(), 'points' => 3, 'required' => 0), array('id' => $competency42->get_id(), 'points' => 2, 'required' => 1))));
     $competency4->set_ruletype('core_competency\\competency_rule_points');
     $competency4->set_ruleoutcome(\core_competency\competency::OUTCOME_EVIDENCE);
     $competency4->set_ruleconfig($config);
     $competency4->update();
     api::add_related_competency($competency1->get_id(), $competency2->get_id());
     api::add_related_competency($competency3->get_id(), $competency4->get_id());
     $frameworkduplicated1 = api::duplicate_framework($framework->get_id());
     $frameworkduplicated2 = api::duplicate_framework($framework->get_id());
     $this->assertEquals($framework->get_idnumber() . '_1', $frameworkduplicated1->get_idnumber());
     $this->assertEquals($framework->get_idnumber() . '_2', $frameworkduplicated2->get_idnumber());
     $competenciesfr1 = api::list_competencies(array('competencyframeworkid' => $frameworkduplicated1->get_id()));
     $competenciesfr2 = api::list_competencies(array('competencyframeworkid' => $frameworkduplicated2->get_id()));
     $competencyidsfr1 = array();
     $competencyidsfr2 = array();
     foreach ($competenciesfr1 as $cmp) {
         $competencyidsfr1[] = $cmp->get_idnumber();
     }
     foreach ($competenciesfr2 as $cmp) {
         $competencyidsfr2[] = $cmp->get_idnumber();
     }
     $this->assertEmpty(array_diff($competencyidsfr1, $competencyidnumbers));
     $this->assertEmpty(array_diff($competencyidsfr2, $competencyidnumbers));
     $this->assertCount(6, $competenciesfr1);
     $this->assertCount(6, $competenciesfr2);
     // Test the related competencies.
     reset($competenciesfr1);
     $compduplicated1 = current($competenciesfr1);
     $relatedcompetencies = $compduplicated1->get_related_competencies();
     $comprelated = current($relatedcompetencies);
     $this->assertEquals($comprelated->get_idnumber(), $competency2->get_idnumber());
     // Check if config rule have been ported correctly.
     $competency4duplicated = competency::get_record(array('idnumber' => $competency4->get_idnumber(), 'competencyframeworkid' => $frameworkduplicated2->get_id()));
     $configduplicated = json_decode($competency4duplicated->get_ruleconfig(), true);
     $configorigin = json_decode($config, true);
     // Check that the 2 config have the same base.
     $this->assertEquals($configorigin['base'], $configduplicated['base']);
     $this->assertEquals(count($configorigin['competencies']), count($configduplicated['competencies']));
     $competencyidsrules = array();
     foreach ($configduplicated['competencies'] as $key => $value) {
         // Check that the only difference between the 2 config is id competency.
         $this->assertEquals(1, count(array_diff($value, $configorigin['competencies'][$key])));
         $competencyidsrules[] = $value['id'];
     }
     $this->assertTrue($competency4duplicated->is_parent_of($competencyidsrules));
     // Test duplicate an empty framework.
     $emptyfrm = $lpg->create_framework();
     $emptyfrmduplicated = api::duplicate_framework($emptyfrm->get_id());
     $this->assertEquals($emptyfrm->get_idnumber() . '_1', $emptyfrmduplicated->get_idnumber());
     $nbcomp = api::count_competencies(array('competencyframeworkid' => $emptyfrmduplicated->get_id()));
     $this->assertEquals(0, $nbcomp);
 }
Пример #3
0
 /**
  * Count the existing competency frameworks.
  *
  * @param string $filters Filters to use.
  * @return boolean
  */
 public static function count_competencies($filters)
 {
     $params = self::validate_parameters(self::count_competencies_parameters(), array('filters' => $filters));
     $safefilters = array();
     $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid');
     foreach ($params['filters'] as $filter) {
         if (!in_array($filter['column'], $validcolumns)) {
             throw new invalid_parameter_exception('Filter column was invalid');
         }
         $safefilters[$filter['column']] = $filter['value'];
     }
     $context = null;
     if (isset($safefilters['competencyframeworkid'])) {
         $framework = api::read_framework($safefilters['competencyframeworkid']);
         $context = $framework->get_context();
     } else {
         $context = context_system::instance();
     }
     self::validate_context($context);
     return api::count_competencies($safefilters);
 }
 /**
  * Get other values that do not belong to the basic persisent.
  *
  * @param renderer_base $output
  * @return Array
  */
 protected function get_other_values(renderer_base $output)
 {
     $filters = array('competencyframeworkid' => $this->persistent->get_id());
     $context = $this->persistent->get_context();
     return array('canmanage' => has_capability('moodle/competency:competencymanage', $context), 'competenciescount' => api::count_competencies($filters), 'contextname' => $context->get_context_name(), 'contextnamenoprefix' => $context->get_context_name(false));
 }