TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
HtmlentitiesDecodeViewHelperTest.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  */
16 use Prophecy\Prophecy\ObjectProphecy;
20 
25 {
30 
34  protected $viewHelper;
35 
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 
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 
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 
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 
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 
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 
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 
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 }
setArgumentsUnderTest(ViewHelperInterface $viewHelper, array $arguments=[])