TYPO3 CMS  TYPO3_7-6
HtmlentitiesDecodeViewHelperTest.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 
17 
22 {
26  protected $viewHelper;
27 
28  protected function setUp()
29  {
30  $this->viewHelper = $this->getMock(HtmlentitiesDecodeViewHelper::class, ['renderChildren']);
31 
33  $renderingContext = $this->getMock(RenderingContext::class);
34  $this->viewHelper->setRenderingContext($renderingContext);
35  }
36 
41  {
42  $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
43  }
44 
49  {
50  $this->viewHelper->expects($this->never())->method('renderChildren');
51  $actualResult = $this->viewHelper->render('Some string');
52  $this->assertEquals('Some string', $actualResult);
53  }
54 
59  {
60  $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
61  $actualResult = $this->viewHelper->render();
62  $this->assertEquals('Some string', $actualResult);
63  }
64 
69  {
70  $source = 'This is a sample text without special characters. <> &©"\'';
71  $actualResult = $this->viewHelper->render($source);
72  $this->assertSame($source, $actualResult);
73  }
74 
78  public function renderDecodesSimpleString()
79  {
80  $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
81  $expectedResult = 'Some special characters: & " \' < > *';
82  $actualResult = $this->viewHelper->render($source);
83  $this->assertEquals($expectedResult, $actualResult);
84  }
85 
90  {
91  $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
92  $expectedResult = 'Some special characters: & &quot; \' < > *';
93  $actualResult = $this->viewHelper->render($source, true);
94  $this->assertEquals($expectedResult, $actualResult);
95  }
96 
101  {
102  $source = utf8_decode('Some special characters: &amp; &quot; \' &lt; &gt; *');
103  $expectedResult = 'Some special characters: & " \' < > *';
104  $actualResult = $this->viewHelper->render($source, false, 'ISO-8859-1');
105  $this->assertEquals($expectedResult, $actualResult);
106  }
107 
112  {
113  $source = new \stdClass();
114  $actualResult = $this->viewHelper->render($source);
115  $this->assertSame($source, $actualResult);
116  }
117 }