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