public function testImportDateRules() { $xmlstr = <<<XML <?xml version="1.0" encoding="UTF-8"?> <rules> </rules> XML; $xml = new SimpleXMLElement($xmlstr); $date_rules = $xml->addChild('date_rules'); $rule1 = $date_rules->addChild('rule'); $rule1->addChild('source_field')->addAttribute('REF', 'F28'); $rule1->addChild('target_field')->addAttribute('REF', 'F25'); $rule1->addChild('comparator')->addAttribute('type', Tracker_rule_date::COMPARATOR_NOT_EQUALS); $rule2 = $date_rules->addChild('rule'); $rule2->addChild('source_field')->addAttribute('REF', 'F29'); $rule2->addChild('target_field')->addAttribute('REF', 'F30'); $rule2->addChild('comparator')->addAttribute('type', Tracker_rule_date::COMPARATOR_LESS_THAN_OR_EQUALS); $tracker = mock('Tracker'); stub($tracker)->getId()->returns(900); $f1 = stub('Tracker_FormElement_Field_Date')->getId()->returns(102); $f2 = stub('Tracker_FormElement_Field_Date')->getId()->returns(103); $f3 = stub('Tracker_FormElement_Field_Date')->getId()->returns(104); $f4 = stub('Tracker_FormElement_Field_Date')->getId()->returns(105); $array_xml_mapping = array('F25' => $f3, 'F28' => $f1, 'F29' => $f2, 'F30' => $f4); $tracker_rule_dao = mock('Tracker_RuleDao'); $rule_factory = new Tracker_RuleFactory($tracker_rule_dao); $rules = $rule_factory->getInstanceFromXML($xml, $array_xml_mapping, $tracker); $date_rule_expected = new Tracker_Rule_Date(); $date_rule_expected->setComparator(Tracker_rule_date::COMPARATOR_NOT_EQUALS)->setTrackerId($tracker->getId())->setSourceField($array_xml_mapping['F28'])->setTargetField($array_xml_mapping['F25']); $date_rule_expected2 = new Tracker_Rule_Date(); $date_rule_expected2->setComparator(Tracker_rule_date::COMPARATOR_LESS_THAN_OR_EQUALS)->setTrackerId($tracker->getId())->setSourceField($array_xml_mapping['F29'])->setTargetField($array_xml_mapping['F30']); $this->assertEqual(count($rules['date_rules']), 2); $this->assertEqual($rules['date_rules'][0], $date_rule_expected); $this->assertEqual($rules['date_rules'][1], $date_rule_expected2); }
private function setUpRule($id, $source_field, $comparator, $target_field) { $rule = new Tracker_Rule_Date(); $rule->setId($id); $rule->setSourceField($source_field); $rule->setComparator($comparator); $rule->setTargetField($target_field); return $rule; }
/** @return bool */ private function validateDateRuleOnSubmittedFields(Tracker_Rule_Date $rule, array $value_field_list) { $source_value = $value_field_list[$rule->getSourceFieldId()]; $target_value = $value_field_list[$rule->getTargetFieldId()]; return $rule->validate($source_value, $target_value); }
/** * * @param Tracker_Rule_Date $date_rule * @param int $tracker_id * @param int $source_field_id * @param int $target_field_id * @param string $comparator * @return \Tracker_Rule_Date */ private function populate(Tracker_Rule_Date $date_rule, $tracker_id, $source_field_id, $target_field_id, $comparator, $id = null) { $source_field = $this->element_factory->getFormElementById($source_field_id); $target_field = $this->element_factory->getFormElementById($target_field_id); $date_rule->setTrackerId($tracker_id)->setSourceFieldId($source_field_id)->setSourceField($source_field)->setTargetFieldId($target_field_id)->setTargetField($target_field)->setTrackerId($tracker_id)->setComparator($comparator); if ($date_rule !== null) { $date_rule->setId($id); } return $date_rule; }
public function testValidateReturnsFalseForSameDateAndTimestamp() { $date_rule = new Tracker_Rule_Date(); $date_rule->setComparator(Tracker_Rule_Date::COMPARATOR_NOT_EQUALS); $source_value = strtotime('2012-11-15 14:58'); $target_value = '2012-11-15'; $this->assertFalse($date_rule->validate($source_value, $target_value)); }
/** * * @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_Date */ private function generateDateRulesArrayFromXml($date_rules, &$xmlMapping, $tracker) { $rules = array(); foreach ($date_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_comparator_attributes = $xml_rule->comparator->attributes(); $comparator = $xml_comparator_attributes['type']; $rule_list = new Tracker_Rule_Date(); $rule_list->setComparator($comparator)->setTrackerId($tracker->getId())->setSourceField($source_field)->setTargetField($target_field); $rules[] = $rule_list; } return $rules; }
public function setUp() { parent::setUp(); $tracker = stub('Tracker')->getId()->returns($this->tracker_id); $this->rules_manager = partial_mock('Tracker_RulesManager', array('getAllListRulesByTrackerWithOrder', 'getAllDateRulesByTrackerId'), array($tracker, mock('Tracker_FormElementFactory'))); $date_rule1 = new Tracker_Rule_Date(); $date_rule2 = new Tracker_Rule_Date(); $date_field_1 = mock('Tracker_FormElement_Field_Date'); stub($date_field_1)->getId()->returns(1); stub($date_field_1)->isCompatibleWithSoap()->returns(true); $date_field_2 = mock('Tracker_FormElement_Field_Date'); stub($date_field_2)->getId()->returns(2); stub($date_field_2)->isCompatibleWithSoap()->returns(true); $date_field_3 = mock('Tracker_FormElement_Field_Date'); stub($date_field_3)->getId()->returns(3); stub($date_field_3)->isCompatibleWithSoap()->returns(true); $date_field_4 = mock('Tracker_FormElement_Field_Date'); stub($date_field_4)->getId()->returns(4); stub($date_field_4)->isCompatibleWithSoap()->returns(true); $date_rule1->setSourceFieldId(1)->setTargetFieldId(2)->setSourceField($date_field_1)->setTargetField($date_field_2)->setComparator('<'); $date_rule2->setSourceFieldId(3)->setTargetFieldId(4)->setSourceField($date_field_3)->setTargetField($date_field_4)->setComparator('='); $this->dates = array($date_rule1, $date_rule2); $this->lists = array(new Tracker_Rule_List(1, $this->tracker_id, 15, 16, 17, 18), new Tracker_Rule_List(2, $this->tracker_id, 25, 26, 27, 28)); }
public function itDelegatesSaveToDao() { $id = 20; $rule = new Tracker_Rule_Date(); $rule->setId($id); $rule->setSourceField($this->source_field); $rule->setComparator('>'); $rule->setTargetField($this->target_field); stub($this->date_rule_dao)->save($id, $this->source_field_id, $this->target_field_id, '>')->once()->returns(true); $success = $this->date_rule_factory->save($rule); $this->assertTrue($success); }