TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
HtmlentitiesViewHelperTest.php
Go to the documentation of this file.
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  */
18 
23 {
24 
28  protected $viewHelper;
29 
35  protected $defaultArguments;
36 
37  protected function setUp()
38  {
39  parent::setUp();
40  $this->viewHelper = new HtmlentitiesViewHelper();
41  $this->injectDependenciesIntoViewHelper($this->viewHelper);
42  }
43 
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 
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 
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 
93  public function renderDecodesSimpleString()
94  {
95  $source = 'Some special characters: &©"\'';
96  $this->setArgumentsUnderTest(
97  $this->viewHelper,
98  [
99  'value' => $source
100  ]
101  );
102  $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
103  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
104  $this->assertEquals($expectedResult, $actualResult);
105  }
106 
111  {
112  $source = 'Some special characters: &©"\'';
113  $this->setArgumentsUnderTest(
114  $this->viewHelper,
115  [
116  'value' => $source,
117  'keepQuotes' => true,
118  ]
119  );
120  $expectedResult = 'Some special characters: &amp;&copy;"\'';
121  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
122  $this->assertEquals($expectedResult, $actualResult);
123  }
124 
129  {
130  $source = utf8_decode('Some special characters: &©"\'');
131  $this->setArgumentsUnderTest(
132  $this->viewHelper,
133  [
134  'value' => $source,
135  'encoding' => 'ISO-8859-1',
136  ]
137  );
138  $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
139  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
140  $this->assertEquals($expectedResult, $actualResult);
141  }
142 
147  {
148  $source = 'already &quot;encoded&quot;';
149  $this->setArgumentsUnderTest(
150  $this->viewHelper,
151  [
152  'value' => $source
153  ]
154  );
155  $expectedResult = 'already &amp;quot;encoded&amp;quot;';
156  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
157  $this->assertEquals($expectedResult, $actualResult);
158  }
159 
164  {
165  $source = 'already &quot;encoded&quot;';
166  $this->setArgumentsUnderTest(
167  $this->viewHelper,
168  [
169  'value' => $source,
170  'doubleEncode' => false,
171  ]
172  );
173  $expectedResult = 'already &quot;encoded&quot;';
174  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
175  $this->assertEquals($expectedResult, $actualResult);
176  }
177 
185  {
186  $source = new \stdClass();
187  $this->setArgumentsUnderTest(
188  $this->viewHelper,
189  [
190  'value' => $source
191  ]
192  );
193  $actualResult = $this->viewHelper->render();
194  $this->assertSame($source, $actualResult);
195  }
196 }
setArgumentsUnderTest(ViewHelperInterface $viewHelper, array $arguments=[])