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