Пример #1
0
 public function itRaisesAnExceptionIfTargetFieldAlreadyHasRuleForSameValue()
 {
     $json = new stdClass();
     $json->target = new stdClass();
     $json->target->field_id = 34;
     $json->target->field_value_id = 75;
     $json->condition = Tracker_Workflow_Trigger_RulesBuilderData::CONDITION_ALL_OFF;
     $triggering_field = new stdClass();
     $triggering_field->field_id = 46;
     $triggering_field->field_value_id = 156;
     $triggering_field2 = new stdClass();
     $triggering_field2->field_id = 67;
     $triggering_field2->field_value_id = 62;
     $json->triggering_fields = array($triggering_field, $triggering_field2);
     $field_list = mock('Tracker_FormElement_Field_List');
     $bind_value = mock('Tracker_FormElement_Field_List_BindValue');
     stub($bind_value)->getId()->returns(75);
     $target = new Tracker_Workflow_Trigger_FieldValue($field_list, $bind_value);
     $condition = 'some_condition';
     $triggers = array();
     $rule = new Tracker_Workflow_Trigger_TriggerRule(7, $target, $condition, $triggers);
     $collection = new Tracker_Workflow_Trigger_TriggerRuleCollection();
     $collection->push($rule);
     $tracker = mock('Tracker');
     $this->expectException('Tracker_Workflow_Trigger_Exception_TriggerInvalidTargetException');
     $rules_manager = mock('Tracker_Workflow_Trigger_RulesManager');
     stub($rules_manager)->getForTargetTracker($tracker)->returns($collection);
     $validator = new Tracker_Workflow_Trigger_TriggerValidator($rules_manager);
     $validator->validateJsonFormat($json, $tracker);
 }
Пример #2
0
 /**
  * Get all rules that applies on a given tracker
  *
  * @param Tracker $tracker
  *
  * @return Tracker_Workflow_Trigger_TriggerRuleCollection
  */
 public function getForTargetTracker(Tracker $tracker)
 {
     $rules = new Tracker_Workflow_Trigger_TriggerRuleCollection();
     foreach ($this->dao->searchForTargetTracker($tracker->getId()) as $row) {
         $rules->push($this->getInstanceFromRow($row));
     }
     return $rules;
 }