TYPO3 CMS  TYPO3_8-7
HtmlentitiesDecodeViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
21 
25 class HtmlentitiesDecodeViewHelperTest extends ViewHelperBaseTestcase
26 {
31 
35  protected $viewHelper;
36 
42  protected $defaultArguments;
43 
44  protected function setUp()
45  {
46  parent::setUp();
47  $this->reflectionServiceProphecy = $this->prophesize(ReflectionService::class);
48  $this->viewHelper = new HtmlentitiesDecodeViewHelper();
49  $this->viewHelper->injectReflectionService($this->reflectionServiceProphecy->reveal());
50  $this->injectDependenciesIntoViewHelper($this->viewHelper);
51  }
52 
57  {
58  $this->setArgumentsUnderTest(
59  $this->viewHelper,
60  [
61  'value' => 'Some string'
62  ]
63  );
64  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
65  $this->assertEquals('Some string', $actualResult);
66  }
67 
72  {
73  $this->viewHelper->setRenderChildrenClosure(
74  function () {
75  return 'Some string';
76  }
77  );
78  $this->setArgumentsUnderTest($this->viewHelper);
79  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
80  $this->assertEquals('Some string', $actualResult);
81  }
82 
87  {
88  $source = 'This is a sample text without special characters. <> &©"\'';
89  $this->setArgumentsUnderTest(
90  $this->viewHelper,
91  [
92  'value' => $source,
93  ]
94  );
95  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
96  $this->assertSame($source, $actualResult);
97  }
98 
102  public function renderDecodesSimpleString()
103  {
104  $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
105  $expectedResult = 'Some special characters: & " \' < > *';
106  $this->setArgumentsUnderTest(
107  $this->viewHelper,
108  [
109  'value' => $source
110  ]
111  );
112  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
113  $this->assertEquals($expectedResult, $actualResult);
114  }
115 
120  {
121  $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
122  $expectedResult = 'Some special characters: & &quot; \' < > *';
123  $this->setArgumentsUnderTest(
124  $this->viewHelper,
125  [
126  'value' => $source,
127  'keepQuotes' => true,
128  ]
129  );
130  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
131  $this->assertEquals($expectedResult, $actualResult);
132  }
133 
138  {
139  $source = utf8_decode('Some special characters: &amp; &quot; \' &lt; &gt; *');
140  $expectedResult = 'Some special characters: & " \' < > *';
141  $this->setArgumentsUnderTest(
142  $this->viewHelper,
143  [
144  'value' => $source,
145  'encoding' => 'ISO-8859-1',
146  ]
147  );
148  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
149  $this->assertEquals($expectedResult, $actualResult);
150  }
151 
156  {
157  $source = new \stdClass();
158  $this->setArgumentsUnderTest(
159  $this->viewHelper,
160  [
161  'value' => $source
162  ]
163  );
164  $actualResult = $this->viewHelper->render();
165  $this->assertSame($source, $actualResult);
166  }
167 }