TYPO3 CMS  TYPO3_7-6
HtmlentitiesViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
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 3 of the *
9  * License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 {
22  protected $viewHelper;
23 
24  protected function setUp()
25  {
26  $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesViewHelper::class, ['renderChildren', 'resolveDefaultEncoding']);
27  $this->viewHelper->expects($this->any())->method('resolveDefaultEncoding')->will($this->returnValue('UTF-8'));
28  }
29 
34  {
35  $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
36  }
37 
42  {
43  $this->viewHelper->expects($this->never())->method('renderChildren');
44  $actualResult = $this->viewHelper->render('Some string');
45  $this->assertEquals('Some string', $actualResult);
46  }
47 
52  {
53  $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
54  $actualResult = $this->viewHelper->render();
55  $this->assertEquals('Some string', $actualResult);
56  }
57 
62  {
63  $source = 'This is a sample text without special characters.';
64  $actualResult = $this->viewHelper->render($source);
65  $this->assertSame($source, $actualResult);
66  }
67 
71  public function renderDecodesSimpleString()
72  {
73  $source = 'Some special characters: &©"\'';
74  $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
75  $actualResult = $this->viewHelper->render($source);
76  $this->assertEquals($expectedResult, $actualResult);
77  }
78 
83  {
84  $source = 'Some special characters: &©"\'';
85  $expectedResult = 'Some special characters: &amp;&copy;"\'';
86  $actualResult = $this->viewHelper->render($source, true);
87  $this->assertEquals($expectedResult, $actualResult);
88  }
89 
94  {
95  $source = utf8_decode('Some special characters: &©"\'');
96  $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
97  $actualResult = $this->viewHelper->render($source, false, 'ISO-8859-1');
98  $this->assertEquals($expectedResult, $actualResult);
99  }
100 
105  {
106  $source = 'already &quot;encoded&quot;';
107  $expectedResult = 'already &amp;quot;encoded&amp;quot;';
108  $actualResult = $this->viewHelper->render($source);
109  $this->assertEquals($expectedResult, $actualResult);
110  }
111 
116  {
117  $source = 'already &quot;encoded&quot;';
118  $expectedResult = 'already &quot;encoded&quot;';
119  $actualResult = $this->viewHelper->render($source, false, 'UTF-8', false);
120  $this->assertEquals($expectedResult, $actualResult);
121  }
122 
127  {
128  $source = new \stdClass();
129  $actualResult = $this->viewHelper->render($source);
130  $this->assertSame($source, $actualResult);
131  }
132 }