[FEATURE] EXT:form - integrate new form framework
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Controller / FormFrontendControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Prophecy\Argument;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19 use TYPO3\CMS\Extbase\Object\ObjectManager;
20 use TYPO3\CMS\Form\Controller\FormFrontendController;
21 use TYPO3\CMS\Form\Domain\Configuration\ConfigurationService;
22 use TYPO3\CMS\Form\Mvc\Configuration\TypoScriptService;
23
24 /**
25 * Test case
26 */
27 class FormFrontendControllerTest extends UnitTestCase
28 {
29
30 /**
31 * @test
32 */
33 public function overrideByFlexFormSettingsReturnsNoOverriddenConfigurationIfFlexformOverridesDisabled()
34 {
35 $mockController = $this->getAccessibleMock(FormFrontendController::class, [
36 'dummy'
37 ], [], '', false);
38
39 $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
40
41 $objectManagerMock = $this->createMock(ObjectManager::class);
42 $objectManagerMock
43 ->expects($this->any())
44 ->method('get')
45 ->with(ConfigurationService::class)
46 ->willReturn($configurationServiceProphecy->reveal());
47
48 $mockController->_set('objectManager', $objectManagerMock);
49
50 $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
51 'finishersDefinition' => [
52 'EmailToReceiver' => [
53 'FormEngine' => [
54 'elements' => [
55 'subject' => [],
56 'recipientAddress' => [],
57 'format' => [],
58 ],
59 ],
60 ],
61 ],
62 ]);
63
64 $mockController->_set('settings', [
65 'overrideFinishers' => 0,
66 'finishers' => [
67 'EmailToReceiver' => [
68 'subject' => 'Mesage Subject overridden',
69 'recipientAddress' => 'your.company@example.com overridden',
70 'format' => 'html overridden',
71 ],
72 ],
73 ]);
74
75 $input = [
76 'identifier' => 'ext-form-identifier',
77 'prototypeName' => 'standard',
78 'finishers' => [
79 0 => [
80 'identifier' => 'EmailToReceiver',
81 'options' => [
82 'subject' => 'Mesage Subject',
83 'recipientAddress' => 'your.company@example.com',
84 'format' => 'html',
85 ],
86 ],
87 ],
88 ];
89
90 $expected = [
91 'identifier' => 'ext-form-identifier',
92 'prototypeName' => 'standard',
93 'finishers' => [
94 0 => [
95 'identifier' => 'EmailToReceiver',
96 'options' => [
97 'subject' => 'Mesage Subject',
98 'recipientAddress' => 'your.company@example.com',
99 'format' => 'html',
100 ],
101 ],
102 ],
103 ];
104
105 $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
106 }
107
108 /**
109 * @test
110 */
111 public function overrideByFlexFormSettingsReturnsOverriddenConfigurationIfFlexformOverridesEnabled()
112 {
113 $mockController = $this->getAccessibleMock(FormFrontendController::class, [
114 'dummy'
115 ], [], '', false);
116
117 $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
118
119 $objectManagerMock = $this->createMock(ObjectManager::class);
120 $objectManagerMock
121 ->expects($this->any())
122 ->method('get')
123 ->with(ConfigurationService::class)
124 ->willReturn($configurationServiceProphecy->reveal());
125
126 $mockController->_set('objectManager', $objectManagerMock);
127
128 $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
129 'finishersDefinition' => [
130 'EmailToReceiver' => [
131 'FormEngine' => [
132 'elements' => [
133 'subject' => [],
134 'recipientAddress' => [],
135 'format' => [],
136 ],
137 ],
138 ],
139 ],
140 ]);
141
142 $mockController->_set('settings', [
143 'overrideFinishers' => 1,
144 'finishers' => [
145 'EmailToReceiver' => [
146 'subject' => 'Mesage Subject overridden',
147 'recipientAddress' => 'your.company@example.com overridden',
148 'format' => 'html overridden',
149 ],
150 ],
151 ]);
152
153 $input = [
154 'identifier' => 'ext-form-identifier',
155 'prototypeName' => 'standard',
156 'finishers' => [
157 0 => [
158 'identifier' => 'EmailToReceiver',
159 'options' => [
160 'subject' => 'Mesage Subject',
161 'recipientAddress' => 'your.company@example.com',
162 'format' => 'html',
163 ],
164 ],
165 ],
166 ];
167
168 $expected = [
169 'identifier' => 'ext-form-identifier',
170 'prototypeName' => 'standard',
171 'finishers' => [
172 0 => [
173 'identifier' => 'EmailToReceiver',
174 'options' => [
175 'subject' => 'Mesage Subject overridden',
176 'recipientAddress' => 'your.company@example.com overridden',
177 'format' => 'html overridden',
178 ],
179 ],
180 ],
181 ];
182
183 $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
184 }
185
186 /**
187 * @test
188 */
189 public function overrideByFlexFormSettingsReturnsNotOverriddenConfigurationKeyIfFlexformOverridesAreNotRepresentedInFormEngineConfiguration()
190 {
191 $mockController = $this->getAccessibleMock(FormFrontendController::class, [
192 'dummy'
193 ], [], '', false);
194
195 $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
196
197 $objectManagerMock = $this->createMock(ObjectManager::class);
198 $objectManagerMock
199 ->expects($this->any())
200 ->method('get')
201 ->with(ConfigurationService::class)
202 ->willReturn($configurationServiceProphecy->reveal());
203
204 $mockController->_set('objectManager', $objectManagerMock);
205
206 $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
207 'finishersDefinition' => [
208 'EmailToReceiver' => [
209 'FormEngine' => [
210 'elements' => [
211 'subject' => [],
212 'recipientAddress' => [],
213 ],
214 ],
215 ],
216 ],
217 ]);
218
219 $mockController->_set('settings', [
220 'overrideFinishers' => 1,
221 'finishers' => [
222 'EmailToReceiver' => [
223 'subject' => 'Mesage Subject overridden',
224 'recipientAddress' => 'your.company@example.com overridden',
225 'format' => 'html overridden',
226 ],
227 ],
228 ]);
229
230 $input = [
231 'identifier' => 'ext-form-identifier',
232 'prototypeName' => 'standard',
233 'finishers' => [
234 0 => [
235 'identifier' => 'EmailToReceiver',
236 'options' => [
237 'subject' => 'Mesage Subject',
238 'recipientAddress' => 'your.company@example.com',
239 'format' => 'html',
240 ],
241 ],
242 ],
243 ];
244
245 $expected = [
246 'identifier' => 'ext-form-identifier',
247 'prototypeName' => 'standard',
248 'finishers' => [
249 0 => [
250 'identifier' => 'EmailToReceiver',
251 'options' => [
252 'subject' => 'Mesage Subject overridden',
253 'recipientAddress' => 'your.company@example.com overridden',
254 'format' => 'html',
255 ],
256 ],
257 ],
258 ];
259
260 $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
261 }
262
263 /**
264 * @test
265 */
266 public function overrideByTypoScriptSettingsReturnsNotOverriddenConfigurationIfNoTypoScriptOverridesExists()
267 {
268 $mockController = $this->getAccessibleMock(FormFrontendController::class, [
269 'dummy'
270 ], [], '', false);
271
272 $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
273
274 $objectManagerMock = $this->createMock(ObjectManager::class);
275 $objectManagerMock
276 ->expects($this->any())
277 ->method('get')
278 ->with(TypoScriptService::class)
279 ->willReturn($typoScriptServiceProphecy->reveal());
280
281 $mockController->_set('objectManager', $objectManagerMock);
282
283 $typoScriptServiceProphecy
284 ->resolvePossibleTypoScriptConfiguration(Argument::cetera())
285 ->willReturnArgument(0);
286
287 $mockController->_set('settings', [
288 'formDefinitionOverrides' => [
289 ],
290 ]);
291
292 $input = [
293 'identifier' => 'ext-form-identifier',
294 'prototypeName' => 'standard',
295 'label' => 'Label',
296 'renderables' => [
297 0 => [
298 'identifier' => 'page-1',
299 'type' => 'Page',
300 'label' => 'Label',
301 'renderables' => [
302 0 => [
303 'identifier' => 'text-1',
304 'type' => 'Text',
305 'label' => 'Label',
306 ],
307 ],
308 ],
309 ],
310 ];
311
312 $expected = [
313 'identifier' => 'ext-form-identifier',
314 'prototypeName' => 'standard',
315 'label' => 'Label',
316 'renderables' => [
317 0 => [
318 'identifier' => 'page-1',
319 'type' => 'Page',
320 'label' => 'Label',
321 'renderables' => [
322 0 => [
323 'identifier' => 'text-1',
324 'type' => 'Text',
325 'label' => 'Label',
326 ],
327 ],
328 ],
329 ],
330 ];
331
332 $this->assertSame($expected, $mockController->_call('overrideByTypoScriptSettings', $input));
333 }
334
335 /**
336 * @test
337 */
338 public function overrideByTypoScriptSettingsReturnsOverriddenConfigurationIfTypoScriptOverridesExists()
339 {
340 $mockController = $this->getAccessibleMock(FormFrontendController::class, [
341 'dummy'
342 ], [], '', false);
343
344 $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
345
346 $objectManagerMock = $this->createMock(ObjectManager::class);
347 $objectManagerMock
348 ->expects($this->any())
349 ->method('get')
350 ->with(TypoScriptService::class)
351 ->willReturn($typoScriptServiceProphecy->reveal());
352
353 $mockController->_set('objectManager', $objectManagerMock);
354
355 $typoScriptServiceProphecy
356 ->resolvePossibleTypoScriptConfiguration(Argument::cetera())
357 ->willReturnArgument(0);
358
359 $mockController->_set('settings', [
360 'formDefinitionOverrides' => [
361 'ext-form-identifier' => [
362 'label' => 'Label override',
363 'renderables' => [
364 0 => [
365 'renderables' => [
366 0 => [
367 'label' => 'Label override',
368 ],
369 ],
370 ],
371 ],
372 ],
373 ],
374 ]);
375
376 $input = [
377 'identifier' => 'ext-form-identifier',
378 'prototypeName' => 'standard',
379 'label' => 'Label',
380 'renderables' => [
381 0 => [
382 'identifier' => 'page-1',
383 'type' => 'Page',
384 'label' => 'Label',
385 'renderables' => [
386 0 => [
387 'identifier' => 'text-1',
388 'type' => 'Text',
389 'label' => 'Label',
390 ],
391 ],
392 ],
393 ],
394 ];
395
396 $expected = [
397 'identifier' => 'ext-form-identifier',
398 'prototypeName' => 'standard',
399 'label' => 'Label override',
400 'renderables' => [
401 0 => [
402 'identifier' => 'page-1',
403 'type' => 'Page',
404 'label' => 'Label',
405 'renderables' => [
406 0 => [
407 'identifier' => 'text-1',
408 'type' => 'Text',
409 'label' => 'Label override',
410 ],
411 ],
412 ],
413 ],
414 ];
415
416 $this->assertSame($expected, $mockController->_call('overrideByTypoScriptSettings', $input));
417 }
418 }