TYPO3 CMS  TYPO3_8-7
FormFrontendControllerTest.php
Go to the documentation of this file.
1 <?php
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 
22 
26 class FormFrontendControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
28 
33  {
34  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
35  'dummy'
36  ], [], '', false);
37 
38  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
39 
40  $objectManagerMock = $this->createMock(ObjectManager::class);
41  $objectManagerMock
42  ->expects($this->any())
43  ->method('get')
44  ->with(ConfigurationService::class)
45  ->willReturn($configurationServiceProphecy->reveal());
46 
47  $mockController->_set('objectManager', $objectManagerMock);
48 
49  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
50  'finishersDefinition' => [
51  'EmailToReceiver' => [
52  'FormEngine' => [
53  'elements' => [
54  'subject' => [],
55  'recipientAddress' => [],
56  'format' => [],
57  ],
58  ],
59  ],
60  ],
61  ]);
62 
63  $mockController->_set('settings', [
64  'overrideFinishers' => 0,
65  'finishers' => [
66  'EmailToReceiver' => [
67  'subject' => 'Mesage Subject overridden',
68  'recipientAddress' => 'your.company@example.com overridden',
69  'format' => 'html overridden',
70  ],
71  ],
72  ]);
73 
74  $input = [
75  'identifier' => 'ext-form-identifier',
76  'prototypeName' => 'standard',
77  'finishers' => [
78  0 => [
79  'identifier' => 'EmailToReceiver',
80  'options' => [
81  'subject' => 'Mesage Subject',
82  'recipientAddress' => 'your.company@example.com',
83  'format' => 'html',
84  ],
85  ],
86  ],
87  ];
88 
89  $expected = [
90  'identifier' => 'ext-form-identifier',
91  'prototypeName' => 'standard',
92  'finishers' => [
93  0 => [
94  'identifier' => 'EmailToReceiver',
95  'options' => [
96  'subject' => 'Mesage Subject',
97  'recipientAddress' => 'your.company@example.com',
98  'format' => 'html',
99  ],
100  ],
101  ],
102  ];
103 
104  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
105  }
106 
111  {
112  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
113  'dummy'
114  ], [], '', false);
115 
116  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
117 
118  $objectManagerMock = $this->createMock(ObjectManager::class);
119  $objectManagerMock
120  ->expects($this->any())
121  ->method('get')
122  ->with(ConfigurationService::class)
123  ->willReturn($configurationServiceProphecy->reveal());
124 
125  $mockController->_set('objectManager', $objectManagerMock);
126 
127  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
128  'finishersDefinition' => [
129  'EmailToReceiver' => [
130  'FormEngine' => [
131  'elements' => [
132  'subject' => [],
133  'recipientAddress' => [],
134  'format' => [],
135  ],
136  ],
137  ],
138  ],
139  ]);
140 
141  $mockController->_set('settings', [
142  'overrideFinishers' => 1,
143  'finishers' => [
144  'EmailToReceiver' => [
145  'subject' => 'Mesage Subject overridden',
146  'recipientAddress' => 'your.company@example.com overridden',
147  'format' => 'html overridden',
148  ],
149  ],
150  ]);
151 
152  $input = [
153  'identifier' => 'ext-form-identifier',
154  'prototypeName' => 'standard',
155  'finishers' => [
156  0 => [
157  'identifier' => 'EmailToReceiver',
158  'options' => [
159  'subject' => 'Mesage Subject',
160  'recipientAddress' => 'your.company@example.com',
161  'format' => 'html',
162  ],
163  ],
164  ],
165  ];
166 
167  $expected = [
168  'identifier' => 'ext-form-identifier',
169  'prototypeName' => 'standard',
170  'finishers' => [
171  0 => [
172  'identifier' => 'EmailToReceiver',
173  'options' => [
174  'subject' => 'Mesage Subject overridden',
175  'recipientAddress' => 'your.company@example.com overridden',
176  'format' => 'html overridden',
177  ],
178  ],
179  ],
180  ];
181 
182  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
183  }
184 
189  {
190  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
191  'dummy'
192  ], [], '', false);
193 
194  $configurationServiceProphecy = $this->prophesize(ConfigurationService::class);
195 
196  $objectManagerMock = $this->createMock(ObjectManager::class);
197  $objectManagerMock
198  ->expects($this->any())
199  ->method('get')
200  ->with(ConfigurationService::class)
201  ->willReturn($configurationServiceProphecy->reveal());
202 
203  $mockController->_set('objectManager', $objectManagerMock);
204 
205  $configurationServiceProphecy->getPrototypeConfiguration(Argument::cetera())->willReturn([
206  'finishersDefinition' => [
207  'EmailToReceiver' => [
208  'FormEngine' => [
209  'elements' => [
210  'subject' => [],
211  'recipientAddress' => [],
212  ],
213  ],
214  ],
215  ],
216  ]);
217 
218  $mockController->_set('settings', [
219  'overrideFinishers' => 1,
220  'finishers' => [
221  'EmailToReceiver' => [
222  'subject' => 'Mesage Subject overridden',
223  'recipientAddress' => 'your.company@example.com overridden',
224  'format' => 'html overridden',
225  ],
226  ],
227  ]);
228 
229  $input = [
230  'identifier' => 'ext-form-identifier',
231  'prototypeName' => 'standard',
232  'finishers' => [
233  0 => [
234  'identifier' => 'EmailToReceiver',
235  'options' => [
236  'subject' => 'Mesage Subject',
237  'recipientAddress' => 'your.company@example.com',
238  'format' => 'html',
239  ],
240  ],
241  ],
242  ];
243 
244  $expected = [
245  'identifier' => 'ext-form-identifier',
246  'prototypeName' => 'standard',
247  'finishers' => [
248  0 => [
249  'identifier' => 'EmailToReceiver',
250  'options' => [
251  'subject' => 'Mesage Subject overridden',
252  'recipientAddress' => 'your.company@example.com overridden',
253  'format' => 'html',
254  ],
255  ],
256  ],
257  ];
258 
259  $this->assertSame($expected, $mockController->_call('overrideByFlexFormSettings', $input));
260  }
261 
266  {
267  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
268  'dummy'
269  ], [], '', false);
270 
271  $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
272 
273  $objectManagerMock = $this->createMock(ObjectManager::class);
274  $objectManagerMock
275  ->expects($this->any())
276  ->method('get')
277  ->with(TypoScriptService::class)
278  ->willReturn($typoScriptServiceProphecy->reveal());
279 
280  $mockController->_set('objectManager', $objectManagerMock);
281 
282  $typoScriptServiceProphecy
283  ->resolvePossibleTypoScriptConfiguration(Argument::cetera())
284  ->willReturnArgument(0);
285 
286  $mockController->_set('settings', [
287  'formDefinitionOverrides' => [
288  ],
289  ]);
290 
291  $input = [
292  'identifier' => 'ext-form-identifier',
293  'prototypeName' => 'standard',
294  'label' => 'Label',
295  'renderables' => [
296  0 => [
297  'identifier' => 'page-1',
298  'type' => 'Page',
299  'label' => 'Label',
300  'renderables' => [
301  0 => [
302  'identifier' => 'text-1',
303  'type' => 'Text',
304  'label' => 'Label',
305  ],
306  ],
307  ],
308  ],
309  ];
310 
311  $expected = [
312  'identifier' => 'ext-form-identifier',
313  'prototypeName' => 'standard',
314  'label' => 'Label',
315  'renderables' => [
316  0 => [
317  'identifier' => 'page-1',
318  'type' => 'Page',
319  'label' => 'Label',
320  'renderables' => [
321  0 => [
322  'identifier' => 'text-1',
323  'type' => 'Text',
324  'label' => 'Label',
325  ],
326  ],
327  ],
328  ],
329  ];
330 
331  $this->assertSame($expected, $mockController->_call('overrideByTypoScriptSettings', $input));
332  }
333 
338  {
339  $mockController = $this->getAccessibleMock(FormFrontendController::class, [
340  'dummy'
341  ], [], '', false);
342 
343  $typoScriptServiceProphecy = $this->prophesize(TypoScriptService::class);
344 
345  $objectManagerMock = $this->createMock(ObjectManager::class);
346  $objectManagerMock
347  ->expects($this->any())
348  ->method('get')
349  ->with(TypoScriptService::class)
350  ->willReturn($typoScriptServiceProphecy->reveal());
351 
352  $mockController->_set('objectManager', $objectManagerMock);
353 
354  $typoScriptServiceProphecy
355  ->resolvePossibleTypoScriptConfiguration(Argument::cetera())
356  ->willReturnArgument(0);
357 
358  $mockController->_set('settings', [
359  'formDefinitionOverrides' => [
360  'ext-form-identifier' => [
361  'label' => 'Label override',
362  'renderables' => [
363  0 => [
364  'renderables' => [
365  0 => [
366  'label' => 'Label override',
367  ],
368  ],
369  ],
370  ],
371  ],
372  ],
373  ]);
374 
375  $input = [
376  'identifier' => 'ext-form-identifier',
377  'prototypeName' => 'standard',
378  'label' => 'Label',
379  'renderables' => [
380  0 => [
381  'identifier' => 'page-1',
382  'type' => 'Page',
383  'label' => 'Label',
384  'renderables' => [
385  0 => [
386  'identifier' => 'text-1',
387  'type' => 'Text',
388  'label' => 'Label',
389  ],
390  ],
391  ],
392  ],
393  ];
394 
395  $expected = [
396  'identifier' => 'ext-form-identifier',
397  'prototypeName' => 'standard',
398  'label' => 'Label override',
399  'renderables' => [
400  0 => [
401  'identifier' => 'page-1',
402  'type' => 'Page',
403  'label' => 'Label',
404  'renderables' => [
405  0 => [
406  'identifier' => 'text-1',
407  'type' => 'Text',
408  'label' => 'Label override',
409  ],
410  ],
411  ],
412  ],
413  ];
414 
415  $this->assertSame($expected, $mockController->_call('overrideByTypoScriptSettings', $input));
416  }
417 }