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