1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace spec\FSi\Bundle\AdminBundle\Controller; |
11
|
|
|
|
12
|
|
|
use FSi\Bundle\AdminBundle\Event\AdminEvents; |
13
|
|
|
use PhpSpec\ObjectBehavior; |
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
|
16
|
|
|
class FormControllerSpec extends ObjectBehavior |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\Context\ContextManager $manager |
20
|
|
|
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating |
21
|
|
|
*/ |
22
|
|
|
function let($manager, $templating, $dispatcher) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$this->beConstructedWith( |
25
|
|
|
$templating, |
26
|
|
|
$manager, |
27
|
|
|
'default_form' |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher |
33
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
34
|
|
|
* @param \Symfony\Component\HttpFoundation\Response $response |
35
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\GenericFormElement $element |
36
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\Context\ContextManager $manager |
37
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\Context\FormElementContext $context |
38
|
|
|
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating |
39
|
|
|
*/ |
40
|
|
|
function it_dispatch_event_if_displatcher_present( |
41
|
|
|
$dispatcher, |
42
|
|
|
$request, |
43
|
|
|
$response, |
44
|
|
|
$element, |
45
|
|
|
$manager, |
46
|
|
|
$context, |
47
|
|
|
$templating |
48
|
|
|
) { |
49
|
|
|
$this->setEventDispatcher($dispatcher); |
50
|
|
|
|
51
|
|
|
$dispatcher->dispatch( |
52
|
|
|
AdminEvents::CONTEXT_PRE_CREATE, |
53
|
|
|
Argument::type('FSi\Bundle\AdminBundle\Event\AdminEvent') |
54
|
|
|
)->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$manager->createContext('fsi_admin_form', $element)->willReturn($context); |
57
|
|
|
$context->handleRequest($request)->willReturn(null); |
58
|
|
|
$context->hasTemplateName()->willReturn(false); |
59
|
|
|
$context->getData()->willReturn(array()); |
60
|
|
|
|
61
|
|
|
$templating->renderResponse('default_form', array(), null)->willReturn($response); |
62
|
|
|
$this->formAction($element, $request)->shouldReturn($response); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\GenericFormElement $element |
67
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\Context\ContextManager $manager |
68
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
69
|
|
|
*/ |
70
|
|
|
function it_throw_exception_when_cant_find_context_builder_that_supports_admin_element( |
71
|
|
|
$element, |
72
|
|
|
$manager, |
73
|
|
|
$request |
74
|
|
|
) { |
75
|
|
|
$element->getId()->willReturn('admin_element_id'); |
76
|
|
|
$manager->createContext(Argument::type('string'), $element)->shouldBeCalled()->willReturn(null); |
77
|
|
|
|
78
|
|
|
$this->shouldThrow('Symfony\Component\HttpKernel\Exception\NotFoundHttpException') |
79
|
|
|
->during('formAction', array($element, $request)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
84
|
|
|
* @param \Symfony\Component\HttpFoundation\Response $response |
85
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\GenericFormElement $element |
86
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\Context\ContextManager $manager |
87
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\Context\FormElementContext $context |
88
|
|
|
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating |
89
|
|
|
*/ |
90
|
|
|
function it_render_default_template_in_form_action( |
91
|
|
|
$request, |
92
|
|
|
$response, |
93
|
|
|
$element, |
94
|
|
|
$manager, |
95
|
|
|
$context, |
96
|
|
|
$templating |
97
|
|
|
) { |
98
|
|
|
$manager->createContext('fsi_admin_form', $element)->willReturn($context); |
99
|
|
|
$context->handleRequest($request)->willReturn(null); |
100
|
|
|
$context->hasTemplateName()->willReturn(false); |
101
|
|
|
$context->getData()->willReturn(array()); |
102
|
|
|
|
103
|
|
|
$templating->renderResponse('default_form', array(), null)->willReturn($response); |
104
|
|
|
$this->formAction($element, $request)->shouldReturn($response); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\Context\ContextManager $manager |
109
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\GenericFormElement $element |
110
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\Context\FormElementContext $context |
111
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
112
|
|
|
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating |
113
|
|
|
* @param \Symfony\Component\HttpFoundation\Response $response |
114
|
|
|
*/ |
115
|
|
|
function it_render_template_from_element_in_form_action( |
116
|
|
|
$manager, |
117
|
|
|
$element, |
118
|
|
|
$context, |
119
|
|
|
$request, |
120
|
|
|
$templating, |
121
|
|
|
$response |
122
|
|
|
) { |
123
|
|
|
$manager->createContext('fsi_admin_form', $element)->willReturn($context); |
124
|
|
|
$context->handleRequest($request)->willReturn(null); |
125
|
|
|
$context->hasTemplateName()->willReturn(true); |
126
|
|
|
$context->getTemplateName()->willReturn('custom_template'); |
127
|
|
|
$context->getData()->willReturn(array()); |
128
|
|
|
|
129
|
|
|
$templating->renderResponse('custom_template', array(), null)->willReturn($response); |
130
|
|
|
$this->formAction($element, $request)->shouldReturn($response); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\Context\ContextManager $manager |
135
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\GenericFormElement $element |
136
|
|
|
* @param \FSi\Bundle\AdminBundle\Admin\CRUD\Context\FormElementContext $context |
137
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
138
|
|
|
* @param \Symfony\Component\HttpFoundation\Response $response |
139
|
|
|
*/ |
140
|
|
|
function it_return_response_from_context_in_form_action( |
141
|
|
|
$manager, |
142
|
|
|
$element, |
143
|
|
|
$context, |
144
|
|
|
$request, |
145
|
|
|
$response |
146
|
|
|
) { |
147
|
|
|
$manager->createContext('fsi_admin_form', $element)->willReturn($context); |
148
|
|
|
$context->handleRequest($request)->willReturn($response); |
149
|
|
|
|
150
|
|
|
$this->formAction($element, $request)->shouldReturn($response); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.