‪TYPO3CMS  11.5
RequestHandlingTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
22 
24 {
25  protected string ‪$databaseScenarioFile = __DIR__ . '/Fixtures/OnePageWithMultipleFormIntegrationsScenario.yaml';
27 
28  protected function ‪setUp(): void
29  {
30  parent::setUp();
31  $this->formDataFactory = new ‪FormDataFactory();
32  }
33 
35  {
36  yield 'Multistep form / ext:form content element' => [
37  'formIdentifier' => 'multistep-test-form-1001',
38  'formNamePrefix' => 'tx_form_formframework',
39  ];
40 
41  yield 'Multistep form / custom extbase controller => RenderActionIsCached' => [
42  'formIdentifier' => 'RenderActionIsCached-1002',
43  'formNamePrefix' => 'tx_formcachingtests_renderactioniscached',
44  ];
45 
46  yield 'Multistep form / custom extbase controller => AllActionsUncached' => [
47  'formIdentifier' => 'AllActionsUncached-1003',
48  'formNamePrefix' => 'tx_formcachingtests_allactionsuncached',
49  ];
50 
51  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
52  // yield 'Multistep form / custom extbase controller => AllActionsCached' => [
53  // 'formIdentifier' => 'AllActionsCached-1004',
54  // 'formNamePrefix' => 'tx_formcachingtests_allactionscached',
55  // ];
56 
57  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
58  // yield 'Multistep form / simple FLUIDTEMPLATE' => [
59  // 'formIdentifier' => 'FormFromSimpleFluidtemplate',
60  // 'formNamePrefix' => 'tx_form_formframework',
61  // ];
62 
63  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
64  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => AllActionsCached' => [
65  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerAllActionsCached',
66  // 'formNamePrefix' => 'tx_formcachingtests_allactionscached',
67  // ];
68 
69  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => AllActionsCached' => [
70  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerAllActionsCached',
71  'formNamePrefix' => 'tx_formcachingtests_allactionscached',
72  ];
73 
74  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
75  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => RenderActionIsCached' => [
76  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerRenderActionIsCached',
77  // 'formNamePrefix' => 'tx_formcachingtests_renderactioniscached',
78  // ];
79 
80  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => RenderActionIsCached' => [
81  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerRenderActionIsCached',
82  'formNamePrefix' => 'tx_formcachingtests_renderactioniscached',
83  ];
84 
85  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
86  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => AllActionsUncached' => [
87  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerAllActionsUncached',
88  // 'formNamePrefix' => 'tx_formcachingtests_allactionsuncached',
89  // ];
90 
91  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => AllActionsUncached' => [
92  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerAllActionsUncached',
93  'formNamePrefix' => 'tx_formcachingtests_allactionsuncached',
94  ];
95 
96  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
97  // yield 'Multistep form / COA FLUIDTEMPLATE through ext:form controller' => [
98  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughExtFormController',
99  // 'formNamePrefix' => 'tx_form_formframework',
100  // ];
101 
102  yield 'Multistep form / COA_INT FLUIDTEMPLATE through ext:form controller' => [
103  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughExtFormController',
104  'formNamePrefix' => 'tx_form_formframework',
105  ];
106  }
107 
112  public function ‪theCachingBehavesTheSameForAllFormIntegrationVariants(string $formIdentifier, string $formNamePrefix): void
113  {
114  $uri = static::ROOT_PAGE_BASE_URI . '/form';
115 
116  // goto form page
117  $pageMarkup = (string)$this->executeFrontendSubRequest(new InternalRequest($uri), null, true)->getBody();
118  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
119 
120  $honeypotIdFromStep1 = $formData->getHoneypotId();
121  $sessionIdFromStep1 = $formData->getSessionId();
122 
123  self::assertEmpty($sessionIdFromStep1, 'session element is not rendered');
124  self::assertEmpty($formData->toArray()['elementData'][$formNamePrefix . '[' . $formIdentifier . '][text-1]']['value'] ?? '_notempty_', 'form element "text-1" is empty');
125  self::assertNotEmpty($honeypotIdFromStep1, 'honeypot element exists');
126 
127  // post data and go to summary page
128  $formPostRequest = $formData->with('text-1', 'FOObarBAZ')->toPostRequest(new InternalRequest($uri));
129  $pageMarkup = (string)$this->executeFrontendSubRequest($formPostRequest, null, true)->getBody();
130  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
131 
132  $honeypotIdFromStep2 = $formData->getHoneypotId();
133  $sessionIdFromStep2 = $formData->getSessionId();
134  $formMarkup = $formData->getFormMarkup();
135 
136  self::assertStringContainsString('Summary step', $formMarkup, 'the summary form step is shown');
137  self::assertStringContainsString('FOObarBAZ', $formMarkup, 'data from "text-1" is shown');
138  self::assertNotEmpty($sessionIdFromStep2, 'session element is rendered');
139  self::assertEmpty($honeypotIdFromStep2, 'honeypot element does not exists on summary form step');
140 
141  // go back to first page
142  $formPostRequest = $formData->with('__currentPage', '0')->toPostRequest(new InternalRequest($uri));
143  $pageMarkup = (string)$this->executeFrontendSubRequest($formPostRequest, null, true)->getBody();
144  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
145 
146  $honeypotIdFromStep3 = $formData->getHoneypotId();
147  $sessionIdFromStep3 = $formData->getSessionId();
148 
149  self::assertEquals('FOObarBAZ', $formData->toArray()['elementData'][$formNamePrefix . '[' . $formIdentifier . '][text-1]']['value'] ?? null, 'form element "text-1" contains submitted data');
150  self::assertNotEquals($honeypotIdFromStep3, $honeypotIdFromStep1, 'honeypot differs from historical honeypot');
151  self::assertEquals($sessionIdFromStep3, $sessionIdFromStep2, 'session is still available');
152 
153  // post data and go to summary page
154  $formPostRequest = $formData->with('text-1', 'BAZbarFOO')->toPostRequest(new InternalRequest($uri));
155  $pageMarkup = (string)$this->executeFrontendSubRequest($formPostRequest, null, true)->getBody();
156  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
157 
158  $honeypotIdFromStep4 = $formData->getHoneypotId();
159  $sessionIdFromStep4 = $formData->getSessionId();
160  $formMarkup = $formData->getFormMarkup();
161 
162  self::assertStringContainsString('Summary step', $formMarkup, 'the summary form step is shown');
163  self::assertStringContainsString('BAZbarFOO', $formMarkup, 'data from "text-1" is shown');
164  self::assertEmpty($honeypotIdFromStep4, 'honeypot element does not exists on summary form step');
165  self::assertEquals($sessionIdFromStep4, $sessionIdFromStep3, 'session is still available');
166 
167  // submit and trigger finishers
168  $formPostRequest = $formData->toPostRequest(new InternalRequest($uri));
169  $pageMarkup = (string)$this->executeFrontendSubRequest($formPostRequest, null, true)->getBody();
170  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//*[@id="' . $formIdentifier . '"]');
171 
172  $formMarkup = $formData->getFormMarkup();
173  $mails = $this->‪getMailSpoolMessages();
174 
175  self::assertStringContainsString('Form is submitted', $formMarkup, 'the finisher text is shown');
176  self::assertCount(1, $this->‪getMailSpoolMessages(), 'a mail is sent');
177  self::assertStringContainsString('Text: BAZbarFOO', $mails[0]['plaintext'] ?? '', 'Mail contains form data');
178  }
179 
181  {
182  yield 'Multistep form / ext:form content element' => [
183  'formIdentifier' => 'multistep-test-form-1001',
184  ];
185 
186  yield 'Multistep form / custom extbase controller => RenderActionIsCached' => [
187  'formIdentifier' => 'RenderActionIsCached-1002',
188  ];
189 
190  yield 'Multistep form / custom extbase controller => AllActionsUncached' => [
191  'formIdentifier' => 'AllActionsUncached-1003',
192  ];
193 
194  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
195  // yield 'Multistep form / custom extbase controller => AllActionsCached' => [
196  // 'formIdentifier' => 'AllActionsCached-1004',
197  // ];
198 
199  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
200  // yield 'Multistep form / simple FLUIDTEMPLATE' => [
201  // 'formIdentifier' => 'FormFromSimpleFluidtemplate',
202  // ];
203 
204  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
205  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => AllActionsCached' => [
206  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerAllActionsCached',
207  // ];
208 
209  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => AllActionsCached' => [
210  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerAllActionsCached',
211  ];
212 
213  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
214  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => RenderActionIsCached' => [
215  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerRenderActionIsCached',
216  // ];
217 
218  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => RenderActionIsCached' => [
219  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerRenderActionIsCached',
220  ];
221 
222  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
223  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => AllActionsUncached' => [
224  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerAllActionsUncached',
225  // ];
226 
227  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => AllActionsUncached' => [
228  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerAllActionsUncached',
229  ];
230 
231  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/70460 is fixed
232  // yield 'Multistep form / COA FLUIDTEMPLATE through ext:form controller' => [
233  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughExtFormController',
234  // ];
235 
236  yield 'Multistep form / COA_INT FLUIDTEMPLATE through ext:form controller' => [
237  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughExtFormController',
238  ];
239  }
240 
245  public function ‪formRendersUncachedIfTheActionTargetIsCalledViaHttpGet(string $formIdentifier): void
246  {
247  $uri = static::ROOT_PAGE_BASE_URI . '/form';
248 
249  // goto form page
250  $pageMarkup = (string)$this->executeFrontendSubRequest(new InternalRequest($uri), null, true)->getBody();
251  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
252 
253  // goto form target with HTTP GET
254  $pageMarkup = (string)$this->executeFrontendSubRequest($formData->toGetRequest(new InternalRequest($uri), false), null, true)->getBody();
255 
256  // goto form page
257  $pageMarkup = (string)$this->executeFrontendSubRequest(new InternalRequest($uri), null, true)->getBody();
258  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
259 
260  // post data and go to summary page
261  $formPostRequest = $formData->with('text-1', 'FOObarBAZ')->toPostRequest(new InternalRequest($uri));
262  $pageMarkup = (string)$this->executeFrontendSubRequest($formPostRequest, null, true)->getBody();
263  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
264 
265  $formMarkup = $formData->getFormMarkup();
266 
267  self::assertStringContainsString('Summary step', $formMarkup, 'the summary form step is shown');
268  self::assertStringContainsString('FOObarBAZ', $formMarkup, 'data from "text-1" is shown');
269  }
270 
272  {
273  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
274  // yield 'Multistep form / ext:form content element' => [
275  // 'formIdentifier' => 'multistep-test-form-1001',
276  // ];
277 
278  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
279  // yield 'Multistep form / custom extbase controller => RenderActionIsCached' => [
280  // 'formIdentifier' => 'RenderActionIsCached-1002',
281  // ];
282 
283  yield 'Multistep form / custom extbase controller => AllActionsUncached' => [
284  'formIdentifier' => 'AllActionsUncached-1003',
285  ];
286 
287  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
288  // yield 'Multistep form / custom extbase controller => AllActionsCached' => [
289  // 'formIdentifier' => 'AllActionsCached-1004',
290  // ];
291 
292  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
293  // yield 'Multistep form / simple FLUIDTEMPLATE' => [
294  // 'formIdentifier' => 'FormFromSimpleFluidtemplate',
295  // ];
296 
297  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
298  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => AllActionsCached' => [
299  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerAllActionsCached',
300  // ];
301 
302  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => AllActionsCached' => [
303  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerAllActionsCached',
304  ];
305 
306  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
307  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => RenderActionIsCached' => [
308  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerRenderActionIsCached',
309  // ];
310 
311  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => RenderActionIsCached' => [
312  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerRenderActionIsCached',
313  ];
314 
315  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
316  // yield 'Multistep form / COA FLUIDTEMPLATE through custom extbase controller => AllActionsUncached' => [
317  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughCustomExtbaseControllerAllActionsUncached',
318  // ];
319 
320  yield 'Multistep form / COA_INT FLUIDTEMPLATE through custom extbase controller => AllActionsUncached' => [
321  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughCustomExtbaseControllerAllActionsUncached',
322  ];
323 
324  // disabled until https://review.typo3.org/c/Packages/TYPO3.CMS/+/67642/ is fixed
325  // yield 'Multistep form / COA FLUIDTEMPLATE through ext:form controller' => [
326  // 'formIdentifier' => 'FormFromCoaFluidtemplateThroughExtFormController',
327  // ];
328 
329  yield 'Multistep form / COA_INT FLUIDTEMPLATE through ext:form controller' => [
330  'formIdentifier' => 'FormFromCoaIntFluidtemplateThroughExtFormController',
331  ];
332  }
333 
338  public function ‪theHoneypotElementChangesWithEveryCallOfTheFirstFormStep(string $formIdentifier): void
339  {
340  $uri = static::ROOT_PAGE_BASE_URI . '/form';
341 
342  // goto form page
343  $pageMarkup = (string)$this->executeFrontendSubRequest(new InternalRequest($uri), null, true)->getBody();
344  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
345  $honeypotId = $formData->getHoneypotId();
346 
347  self::assertNotEmpty($honeypotId, 'honeypot element exists');
348 
349  // revisit form page
350  $pageMarkup = (string)$this->executeFrontendSubRequest(new InternalRequest($uri), null, true)->getBody();
351  $formData = $this->formDataFactory->fromHtmlMarkupAndXpath($pageMarkup, '//form[@id="' . $formIdentifier . '"]');
352 
353  $honeypotIdFromRevisit = $formData->getHoneypotId();
354 
355  self::assertNotEquals($honeypotIdFromRevisit, $honeypotId, 'honeypot differs from historical honeypot');
356  }
357 }
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling
Definition: AbstractRequestHandlingTest.php:18
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\formRendersUncachedIfTheActionTargetIsCalledViaHttpGet
‪formRendersUncachedIfTheActionTargetIsCalledViaHttpGet(string $formIdentifier)
Definition: RequestHandlingTest.php:245
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\AbstractRequestHandlingTest\getMailSpoolMessages
‪getMailSpoolMessages()
Definition: AbstractRequestHandlingTest.php:119
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest
Definition: RequestHandlingTest.php:24
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\formRendersUncachedIfTheActionTargetIsCalledViaHttpGetDataProvider
‪formRendersUncachedIfTheActionTargetIsCalledViaHttpGetDataProvider()
Definition: RequestHandlingTest.php:180
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\theCachingBehavesTheSameForAllFormIntegrationVariantsDataProvider
‪theCachingBehavesTheSameForAllFormIntegrationVariantsDataProvider()
Definition: RequestHandlingTest.php:34
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\setUp
‪setUp()
Definition: RequestHandlingTest.php:28
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\$formDataFactory
‪FormDataFactory $formDataFactory
Definition: RequestHandlingTest.php:26
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\AbstractRequestHandlingTest
Definition: AbstractRequestHandlingTest.php:31
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\$databaseScenarioFile
‪string $databaseScenarioFile
Definition: RequestHandlingTest.php:25
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\theCachingBehavesTheSameForAllFormIntegrationVariants
‪theCachingBehavesTheSameForAllFormIntegrationVariants(string $formIdentifier, string $formNamePrefix)
Definition: RequestHandlingTest.php:112
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\theHoneypotElementChangesWithEveryCallOfTheFirstFormStep
‪theHoneypotElementChangesWithEveryCallOfTheFirstFormStep(string $formIdentifier)
Definition: RequestHandlingTest.php:338
‪TYPO3\CMS\Form\Tests\Functional\RequestHandling\RequestHandlingTest\theHoneypotElementChangesWithEveryCallOfTheFirstFormStepDataProvider
‪theHoneypotElementChangesWithEveryCallOfTheFirstFormStepDataProvider()
Definition: RequestHandlingTest.php:271
‪TYPO3\CMS\Form\Tests\Functional\Framework\FormHandling\FormDataFactory
Definition: FormDataFactory.php:25