Exemplo n.º 1
0
 /**
  * Receive transition by name or object
  *
  * @param string|Transition $transition
  * @return Transition
  * @throws InvalidTransitionException
  */
 public function extractTransition($transition)
 {
     $this->assertTransitionArgument($transition);
     if (is_string($transition)) {
         $transitionName = $transition;
         $transition = $this->getTransition($transitionName);
         if (!$transition) {
             throw InvalidTransitionException::unknownTransition($transitionName);
         }
     }
     return $transition;
 }
Exemplo n.º 2
0
 /**
  * Checks whether transition is valid in context of workflow item state.
  *
  * Transition is considered invalid when workflow item is new and transition is not "start".
  * Also transition is considered invalid when current step doesn't contain such allowed transition.
  *
  * @param Transition $transition
  * @param WorkflowItem $workflowItem
  * @param bool $fireExceptions
  * @return bool
  * @throws InvalidTransitionException
  */
 protected function checkTransitionValid(Transition $transition, WorkflowItem $workflowItem, $fireExceptions)
 {
     // get current step
     $currentStep = null;
     if ($workflowItem->getCurrentStep() && ($currentStepName = $workflowItem->getCurrentStep()->getName())) {
         $currentStep = $this->stepManager->getStep($currentStepName);
     }
     // if there is no current step - consider transition as a start transition
     if (!$currentStep) {
         if (!$transition->isStart()) {
             if ($fireExceptions) {
                 throw InvalidTransitionException::notStartTransition($workflowItem->getWorkflowName(), $transition->getName());
             }
             return false;
         }
     } elseif (!$currentStep->isAllowedTransition($transition->getName())) {
         // if transition is not allowed for current step
         if ($fireExceptions) {
             throw InvalidTransitionException::stepHasNoAllowedTransition($workflowItem->getWorkflowName(), $currentStep->getName(), $transition->getName());
         }
         return false;
     }
     return true;
 }
 public function isTransitionAllowedDataProvider()
 {
     return array('not_allowed_transition' => array('expectedResult' => false, 'transitionExist' => true, 'transitionAllowed' => false, 'isTransitionStart' => true, 'hasCurrentStep' => true, 'stepAllowTransition' => true), 'allowed_transition' => array('expectedResult' => true, 'transitionExist' => true, 'transitionAllowed' => true, 'isTransitionStart' => true, 'hasCurrentStep' => true, 'stepAllowTransition' => true), 'not_allowed_start_transition' => array('expectedResult' => false, 'transitionExist' => true, 'transitionAllowed' => false, 'isTransitionStart' => false, 'hasCurrentStep' => true, 'stepAllowTransition' => true), 'allowed_start_transition' => array('expectedResult' => true, 'transitionExist' => true, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => true, 'stepAllowTransition' => true), 'unknown_transition_fire_exception' => array('expectedException' => InvalidTransitionException::unknownTransition('test_transition'), 'transitionExist' => false, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => true, 'stepAllowTransition' => true), 'unknown_transition_no_exception' => array('expectedResult' => false, 'transitionExist' => false, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => true, 'stepAllowTransition' => true, 'fireException' => false), 'not_start_transition_fire_exception' => array('expectedException' => InvalidTransitionException::notStartTransition('test_workflow', 'test_transition'), 'transitionExist' => true, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => false, 'stepAllowTransition' => true), 'not_start_transition_no_exception' => array('expectedResult' => false, 'transitionExist' => true, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => false, 'stepAllowTransition' => true, 'fireException' => false), 'step_not_allow_transition_fire_exception' => array('expectedException' => InvalidTransitionException::stepHasNoAllowedTransition('test_workflow', 'test_step', 'test_transition'), 'transitionExist' => true, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => true, 'stepAllowTransition' => false), 'step_not_allow_transition_no_exception' => array('expectedResult' => false, 'transitionExist' => true, 'transitionAllowed' => true, 'isTransitionStart' => false, 'hasCurrentStep' => true, 'stepAllowTransition' => false, 'fireException' => false));
 }
 public function validateExceptionsDataProvider()
 {
     /** @var TransitionIsAllowed $constraint */
     $constraint = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Validator\\Constraints\\TransitionIsAllowed')->disableOriginalConstructor()->getMock();
     return array(array('workflowException' => InvalidTransitionException::unknownTransition('test_transition'), 'expectedViolations' => array(array($constraint->unknownTransitionMessage, array('{{ transition }}' => 'test_transition')))), array('workflowException' => InvalidTransitionException::notStartTransition('test_workflow', 'test_transition'), 'expectedViolations' => array(array($constraint->notStartTransitionMessage, array('{{ transition }}' => 'test_transition')))), array('workflowException' => InvalidTransitionException::stepHasNoAllowedTransition('test_workflow', 'test_step', 'test_transition'), 'expectedViolations' => array(array($constraint->stepHasNotAllowedTransitionMessage, array('{{ transition }}' => 'test_transition', '{{ step }}' => 'test_step')))), array('workflowException' => new InvalidTransitionException(), 'expectedViolations' => array($constraint->someConditionsNotMetMessage)));
 }