/** * * @param Tracker_Rule_List $rule * @return int The ID of the saved tracker_rule */ public function insert(Tracker_Rule_List $rule) { $rule_id = $this->da->escapeInt($rule->getTrackerId()); $rule_type = $this->da->quoteSmart(Tracker_Rule::RULETYPE_VALUE); $source_field_id = $this->da->escapeInt($rule->getSourceFieldId()); if ($rule->getSourceValue() instanceof Tracker_FormElement_Field_List_Value) { $source_value_id = $this->da->quoteSmart($rule->getSourceValue()->getId()); } else { $source_value_id = $this->da->quoteSmart($rule->getSourceValue()); } $target_field_id = $this->da->escapeInt($rule->getTargetFieldId()); if ($rule->getTargetValue() instanceof Tracker_FormElement_Field_List_Value) { $target_value_id = $this->da->quoteSmart($rule->getTargetValue()->getId()); } else { $target_value_id = $this->da->quoteSmart($rule->getTargetValue()); } $sql_insert_rule = "INSERT INTO tracker_rule (tracker_id, rule_type)\n VALUES ({$rule_id}, {$rule_type})"; $this->startTransaction(); try { $tracker_rule_id = $this->updateAndGetLastId($sql_insert_rule); $sql = "INSERT INTO tracker_rule_list (\n tracker_rule_id, \n source_field_id, \n source_value_id, \n target_field_id, \n target_value_id\n )\n VALUES (\n {$tracker_rule_id}, \n {$source_field_id}, \n {$source_value_id}, \n {$target_field_id}, \n {$target_value_id})"; $this->retrieve($sql); } catch (Exception $e) { $this->rollBack(); throw $e; } $this->commit(); return $tracker_rule_id; }
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 Tracker_Rule_List $list_rule * @param int $tracker_id * @param int $source_field_id * @param int $target_field_id * @param int $source_value * @param int $target_value * @return \Tracker_Rule_List */ private function populate(Tracker_Rule_List $list_rule, $tracker_id, $source_field_id, $target_field_id, $source_value, $target_value) { $list_rule->setTrackerId($tracker_id)->setSourceFieldId($source_field_id)->setTargetFieldId($target_field_id)->setSourceValue($source_value)->setTargetValue($target_value); return $list_rule; }
/** * * @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; }
private function setUpRuleList() { $rule = new Tracker_Rule_List(); $rule->setTrackerId($this->tracker_id)->setSourceFieldId($this->source_field_list_id)->setTargetFieldId($this->target_field_list_id)->setSourceValue('A')->setTargetValue('B'); return $rule; }
public function testGetTargetValueReturnsTargetIdSet() { $this->list_rule->setTargetValue(45); $this->assertEqual(45, $this->list_rule->getTargetValue()); }
/** * * @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; }