Exemplo n.º 1
0
 function testCanApplyTo()
 {
     $trv = new Tracker_Rule_List();
     $trv->setSourceValue('source_value')->setTargetValue('target_value')->setId('id')->setTrackerId('tracker_id')->setSourceFieldId('source_field')->setTargetFieldId('target_field');
     $this->assertTrue($trv->canApplyTo('tracker_id', 'source_field', 'source_value', 'target_field', 'target_value'));
     $this->assertTrue($trv->canApplyTo('tracker_id', 'source_field', 'source_value', 'target_field', 'false_target_value'));
     //$this->assertFalse($trv->canApplyTo('false_tracker_id', 'source_field',        'source_value',       'target_field',       'target_value'      ));
     //$this->assertFalse($trv->canApplyTo('false_tracker_id', 'source_field',        'source_value',       'target_field',       'false_target_value'));
     $this->assertFalse($trv->canApplyTo('tracker_id', 'target_source_field', 'source_value', 'target_field', 'false_value'));
     $this->assertFalse($trv->canApplyTo('tracker_id', 'target_source_field', 'source_value', 'target_field', 'false_target_value'));
     $this->assertFalse($trv->canApplyTo('tracker_id', 'source_field', 'false_source_value', 'target_field', 'false_value'));
     $this->assertFalse($trv->canApplyTo('tracker_id', 'source_field', 'false_source_value', 'target_field', 'false_target_value'));
     $this->assertFalse($trv->canApplyTo('tracker_id', 'source_field', 'source_value', 'false_target_field', 'false_value'));
     $this->assertFalse($trv->canApplyTo('tracker_id', 'source_field', 'source_value', 'false_target_field', 'false_target_value'));
 }
    public function testImportListRules()
    {
        $xmlstr = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
    <rules>
    </rules>
XML;
        $xml = new SimpleXMLElement($xmlstr);
        $list_rules = $xml->addChild('list_rules');
        $rule1 = $list_rules->addChild('rule');
        $rule1->addChild('source_field')->addAttribute('REF', 'F28');
        $rule1->addChild('target_field')->addAttribute('REF', 'F25');
        $rule1->addChild('source_value')->addAttribute('REF', 'F28-V1');
        $rule1->addChild('target_value')->addAttribute('REF', 'F25-V3');
        $rule2 = $list_rules->addChild('rule');
        $rule2->addChild('source_field')->addAttribute('REF', 'F28');
        $rule2->addChild('target_field')->addAttribute('REF', 'F25');
        $rule2->addChild('source_value')->addAttribute('REF', 'F28-V1');
        $rule2->addChild('target_value')->addAttribute('REF', 'F25-V4');
        $tracker = aTracker()->withId(666)->build();
        $f1 = stub('Tracker_FormElement_Field_List')->getId()->returns(102);
        $f2 = stub('Tracker_FormElement_Field_List')->getId()->returns(103);
        $f3 = stub('Tracker_FormElement_Field_List')->getId()->returns(104);
        $f4 = stub('Tracker_FormElement_Field_List')->getId()->returns(105);
        $f5 = stub('Tracker_FormElement_Field_List')->getId()->returns(106);
        $array_xml_mapping = array('F25' => $f1, 'F28' => $f2, 'F25-V3' => $f4, 'F25-V4' => $f5, 'F28-V1' => $f3);
        $tracker_rule_dao = mock('Tracker_RuleDao');
        $rule_factory = new Tracker_RuleFactory($tracker_rule_dao);
        $rules = $rule_factory->getInstanceFromXML($xml, $array_xml_mapping, $tracker);
        $list_rule_expected = new Tracker_Rule_List();
        $list_rule_expected->setSourceValue($array_xml_mapping['F28-V1'])->setTargetValue($array_xml_mapping['F25-V3'])->setId(0)->setTrackerId($tracker->getId())->setSourceField($array_xml_mapping['F28'])->setTargetField($array_xml_mapping['F25']);
        $list_rule_expected2 = new Tracker_Rule_List();
        $list_rule_expected2->setSourceValue($array_xml_mapping['F28-V1'])->setTargetValue($array_xml_mapping['F25-V4'])->setId(0)->setTrackerId($tracker->getId())->setSourceField($array_xml_mapping['F28'])->setTargetField($array_xml_mapping['F25']);
        $this->assertEqual(count($rules['list_rules']), 2);
        $this->assertEqual($rules['list_rules'][0], $list_rule_expected);
        $this->assertEqual($rules['list_rules'][1], $list_rule_expected2);
    }
 /**
  * 
  * @param SimpleXMLElement $xml         containing the structure of the imported semantic
  * @param array            $xmlMapping containig the newly created formElements idexed by their XML IDs
  * @param Tracker          $tracker     to which the rule is attached
  * @return array of Tracker_Rule_List
  */
 private function generateListRulesArrayFromXml($list_rules, &$xmlMapping, $tracker)
 {
     $rules = array();
     foreach ($list_rules->rule as $xml_rule) {
         $xml_source_field_attributes = $xml_rule->source_field->attributes();
         $source_field = $xmlMapping[(string) $xml_source_field_attributes['REF']];
         $xml_target_field_attributes = $xml_rule->target_field->attributes();
         $target_field = $xmlMapping[(string) $xml_target_field_attributes['REF']];
         $xml_source_value_attributes = $xml_rule->source_value->attributes();
         if (isset($xml_source_value_attributes['is_none'])) {
             $source_value = new Tracker_FormElement_Field_List_Bind_StaticValue_None();
         } else {
             $source_value = $xmlMapping[(string) $xml_source_value_attributes['REF']];
         }
         $xml_target_value_attributes = $xml_rule->target_value->attributes();
         if (isset($xml_target_value_attributes['is_none'])) {
             $target_value = new Tracker_FormElement_Field_List_Bind_StaticValue_None();
         } else {
             $target_value = $xmlMapping[(string) $xml_target_value_attributes['REF']];
         }
         $rule_list = new Tracker_Rule_List();
         $rule_list->setSourceValue($source_value)->setTargetValue($target_value)->setTrackerId($tracker->getId())->setSourceField($source_field)->setTargetField($target_field);
         $rules[] = $rule_list;
     }
     return $rules;
 }
 public function testValidateListRulesReturnsTrueWhenOneRuleOnlyIsValidForAGivenSetting()
 {
     $value_field_list = array(123 => 456, 789 => 586);
     $rule1 = new Tracker_Rule_List();
     $rule1->setSourceValue(456)->setTargetValue(586)->setSourceFieldId(123)->setTargetFieldId(789)->setTrackerId(19)->setId(5);
     //same rule with different target value
     $rule2 = new Tracker_Rule_List();
     $rule2->setSourceValue(456)->setTargetValue(54654)->setSourceFieldId(123)->setTargetFieldId(789)->setTrackerId(19)->setId(11);
     $tracker = mock('Tracker');
     stub($tracker)->getId()->returns(19);
     $form_element_factory = mock('Tracker_FormElementFactory');
     $source_field = mock('Tracker_FormElement_Field_List_OpenValue');
     stub($source_field)->getLabel()->returns('aaaaa');
     stub($form_element_factory)->getFormElementById()->returns($source_field);
     $tracker_rules_manager = partial_mock('Tracker_RulesManager', array('getAllListRulesByTrackerWithOrder', 'getAllDateRulesByTrackerId', 'getSelectedValuesForField'), array($tracker, $form_element_factory));
     stub($tracker_rules_manager)->getSelectedValuesForField()->returns(array());
     $tracker_rules_manager->setReturnValue('getAllDateRulesByTrackerId', array());
     $tracker_rules_manager->setReturnValue('getAllListRulesByTrackerWithOrder', array($rule1, $rule2));
     $this->assertTrue($tracker_rules_manager->validate($tracker->getId(), $value_field_list));
 }
