/** * Check if the current user can reach the next state given by the name * @param ModelInterface $model * @param $stateName * @throws WorkflowException * @return boolean */ public function canReachNextState(ModelInterface $model, $stateName) { $currentModelState = $this->storage->findCurrentModelState($model, $this->process->getName()); if (!$currentModelState instanceof ModelState) { throw new WorkflowException(sprintf('The given model has not started the "%s" process.', $this->process->getName())); } $currentStep = $this->getProcessStep($currentModelState->getStepName()); if (!$currentStep->hasNextState($stateName)) { throw new WorkflowException(sprintf('The step "%s" does not contain any next state named "%s".', $currentStep->getName(), $stateName)); } $state = $currentStep->getNextState($stateName); $step = $state->getTarget($model); return $this->canReachStep($model, $step); }
public function testExecutePreValidations() { // reset fake calls FakeProcessListener::$call = 0; $model = new FakeModel(); $this->modelStorage->newModelStateSuccess($model, 'document_proccess', 'step_create_doc'); $modelState = $this->getProcessHandler()->reachNextState($model, 'validate_with_pre_validation'); $this->assertTrue($modelState->getSuccessful()); $this->assertEquals('step_validate_doc', $modelState->getStepName()); $this->assertEquals(0, FakeProcessListener::$call); $model = new FakeModel(); $this->modelStorage->newModelStateSuccess($model, 'document_proccess', 'step_create_doc'); $modelState = $this->getProcessHandler()->reachNextState($model, 'validate_with_pre_validation_invalid'); $this->assertFalse($modelState->getSuccessful()); $this->assertEquals(array('Validation error!'), $modelState->getErrors()); $this->assertEquals(1, FakeProcessListener::$call); }