Skip to content

Commit

Permalink
Merge pull request #13 from pluess/next-step
Browse files Browse the repository at this point in the history
Fixed wrong variable name and added test cases to cover the bug.
  • Loading branch information
Paweł Jędrzejewski committed Dec 12, 2012
2 parents d5e7bbb + 490f2c7 commit d65638c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Process/Coordinator/Coordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function processStepResult(ProcessInterface $process, $result)
if ($result instanceof ActionResult) {
// Handle explicit jump to step.
if ($result->getNextStepName()) {
$this->context->setNextStepByName($response->getNextStepName());
$this->context->setNextStepByName($result->getNextStepName());

return $this->redirectToStepDisplayAction($process, $this->context->getNextStep());
}
Expand Down
111 changes: 107 additions & 4 deletions Tests/Process/Coordinator/CoordinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,50 @@ public function shouldNotShowForwardWhenProcessIsNotValid()
$this->coordinator->forward('scenarioOne', 'someStepName');
}

/**
* @test
* @expectedException RuntimeException
*/
public function shouldNotShowFormWhenForwardReturnsUnexpectedType()
{
$router = $this->getRouter();

$processBuilder = $this->getProcessBuilder($this->getProcess());

$processContext = $this->getProcessContext();
$processContext->expects($this->any())
->method('isValid')
->will($this->returnValue(true));

$this->coordinator = $this->createCoordinator($router, $processBuilder, $processContext);
$this->coordinator->registerScenario('scenarioOne', $this->getMock('Sylius\Bundle\FlowBundle\Process\Scenario\ProcessScenarioInterface'));

$result = $this->coordinator->forward('scenarioOne', 'unexpectedTypeStep');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $result);
}

/**
* @test
* @expectedException RuntimeException
*/
public function shouldShowFormWhenForwardReturnsUnexpectedType()
{
$router = $this->getRouter();

$processBuilder = $this->getProcessBuilder($this->getProcess());

$processContext = $this->getProcessContext();
$processContext->expects($this->any())
->method('isValid')
->will($this->returnValue(true));

$this->coordinator = $this->createCoordinator($router, $processBuilder, $processContext);
$this->coordinator->registerScenario('scenarioOne', $this->getMock('Sylius\Bundle\FlowBundle\Process\Scenario\ProcessScenarioInterface'));

$result = $this->coordinator->forward('scenarioOne', 'unexpectedTypeStep');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $result);
}

/**
* @test
* @covers Sylius\Bundle\FlowBundle\Process\Coordinator\Coordinator::forward
Expand Down Expand Up @@ -277,6 +321,45 @@ public function shouldRedirectToNextStepDisplayActionWhenStepIsCompleted()
$this->assertEquals('http://someurl.dev/step/scenarioOne/nextStepName', $response->getTargetUrl());
}

/**
* @test
* @covers Sylius\Bundle\FlowBundle\Process\Coordinator\Coordinator::forward
*/
public function shouldRedirectToNextStepDisplayActionWhenStepProceeds()
{
$router = $this->getRouter(
'sylius_flow_display',
array(
'scenarioAlias' => 'scenarioOne',
'stepName' => 'nextStepName'
),
'http://someurl.dev/step/scenarioOne/nextStepName'
);

$processBuilder = $this->getProcessBuilder($this->getProcess());

$processContext = $this->getProcessContext();
$processContext->expects($this->any())
->method('isValid')
->will($this->returnValue(true));
$processContext->expects($this->any())
->method('getNextStep')
->will($this->returnValue(
$this->getStep('nextStepName')
));
$processContext->expects($this->any())
->method('getStepHistory')
->will($this->returnValue(array()));

$this->coordinator = $this->createCoordinator($router, $processBuilder, $processContext);
$this->coordinator->registerScenario('scenarioOne', $this->getMock('Sylius\Bundle\FlowBundle\Process\Scenario\ProcessScenarioInterface'));

$response = $this->coordinator->forward('scenarioOne', 'goToNextStep');

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
$this->assertEquals('http://someurl.dev/step/scenarioOne/nextStepName', $response->getTargetUrl());
}

/**
* @test
* @covers Sylius\Bundle\FlowBundle\Process\Coordinator\Coordinator::forward
Expand Down Expand Up @@ -365,6 +448,8 @@ private function getProcess()
array(
array('someStepName', $this->getStep('someStepName')),
array('notForwardStep', $this->getStep('notForwardStep')),
array('unexpectedTypeStep', $this->getStep('unexpectedTypeStep')),
array('goToNextStep', $this->getStep('goToNextStep')),
)
));
$process->expects($this->any())
Expand All @@ -389,10 +474,28 @@ private function getStep($name)
$step->expects($this->any())
->method('displayAction')
->will($this->returnValue(new Response()));
$step->expects($this->any())
->method('forwardAction')
->will($this->returnValue($name=='notForwardStep' ? new Response() : new ActionResult()));

switch($name) {
case 'notForwardStep':
$step->expects($this->any())
->method('forwardAction')
->will($this->returnValue(new Response()));
break;
case 'unexpectedTypeStep':
$step->expects($this->any())
->method('forwardAction')
->will($this->returnValue("dummy"));
break;
case 'goToNextStep':
$step->expects($this->any())
->method('forwardAction')
->will($this->returnValue(new ActionResult('someStepName')));
break;
default:
$step->expects($this->any())
->method('forwardAction')
->will($this->returnValue(new ActionResult()));
}
return $step;
}

}

0 comments on commit d65638c

Please sign in to comment.