function it_creates_the_repository_based_transition_handler(Item $item, Workflow $workflow, StateRepository $stateRepository, EntityManager $entityManager, EntityRepository $entityRepository, Listener $listener)
 {
     $entityManager->getRepository('test')->willReturn($entityRepository);
     $item->isWorkflowStarted()->willReturn(false);
     $item->getEntity()->willReturn(static::$entity);
     $this->setListener($listener);
     $this->createTransitionHandler($item, $workflow, null, 'test', $stateRepository)->shouldHaveType('Netzmacht\\Workflow\\Handler\\RepositoryBasedTransitionHandler');
 }
 function it_does_not_match_if_step_role_is_not_granted(Transition $transition, Item $item, Context $context, User $user, Permission $permission, ErrorCollection $errorCollection)
 {
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn('step');
     $permission->__toString()->willReturn('workflow/permission');
     $user->hasPermission($permission)->willReturn(false);
     $errorCollection->addError(Argument::cetera())->shouldBeCalled();
     $this->match($transition, $item, $context, $errorCollection)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public function match(Transition $transition, Item $item, Context $context, ErrorCollection $errorCollection)
 {
     // workflow is not started, so no start step exists
     if (!$item->isWorkflowStarted()) {
         if ($this->allowStartTransition) {
             return true;
         }
         $errorCollection->addError('transition.condition.step.failed.not-started');
         return false;
     }
     $permission = $this->getStepPermission($transition, $item);
     if ($this->checkPermission($permission)) {
         return true;
     }
     $errorCollection->addError('transition.condition.step.failed', array($item->getCurrentStepName(), $permission ? (string) $permission : '-'));
     return false;
 }
Example #4
0
 /**
  * Guard that already started workflow is the same which is tried to be ran now.
  *
  * @param Item     $item     Current workflow item.
  * @param Workflow $workflow Selected workflow.
  *
  * @throws WorkflowException If item workflow is not the same as current workflow.
  *
  * @return void
  */
 private function guardSameWorkflow(Item $item, Workflow $workflow)
 {
     if ($item->isWorkflowStarted() && $item->getWorkflowName() != $workflow->getName()) {
         $message = sprintf('Item "%s" already process workflow "%s" and cannot be handled by "%s"', $item->getEntityId(), $item->getWorkflowName(), $workflow->getName());
         throw new WorkflowException($message);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function isWorkflowStarted()
 {
     return $this->item->isWorkflowStarted();
 }
Example #6
0
 /**
  * Check if a specific transition is available.
  *
  * @param Item            $item            The workflow item.
  * @param Context         $context         Transition context.
  * @param ErrorCollection $errorCollection Error collection.
  * @param string          $transitionName  The transition name.
  *
  * @return bool
  */
 public function isTransitionAvailable(Item $item, Context $context, ErrorCollection $errorCollection, $transitionName)
 {
     if (!$item->isWorkflowStarted()) {
         return $this->getStartTransition()->getName() === $transitionName;
     }
     $step = $this->getStep($item->getCurrentStepName());
     if (!$step->isTransitionAllowed($transitionName)) {
         return false;
     }
     $transition = $this->getTransition($transitionName);
     return $transition->isAvailable($item, $context, $errorCollection);
 }
 function it_checks_if_workflow_is_started(Item $item)
 {
     $item->isWorkflowStarted()->willReturn(true);
     $this->isWorkflowStarted()->shouldReturn(true);
 }
Example #8
0
 function it_knows_if_transition_is_available_for_an_item(Item $item, Step $step, Context $context, Transition $transition, ErrorCollection $errorCollection)
 {
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn('started');
     $transition->getName()->willReturn('next');
     $transition->isAvailable($item, $context, $errorCollection)->shouldBeCalled()->willReturn(true);
     $this->addTransition($transition);
     $step->getName()->willReturn('started');
     $step->isTransitionAllowed('next')->willReturn(true);
     $this->addStep($step);
     $this->isTransitionAvailable($item, $context, $errorCollection, 'next')->shouldReturn(true);
 }
 function it_throws_than_matches_workflow_is_not_same_as_current(Workflow $workflow, Item $item, EntityId $entityId, Transition $transition, Step $step)
 {
     $step->getName()->willReturn('start');
     $step->isTransitionAllowed('next')->willReturn(true);
     $item->getEntityId()->willReturn($entityId);
     $item->getEntity()->willReturn(static::$entity);
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn('start');
     $item->getWorkflowName()->willReturn('workflow_a');
     $workflow->match($entityId, static::$entity)->willReturn(true);
     $workflow->getStep('start')->willReturn($step);
     $workflow->getTransition('next')->willReturn($transition);
     $workflow->getName()->willReturn('workflow_b');
     $entityId->getProviderName()->willReturn(static::ENTITY_PROVIDER_NAME);
     $entityId->__toString()->willReturn(static::ENTITY_PROVIDER_NAME . '::' . static::ENTITY_ID);
     $this->shouldThrow('Netzmacht\\Workflow\\Flow\\Exception\\WorkflowException')->duringHandle($item, 'next');
 }