‪TYPO3CMS  10.4
HtmlentitiesDecodeViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
20 
24 class ‪HtmlentitiesDecodeViewHelperTest extends ViewHelperBaseTestcase
25 {
29  protected ‪$viewHelper;
30 
37 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  $this->viewHelper = new ‪HtmlentitiesDecodeViewHelper();
42  $this->injectDependenciesIntoViewHelper($this->viewHelper);
43  }
44 
49  {
50  $this->setArgumentsUnderTest(
51  $this->viewHelper,
52  [
53  'value' => 'Some string'
54  ]
55  );
56  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
57  self::assertEquals('Some string', $actualResult);
58  }
59 
64  {
65  $this->viewHelper->setRenderChildrenClosure(
66  function () {
67  return 'Some string';
68  }
69  );
70  $this->setArgumentsUnderTest($this->viewHelper);
71  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
72  self::assertEquals('Some string', $actualResult);
73  }
74 
79  {
80  $source = 'This is a sample text without special characters. <> &©"\'';
81  $this->setArgumentsUnderTest(
82  $this->viewHelper,
83  [
84  'value' => $source,
85  ]
86  );
87  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
88  self::assertSame($source, $actualResult);
89  }
90 
94  public function ‪renderDecodesSimpleString()
95  {
96  $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
97  $expectedResult = 'Some special characters: & " \' < > *';
98  $this->setArgumentsUnderTest(
99  $this->viewHelper,
100  [
101  'value' => $source
102  ]
103  );
104  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
105  self::assertEquals($expectedResult, $actualResult);
106  }
107 
111  public function ‪renderRespectsKeepQuoteArgument()
112  {
113  $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
114  $expectedResult = 'Some special characters: & &quot; \' < > *';
115  $this->setArgumentsUnderTest(
116  $this->viewHelper,
117  [
118  'value' => $source,
119  'keepQuotes' => true,
120  ]
121  );
122  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
123  self::assertEquals($expectedResult, $actualResult);
124  }
125 
129  public function ‪renderRespectsEncodingArgument()
130  {
131  $source = utf8_decode('Some special characters: &amp; &quot; \' &lt; &gt; *');
132  $expectedResult = 'Some special characters: & " \' < > *';
133  $this->setArgumentsUnderTest(
134  $this->viewHelper,
135  [
136  'value' => $source,
137  'encoding' => 'ISO-8859-1',
138  ]
139  );
140  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
141  self::assertEquals($expectedResult, $actualResult);
142  }
143 
148  {
149  $source = new \stdClass();
150  $this->setArgumentsUnderTest(
151  $this->viewHelper,
152  [
153  'value' => $source
154  ]
155  );
156  $actualResult = $this->viewHelper->render();
157  self::assertSame($source, $actualResult);
158  }
159 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\$viewHelper
‪HtmlentitiesDecodeViewHelper $viewHelper
Definition: HtmlentitiesDecodeViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderUsesChildnodesAsSourceIfSpecified
‪renderUsesChildnodesAsSourceIfSpecified()
Definition: HtmlentitiesDecodeViewHelperTest.php:61
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\setUp
‪setUp()
Definition: HtmlentitiesDecodeViewHelperTest.php:36
‪TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper
Definition: HtmlentitiesDecodeViewHelper.php:51
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest
Definition: HtmlentitiesDecodeViewHelperTest.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters
‪renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters()
Definition: HtmlentitiesDecodeViewHelperTest.php:76
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderReturnsUnmodifiedSourceIfItIsNoString
‪renderReturnsUnmodifiedSourceIfItIsNoString()
Definition: HtmlentitiesDecodeViewHelperTest.php:145
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\$defaultArguments
‪array $defaultArguments
Definition: HtmlentitiesDecodeViewHelperTest.php:34
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: ScriptViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderRespectsEncodingArgument
‪renderRespectsEncodingArgument()
Definition: HtmlentitiesDecodeViewHelperTest.php:127
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderUsesValueAsSourceIfSpecified
‪renderUsesValueAsSourceIfSpecified()
Definition: HtmlentitiesDecodeViewHelperTest.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderDecodesSimpleString
‪renderDecodesSimpleString()
Definition: HtmlentitiesDecodeViewHelperTest.php:92
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\HtmlentitiesDecodeViewHelperTest\renderRespectsKeepQuoteArgument
‪renderRespectsKeepQuoteArgument()
Definition: HtmlentitiesDecodeViewHelperTest.php:109