Esempio n. 1
0
 public function test_delete_framework()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $this->setAdminUser();
     $u1 = $dg->create_user();
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2id = $c2->get_id();
     $c1a = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1->get_id()));
     $c1b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1a->get_id()));
     $c11b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1b->get_id()));
     $c12b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1b->get_id()));
     // If we delete framework, the related competencies relations and evidences should be deleted.
     // Create related competencies using one of c1a competency descendants.
     $rc = $lpg->create_related_competency(array('competencyid' => $c2->get_id(), 'relatedcompetencyid' => $c11b->get_id()));
     $this->assertEquals($c11b->get_id(), $rc->get_relatedcompetencyid());
     // Creating a standard evidence with minimal information.
     $uc2 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c11b->get_id()));
     $evidence = $lpg->create_evidence(array('usercompetencyid' => $uc2->get_id()));
     $this->assertEquals($uc2->get_id(), $evidence->get_usercompetencyid());
     $uc2->delete();
     $this->assertTrue(api::delete_framework($f1->get_id()));
     $this->assertFalse(competency_framework::record_exists($f1->get_id()));
     // Check that all competencies were also deleted.
     $this->assertFalse(competency::record_exists($c1->get_id()));
     $this->assertFalse(competency::record_exists($c2->get_id()));
     $this->assertFalse(competency::record_exists($c1a->get_id()));
     $this->assertFalse(competency::record_exists($c1b->get_id()));
     $this->assertFalse(competency::record_exists($c11b->get_id()));
     $this->assertFalse(competency::record_exists($c12b->get_id()));
     // Check if evidence are also deleted.
     $this->assertEquals(0, \core_competency\user_evidence_competency::count_records(array('competencyid' => $c11b->get_id())));
     // Check if related conpetency relation is deleted.
     $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
     // Delete a simple framework.
     $f2 = $lpg->create_framework();
     $this->assertTrue(api::delete_framework($f2->get_id()));
     $this->assertFalse(competency_framework::record_exists($f2->get_id()));
 }
Esempio n. 2
0
 /**
  * Validate the competency framework ID.
  *
  * @param int $value The framework ID.
  * @return true|lang_string
  */
 protected function validate_competencyframeworkid($value)
 {
     // During update.
     if ($this->get_id()) {
         // Ensure that we are not trying to move the competency across frameworks.
         if ($this->beforeupdate->get_competencyframeworkid() != $value) {
             return new lang_string('invaliddata', 'error');
         }
     } else {
         // During create.
         // Check that the framework exists.
         if (!competency_framework::record_exists($value)) {
             return new lang_string('invaliddata', 'error');
         }
     }
     return true;
 }