‪TYPO3CMS  9.5
FormViewHelperTest.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\FunctionalTestCase;
22 
23 class ‪FormViewHelperTest extends FunctionalTestCase
24 {
25  public function ‪isRenderedDataProvider(): array
26  {
27  return [
28  '#1' => [
29  '<f:form action="{action}" method="{method}" fieldNamePrefix="{fieldNamePrefix}" />',
30  [
31  'action' => 'fieldNamePrefix<>&"\'',
32  'method' => 'fieldNamePrefix<>&"\'',
33  'fieldNamePrefix' => 'fieldNamePrefix<>&"\'',
34  ],
35  // first element having "@extension" in name attribute
36  '<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;\'[__referrer][@extension]" value="" />',
37  ],
38  '#2' => [
39  '{f:form(action:action, method:method, fieldNamePrefix:fieldNamePrefix)}',
40  [
41  'action' => 'fieldNamePrefix<>&"\'',
42  'method' => 'fieldNamePrefix<>&"\'',
43  'fieldNamePrefix' => 'fieldNamePrefix<>&"\'',
44  ],
45  // first element having "@extension" in name attribute
46  '<input type="hidden" name="fieldNamePrefix&lt;&gt;&amp;&quot;\'[__referrer][@extension]" value="" />',
47  ],
48  ];
49  }
50 
59  public function ‪isRendered(string $source, array $variables, string $expectation): void
60  {
61  $view = new ‪StandaloneView();
62  $view->setTemplateSource($source);
63  $view->assignMultiple($variables);
64  $body = $view->render();
65 
66  $actual = null;
67  if (preg_match('#<input[^>]+name=".+\[@extension\]"[^>]+>#m', $body, $matches)) {
68  $actual = $matches[0];
69  }
70 
71  self::assertSame($expectation, $actual);
72  }
73 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\FormViewHelperTest\isRenderedDataProvider
‪isRenderedDataProvider()
Definition: FormViewHelperTest.php:25
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\FormViewHelperTest
Definition: FormViewHelperTest.php:24
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\FormViewHelperTest\isRendered
‪isRendered(string $source, array $variables, string $expectation)
Definition: FormViewHelperTest.php:59