示例#1
0
 /**
  * @dataProvider transitDataProvider
  * @param boolean $isFinal
  * @param boolean $hasAllowedTransition
  */
 public function testTransit($isFinal, $hasAllowedTransition)
 {
     $currentStepEntity = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowStep')->disableOriginalConstructor()->getMock();
     $step = $this->getStepMock('currentStep', $isFinal, $hasAllowedTransition, $currentStepEntity);
     $workflowDefinition = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowDefinition')->disableOriginalConstructor()->getMock();
     $workflowDefinition->expects($this->once())->method('getStepByName')->with($step->getName())->will($this->returnValue($currentStepEntity));
     $workflowItem = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem')->disableOriginalConstructor()->getMock();
     $workflowItem->expects($this->once())->method('getDefinition')->will($this->returnValue($workflowDefinition));
     $workflowItem->expects($this->once())->method('setCurrentStep')->with($currentStepEntity);
     $preCondition = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\ConditionInterface');
     $preCondition->expects($this->once())->method('isAllowed')->with($workflowItem)->will($this->returnValue(true));
     $condition = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\ConditionInterface');
     $condition->expects($this->once())->method('isAllowed')->with($workflowItem)->will($this->returnValue(true));
     $postAction = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\Action\\ActionInterface');
     $postAction->expects($this->once())->method('execute')->with($workflowItem);
     $obj = new Transition();
     $obj->setPreCondition($preCondition);
     $obj->setCondition($condition);
     $obj->setPostAction($postAction);
     $obj->setStepTo($step);
     $obj->transit($workflowItem);
 }
示例#2
0
 /**
  * @param string $name
  * @param array $options
  * @param array $definition
  * @param Step[]|ArrayCollection $steps
  * @param Attribute[]|Collection $attributes
  * @return Transition
  * @throws AssemblerException
  */
 protected function assembleTransition($name, array $options, array $definition, $steps, $attributes)
 {
     $this->assertOptions($options, array('step_to', 'label'));
     $stepToName = $options['step_to'];
     if (empty($steps[$stepToName])) {
         throw new AssemblerException(sprintf('Step "%s" not found', $stepToName));
     }
     $transition = new Transition();
     $transition->setName($name)->setLabel($options['label'])->setStepTo($steps[$stepToName])->setMessage($this->getOption($options, 'message'))->setStart($this->getOption($options, 'is_start', false))->setHidden($this->getOption($options, 'is_hidden', false))->setUnavailableHidden($this->getOption($options, 'is_unavailable_hidden', false))->setFormType($this->getOption($options, 'form_type', WorkflowTransitionType::NAME))->setFormOptions($this->assembleFormOptions($options, $attributes, $name))->setFrontendOptions($this->getOption($options, 'frontend_options', array()))->setDisplayType($this->getOption($options, 'display_type', WorkflowConfiguration::DEFAULT_TRANSITION_DISPLAY_TYPE))->setPageTemplate($this->getOption($options, 'page_template'))->setDialogTemplate($this->getOption($options, 'dialog_template'));
     $definition['pre_conditions'] = $this->addAclPreConditions($options, $definition);
     if (!empty($definition['pre_conditions'])) {
         $condition = $this->conditionFactory->create(ConfigurableCondition::ALIAS, $definition['pre_conditions']);
         $transition->setPreCondition($condition);
     }
     if (!empty($definition['conditions'])) {
         $condition = $this->conditionFactory->create(ConfigurableCondition::ALIAS, $definition['conditions']);
         $transition->setCondition($condition);
     }
     if (!empty($definition['post_actions'])) {
         $postAction = $this->actionFactory->create(ConfigurableAction::ALIAS, $definition['post_actions']);
         $transition->setPostAction($postAction);
     }
     return $transition;
 }