[TASK] Move ViewHelper arguments to initializeArguments() in ext:fluid
[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 use Prophecy\Prophecy\ObjectProphecy;
17 use TYPO3\CMS\Extbase\Reflection\ReflectionService;
18 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
19 use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper;
20
21 /**
22 * Test case
23 */
24 class HtmlentitiesDecodeViewHelperTest extends ViewHelperBaseTestcase
25 {
26 /**
27 * @var ReflectionService|ObjectProphecy
28 */
29 protected $reflectionServiceProphecy;
30
31 /**
32 * @var HtmlentitiesDecodeViewHelper
33 */
34 protected $viewHelper;
35
36 /**
37 * shortcut for default Arguments which would be prepared by initializeArguments()
38 *
39 * @var array
40 */
41 protected $defaultArguments;
42
43 protected function setUp()
44 {
45 parent::setUp();
46 $this->reflectionServiceProphecy = $this->prophesize(ReflectionService::class);
47 $this->viewHelper = new HtmlentitiesDecodeViewHelper();
48 $this->viewHelper->injectReflectionService($this->reflectionServiceProphecy->reveal());
49 $this->injectDependenciesIntoViewHelper($this->viewHelper);
50 }
51
52 /**
53 * @test
54 */
55 public function renderUsesValueAsSourceIfSpecified()
56 {
57 $this->setArgumentsUnderTest(
58 $this->viewHelper,
59 [
60 'value' => 'Some string'
61 ]
62 );
63 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
64 $this->assertEquals('Some string', $actualResult);
65 }
66
67 /**
68 * @test
69 */
70 public function renderUsesChildnodesAsSourceIfSpecified()
71 {
72 $this->viewHelper->setRenderChildrenClosure(
73 function () {
74 return 'Some string';
75 }
76 );
77 $this->setArgumentsUnderTest($this->viewHelper);
78 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
79 $this->assertEquals('Some string', $actualResult);
80 }
81
82 /**
83 * @test
84 */
85 public function renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters()
86 {
87 $source = 'This is a sample text without special characters. <> &©"\'';
88 $this->setArgumentsUnderTest(
89 $this->viewHelper,
90 [
91 'value' => $source,
92 ]
93 );
94 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
95 $this->assertSame($source, $actualResult);
96 }
97
98 /**
99 * @test
100 */
101 public function renderDecodesSimpleString()
102 {
103 $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
104 $expectedResult = 'Some special characters: & " \' < > *';
105 $this->setArgumentsUnderTest(
106 $this->viewHelper,
107 [
108 'value' => $source
109 ]
110 );
111 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
112 $this->assertEquals($expectedResult, $actualResult);
113 }
114
115 /**
116 * @test
117 */
118 public function renderRespectsKeepQuoteArgument()
119 {
120 $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
121 $expectedResult = 'Some special characters: & &quot; \' < > *';
122 $this->setArgumentsUnderTest(
123 $this->viewHelper,
124 [
125 'value' => $source,
126 'keepQuotes' => true,
127 ]
128 );
129 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
130 $this->assertEquals($expectedResult, $actualResult);
131 }
132
133 /**
134 * @test
135 */
136 public function renderRespectsEncodingArgument()
137 {
138 $source = utf8_decode('Some special characters: &amp; &quot; \' &lt; &gt; *');
139 $expectedResult = 'Some special characters: & " \' < > *';
140 $this->setArgumentsUnderTest(
141 $this->viewHelper,
142 [
143 'value' => $source,
144 'encoding' => 'ISO-8859-1',
145 ]
146 );
147 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
148 $this->assertEquals($expectedResult, $actualResult);
149 }
150
151 /**
152 * @test
153 */
154 public function renderReturnsUnmodifiedSourceIfItIsNoString()
155 {
156 $source = new \stdClass();
157 $this->setArgumentsUnderTest(
158 $this->viewHelper,
159 [
160 'value' => $source
161 ]
162 );
163 $actualResult = $this->viewHelper->render();
164 $this->assertSame($source, $actualResult);
165 }
166 }