TYPO3 CMS  TYPO3_7-6
HtmlspecialcharsViewHelperTest.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  * */
16 
21 {
25  protected $viewHelper;
26 
27  protected function setUp()
28  {
29  $this->viewHelper = $this->getMock(HtmlspecialcharsViewHelper::class, ['renderChildren']);
31  $renderingContext = $this->getMock(RenderingContext::class);
32  $this->viewHelper->setRenderingContext($renderingContext);
33  }
34 
39  {
40  $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
41  }
42 
47  {
48  $this->viewHelper->expects($this->never())->method('renderChildren');
49  $actualResult = $this->viewHelper->render('Some string');
50  $this->assertEquals('Some string', $actualResult);
51  }
52 
57  {
58  $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
59  $actualResult = $this->viewHelper->render();
60  $this->assertEquals('Some string', $actualResult);
61  }
62 
67  {
68  $source = 'This is a sample text without special characters.';
69  $actualResult = $this->viewHelper->render($source);
70  $this->assertSame($source, $actualResult);
71  }
72 
76  public function renderDecodesSimpleString()
77  {
78  $source = 'Some special characters: &©"\'';
79  $expectedResult = 'Some special characters: &amp;©&quot;\'';
80  $actualResult = $this->viewHelper->render($source);
81  $this->assertEquals($expectedResult, $actualResult);
82  }
83 
88  {
89  $source = 'Some special characters: &©"\'';
90  $expectedResult = 'Some special characters: &amp;©"\'';
91  $actualResult = $this->viewHelper->render($source, true);
92  $this->assertEquals($expectedResult, $actualResult);
93  }
94 
99  {
100  $source = utf8_decode('Some special characters: &"\'');
101  $expectedResult = 'Some special characters: &amp;&quot;\'';
102  $actualResult = $this->viewHelper->render($source, false, 'ISO-8859-1');
103  $this->assertEquals($expectedResult, $actualResult);
104  }
105 
110  {
111  $source = 'already &quot;encoded&quot;';
112  $expectedResult = 'already &amp;quot;encoded&amp;quot;';
113  $actualResult = $this->viewHelper->render($source);
114  $this->assertEquals($expectedResult, $actualResult);
115  }
116 
121  {
122  $source = 'already &quot;encoded&quot;';
123  $expectedResult = 'already &quot;encoded&quot;';
124  $actualResult = $this->viewHelper->render($source, false, 'UTF-8', false);
125  $this->assertEquals($expectedResult, $actualResult);
126  }
127 
132  {
133  $source = new \stdClass();
134  $actualResult = $this->viewHelper->render($source);
135  $this->assertSame($source, $actualResult);
136  }
137 }