Exemplo n.º 5
0
 public function testSetTargetValueReturnsModelObject()
 {
     $set = $this->list_rule->setSourceValue(123);
     $this->assertEqual($this->list_rule, $set);
 }
Exemplo n.º 6
0
 /**
  * 
  * @param SimpleXMLElement $xml         containing the structure of the imported semantic
  * @param array            $xmlMapping containig the newly created formElements idexed by their XML IDs
  * @param Tracker          $tracker     to which the rule is attached
  * @return array of Tracker_Rule_List
  */
 private function generateListRulesArrayFromXml($list_rules, &$xmlMapping, $tracker)
 {
     $rules = array();
     foreach ($list_rules->rule as $xml_rule) {
         $xml_source_field_attributes = $xml_rule->source_field->attributes();
         $source_field = $xmlMapping[(string) $xml_source_field_attributes['REF']];
         $xml_target_field_attributes = $xml_rule->target_field->attributes();
         $target_field = $xmlMapping[(string) $xml_target_field_attributes['REF']];
         $xml_source_value_attributes = $xml_rule->source_value->attributes();
         $source_value = $xmlMapping[(string) $xml_source_value_attributes['REF']];
         $xml_target_value_attributes = $xml_rule->target_value->attributes();
         $target_value = $xmlMapping[(string) $xml_target_value_attributes['REF']];
         $rule_list = new Tracker_Rule_List();
         $rule_list->setSourceValue($source_value)->setTargetValue($target_value)->setTrackerId($tracker->getId())->setSourceField($source_field)->setTargetField($target_field);
         $rules[] = $rule_list;
     }
     return $rules;
 }