function it_gets_current_step_for_started_workflow(Item $item, Workflow $workflow, Step $step)
 {
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn('start');
     $workflow->getStep('start')->willReturn($step);
     $this->getCurrentStep()->shouldReturn($step);
 }
 /**
  * Get role of current step.
  *
  * @param Transition $transition The transition being in.
  * @param Item       $item       The entity being transits.
  *
  * @return Permission|null
  */
 protected function getStepPermission(Transition $transition, Item $item)
 {
     $stepName = $item->getCurrentStepName();
     $step = $transition->getWorkflow()->getStep($stepName);
     $permission = $step->getPermission();
     return $permission;
 }
 /**
  * {@inheritdoc}
  */
 public function getCurrentStep()
 {
     if ($this->isWorkflowStarted()) {
         $stepName = $this->item->getCurrentStepName();
         return $this->workflow->getStep($stepName);
     }
     return null;
 }
 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);
 }
示例#5
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);
 }
示例#6
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');
 }