‪TYPO3CMS  ‪main
EscapeChildrenRenderingTest.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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪EscapeChildrenRenderingTest extends FunctionalTestCase
26 {
27  protected bool ‪$initializeDatabase = false;
28 
29  protected array ‪$testExtensionsToLoad = ['typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test'];
30 
31  public static function ‪viewHelperTemplateSourcesDataProvider(): array
32  {
33  return [
34  'EscapeChildrenEnabledAndEscapeOutputDisabled: Tag syntax with children, properly encodes variable value' =>
35  [
36  '<ft:escapeChildrenEnabledAndEscapeOutputDisabled>{settings.test}</ft:escapeChildrenEnabledAndEscapeOutputDisabled>',
37  '&lt;strong&gt;Bla&lt;/strong&gt;',
38  ],
39  'EscapeChildrenEnabledAndEscapeOutputDisabled: Inline syntax with children, properly encodes variable value' =>
40  [
41  '{settings.test -> ft:escapeChildrenEnabledAndEscapeOutputDisabled()}',
42  '&lt;strong&gt;Bla&lt;/strong&gt;',
43  ],
44  'EscapeChildrenEnabledAndEscapeOutputDisabled: Tag syntax with argument, does not encode variable value' =>
45  [
46  '<ft:escapeChildrenEnabledAndEscapeOutputDisabled content="{settings.test}" />',
47  '<strong>Bla</strong>',
48  ],
49  'EscapeChildrenEnabledAndEscapeOutputDisabled: Inline syntax with argument, does not encode variable value' =>
50  [
51  '{ft:escapeChildrenEnabledAndEscapeOutputDisabled(content: settings.test)}',
52  '<strong>Bla</strong>',
53  ],
54  'EscapeChildrenEnabledAndEscapeOutputDisabled: Inline syntax with string, does not encode string value' =>
55  [
56  '{ft:escapeChildrenEnabledAndEscapeOutputDisabled(content: \'<strong>Bla</strong>\')}',
57  '<strong>Bla</strong>',
58  ],
59  'EscapeChildrenEnabledAndEscapeOutputDisabled: Inline syntax with argument in quotes, does not encode variable value' =>
60  [
61  '{ft:escapeChildrenEnabledAndEscapeOutputDisabled(content: \'{settings.test}\')}',
62  '<strong>Bla</strong>',
63  ],
64  'EscapeChildrenEnabledAndEscapeOutputDisabled: Tag syntax with nested inline syntax and children rendering, does not encode variable value' =>
65  [
66  '<ft:escapeChildrenEnabledAndEscapeOutputDisabled content="{settings.test -> ft:escapeChildrenEnabledAndEscapeOutputDisabled()}" />',
67  '<strong>Bla</strong>',
68  ],
69  'EscapeChildrenEnabledAndEscapeOutputDisabled: Tag syntax with nested inline syntax and argument in inline, does not encode variable value' =>
70  [
71  '<ft:escapeChildrenEnabledAndEscapeOutputDisabled content="{ft:escapeChildrenEnabledAndEscapeOutputDisabled(content: settings.test)}" />',
72  '<strong>Bla</strong>',
73  ],
74 
75  'EscapeChildrenDisabledAndEscapeOutputDisabled: Tag syntax with children, properly encodes variable value' =>
76  [
77  '<ft:escapeChildrenDisabledAndEscapeOutputDisabled>{settings.test}</ft:escapeChildrenDisabledAndEscapeOutputDisabled>',
78  '<strong>Bla</strong>',
79  ],
80  'EscapeChildrenDisabledAndEscapeOutputDisabled: Inline syntax with children, properly encodes variable value' =>
81  [
82  '{settings.test -> ft:escapeChildrenDisabledAndEscapeOutputDisabled()}',
83  '<strong>Bla</strong>',
84  ],
85  'EscapeChildrenDisabledAndEscapeOutputDisabled: Tag syntax with argument, does not encode variable value' =>
86  [
87  '<ft:escapeChildrenDisabledAndEscapeOutputDisabled content="{settings.test}" />',
88  '<strong>Bla</strong>',
89  ],
90  'EscapeChildrenDisabledAndEscapeOutputDisabled: Inline syntax with argument, does not encode variable value' =>
91  [
92  '{ft:escapeChildrenDisabledAndEscapeOutputDisabled(content: settings.test)}',
93  '<strong>Bla</strong>',
94  ],
95  'EscapeChildrenDisabledAndEscapeOutputDisabled: Inline syntax with string, does not encode string value' =>
96  [
97  '{ft:escapeChildrenDisabledAndEscapeOutputDisabled(content: \'<strong>Bla</strong>\')}',
98  '<strong>Bla</strong>',
99  ],
100  'EscapeChildrenDisabledAndEscapeOutputDisabled: Inline syntax with argument in quotes, does not encode variable value' =>
101  [
102  '{ft:escapeChildrenDisabledAndEscapeOutputDisabled(content: \'{settings.test}\')}',
103  '<strong>Bla</strong>',
104  ],
105  'EscapeChildrenDisabledAndEscapeOutputDisabled: Tag syntax with nested inline syntax and children rendering, does not encode variable value' =>
106  [
107  '<ft:escapeChildrenDisabledAndEscapeOutputDisabled content="{settings.test -> ft:escapeChildrenDisabledAndEscapeOutputDisabled()}" />',
108  '<strong>Bla</strong>',
109  ],
110  'EscapeChildrenDisabledAndEscapeOutputDisabled: Tag syntax with nested inline syntax and argument in inline, does not encode variable value' =>
111  [
112  '<ft:escapeChildrenDisabledAndEscapeOutputDisabled content="{ft:escapeChildrenDisabledAndEscapeOutputDisabled(content: settings.test)}" />',
113  '<strong>Bla</strong>',
114  ],
115 
116  ];
117  }
118 
119  #[DataProvider('viewHelperTemplateSourcesDataProvider')]
120  #[Test]
121  public function ‪renderingTest(string $viewHelperTemplate, string $expectedOutput): void
122  {
123  $view = new ‪TemplateView();
124  $view->assign('settings', ['test' => '<strong>Bla</strong>']);
125  $view->getRenderingContext()->getViewHelperResolver()->addNamespace('ft', 'TYPO3Tests\\FluidTest\\ViewHelpers');
126  $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($viewHelperTemplate);
127  self::assertSame($expectedOutput, $view->render());
128  }
129 }
‪TYPO3\CMS\Fluid\Tests\Functional\EscapeChildrenRenderingTest\viewHelperTemplateSourcesDataProvider
‪static viewHelperTemplateSourcesDataProvider()
Definition: EscapeChildrenRenderingTest.php:31
‪TYPO3\CMS\Fluid\Tests\Functional\EscapeChildrenRenderingTest\$initializeDatabase
‪bool $initializeDatabase
Definition: EscapeChildrenRenderingTest.php:27
‪TYPO3\CMS\Fluid\Tests\Functional
Definition: EscapeChildrenRenderingStandaloneTest.php:18
‪TYPO3\CMS\Fluid\Tests\Functional\EscapeChildrenRenderingTest
Definition: EscapeChildrenRenderingTest.php:26
‪TYPO3\CMS\Fluid\View\TemplateView
Definition: TemplateView.php:22
‪TYPO3\CMS\Fluid\Tests\Functional\EscapeChildrenRenderingTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: EscapeChildrenRenderingTest.php:29
‪TYPO3\CMS\Fluid\Tests\Functional\EscapeChildrenRenderingTest\renderingTest
‪renderingTest(string $viewHelperTemplate, string $expectedOutput)
Definition: EscapeChildrenRenderingTest.php:121