public function testIsTransitionAvailable()
 {
     $workflowName = 'test_workflow';
     $workflowItem = new WorkflowItem();
     $workflowItem->setWorkflowName($workflowName);
     $errors = new ArrayCollection();
     $transition = new Transition();
     $transition->setName('test_transition');
     $workflow = $this->createWorkflow($workflowName);
     $workflow->expects($this->once())->method('isTransitionAvailable')->with($workflowItem, $transition, $errors)->will($this->returnValue(true));
     $this->workflowRegistry->expects($this->once())->method('getWorkflow')->with($workflowName)->will($this->returnValue($workflow));
     $this->assertTrue($this->workflowManager->isTransitionAvailable($workflowItem, $transition, $errors));
 }
Ejemplo n.º 2
0
 public function testGetAllowedTransitions()
 {
     $firstTransition = new Transition();
     $firstTransition->setName('first_transition');
     $secondTransition = new Transition();
     $secondTransition->setName('second_transition');
     $step = new Step();
     $step->setName('test_step');
     $step->setAllowedTransitions(array($secondTransition->getName()));
     $workflow = $this->createWorkflow();
     $workflow->getStepManager()->setSteps(array($step));
     $workflow->getTransitionManager()->setTransitions(array($firstTransition, $secondTransition));
     $workflowItem = new WorkflowItem();
     $workflowItem->setCurrentStepName($step->getName());
     $actualTransitions = $workflow->getTransitionsByWorkflowItem($workflowItem);
     $this->assertEquals(array($secondTransition), $actualTransitions->getValues());
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider transitDisallowedDataProvider
  * @param bool $preConditionAllowed
  * @param bool $conditionAllowed
  * @expectedException \Oro\Bundle\WorkflowBundle\Exception\ForbiddenTransitionException
  * @expectedExceptionMessage Transition "test" is not allowed.
  */
 public function testTransitNotAllowed($preConditionAllowed, $conditionAllowed)
 {
     $workflowItem = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem')->disableOriginalConstructor()->getMock();
     $workflowItem->expects($this->never())->method('setCurrentStep');
     $preCondition = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\ConditionInterface');
     $preCondition->expects($this->any())->method('isAllowed')->with($workflowItem)->will($this->returnValue($preConditionAllowed));
     $condition = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\Condition\\ConditionInterface');
     $condition->expects($this->any())->method('isAllowed')->with($workflowItem)->will($this->returnValue($conditionAllowed));
     $postAction = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Model\\Action\\ActionInterface');
     $postAction->expects($this->never())->method('execute');
     $obj = new Transition();
     $obj->setName('test');
     $obj->setPreCondition($preCondition);
     $obj->setCondition($condition);
     $obj->setPostAction($postAction);
     $obj->transit($workflowItem);
 }
Ejemplo n.º 4
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;
 }