1 | <?php |
||
20 | class IndexActionTest extends AbstractGeneratorControllerTest |
||
21 | { |
||
22 | /** |
||
23 | * @expectedException \RuntimeException |
||
24 | * @expectedExceptionMessage Session is mandatory when using the character generator. |
||
25 | */ |
||
26 | public function test index needs session() |
||
27 | { |
||
28 | $controller = $this->createController(); |
||
29 | $request = new Request(); |
||
30 | |||
31 | $controller->indexAction($request); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
36 | * @expectedExceptionMessage No step found to start the generator. |
||
37 | */ |
||
38 | public function test index with no configuration returns 404() |
||
39 | { |
||
40 | $stepsResolver = new StepResolver(['manager' => ['steps' => []]]); |
||
41 | |||
42 | $controller = $this->createController($stepsResolver); |
||
43 | $request = $this->createRequest(); |
||
44 | |||
45 | $controller->indexAction($request); |
||
46 | } |
||
47 | |||
48 | public function test index with no step in session redirects to first step() |
||
49 | { |
||
50 | $resolver = new StepResolver([ |
||
51 | 'manager_one' => $this->createManagerConfiguration('manager_one'), |
||
52 | ]); |
||
53 | |||
54 | $router = $this->createMock(RouterInterface::class); |
||
55 | $router->expects(self::once()) |
||
56 | ->method('generate') |
||
57 | ->with('pierstoval_character_generator_step', ['requestStep' => '01']) |
||
58 | ->willReturn('/generate/01') |
||
59 | ; |
||
60 | |||
61 | $controller = $this->createController($resolver, $router); |
||
62 | $request = $this->createRequest(); |
||
63 | |||
64 | $response = $controller->indexAction($request); |
||
65 | |||
66 | static::assertInstanceOf(RedirectResponse::class, $response); |
||
67 | static::assertSame('/generate/01', $response->headers->get('Location')); |
||
68 | } |
||
69 | |||
70 | public function test index with manager in session redirects to first step with manager name() |
||
71 | { |
||
72 | $resolver = new StepResolver([ |
||
73 | 'manager_one' => $this->createManagerConfiguration('manager_one'), |
||
74 | ]); |
||
75 | |||
76 | $router = $this->createMock(RouterInterface::class); |
||
77 | $router->expects(self::once()) |
||
78 | ->method('generate') |
||
79 | ->with('pierstoval_character_generator_step', ['requestStep' => '01', 'manager' => 'manager_one']) |
||
80 | ->willReturn('/generate/manager_one/01') |
||
81 | ; |
||
82 | |||
83 | $controller = $this->createController($resolver, $router); |
||
84 | $request = $this->createRequest(); |
||
85 | |||
86 | $response = $controller->indexAction($request, 'manager_one'); |
||
87 | |||
88 | static::assertInstanceOf(RedirectResponse::class, $response); |
||
89 | static::assertSame('/generate/manager_one/01', $response->headers->get('Location')); |
||
90 | } |
||
91 | |||
92 | } |
||
93 |