Ejemplo n.º 1
0
 public function test_rule_all_matching()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $u1 = $this->getDataGenerator()->create_user();
     // Set up the framework and competencies.
     $framework = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     $c11 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $c1->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     $c111 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $c11->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     $c112 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $c11->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     $c12 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $c1->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     $c13 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $c1->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     $c131 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $c13->get_id(), 'ruletype' => 'core_competency\\competency_rule_all'));
     // Create some user competency records.
     $uc1 = $lpg->create_user_competency(array('competencyid' => $c1->get_id(), 'userid' => $u1->id));
     $uc11 = $lpg->create_user_competency(array('competencyid' => $c11->get_id(), 'userid' => $u1->id, 'grade' => 1, 'proficiency' => 1));
     $uc111 = $lpg->create_user_competency(array('competencyid' => $c111->get_id(), 'userid' => $u1->id, 'grade' => 1, 'proficiency' => 1));
     $uc112 = $lpg->create_user_competency(array('competencyid' => $c112->get_id(), 'userid' => $u1->id, 'grade' => 1, 'proficiency' => 1));
     $uc12 = $lpg->create_user_competency(array('competencyid' => $c12->get_id(), 'userid' => $u1->id));
     $uc13 = new user_competency(0, (object) array('userid' => $u1->id, 'competencyid' => $c13->get_id()));
     // Not all children are met.
     $cr = new competency_rule_all($c1);
     $this->assertFalse($cr->matches($uc1));
     // All children are met.
     $cr = new competency_rule_all($c11);
     $this->assertTrue($cr->matches($uc11));
     // The competency doesn't have any children.
     $cr = new competency_rule_all($c12);
     $this->assertFalse($cr->matches($uc12));
     // The competency doesn't have saved user competency records.
     $cr = new competency_rule_all($c13);
     $this->assertFalse($cr->matches($uc13));
 }
Ejemplo n.º 2
0
 /**
  * Get the available rules.
  *
  * @return array Keys are the class names, values are the name of the rule.
  */
 public static function get_available_rules()
 {
     // Fully qualified class names without leading slashes because get_class() does not add them either.
     $rules = array('core_competency\\competency_rule_all' => competency_rule_all::get_name(), 'core_competency\\competency_rule_points' => competency_rule_points::get_name());
     return $rules;
 }