TYPO3 CMS  TYPO3_6-2
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  * */
13 
18 
22  protected $viewHelper;
23 
24  public function setUp() {
25  $this->viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\HtmlspecialcharsViewHelper', array('renderChildren'));
26  }
27 
32  $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
33  }
34 
39  $this->viewHelper->expects($this->never())->method('renderChildren');
40  $actualResult = $this->viewHelper->render('Some string');
41  $this->assertEquals('Some string', $actualResult);
42  }
43 
48  $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
49  $actualResult = $this->viewHelper->render();
50  $this->assertEquals('Some string', $actualResult);
51  }
52 
57  $source = 'This is a sample text without special characters.';
58  $actualResult = $this->viewHelper->render($source);
59  $this->assertSame($source, $actualResult);
60  }
61 
65  public function renderDecodesSimpleString() {
66  $source = 'Some special characters: &©"\'';
67  $expectedResult = 'Some special characters: &amp;©&quot;\'';
68  $actualResult = $this->viewHelper->render($source);
69  $this->assertEquals($expectedResult, $actualResult);
70  }
71 
75  public function renderRespectsKeepQuoteArgument() {
76  $source = 'Some special characters: &©"\'';
77  $expectedResult = 'Some special characters: &amp;©"\'';
78  $actualResult = $this->viewHelper->render($source, TRUE);
79  $this->assertEquals($expectedResult, $actualResult);
80  }
81 
85  public function renderRespectsEncodingArgument() {
86  $source = utf8_decode('Some special characters: &"\'');
87  $expectedResult = 'Some special characters: &amp;&quot;\'';
88  $actualResult = $this->viewHelper->render($source, FALSE, 'ISO-8859-1');
89  $this->assertEquals($expectedResult, $actualResult);
90  }
91 
96  $source = 'already &quot;encoded&quot;';
97  $expectedResult = 'already &amp;quot;encoded&amp;quot;';
98  $actualResult = $this->viewHelper->render($source);
99  $this->assertEquals($expectedResult, $actualResult);
100  }
101 
106  $source = 'already &quot;encoded&quot;';
107  $expectedResult = 'already &quot;encoded&quot;';
108  $actualResult = $this->viewHelper->render($source, FALSE, 'UTF-8', FALSE);
109  $this->assertEquals($expectedResult, $actualResult);
110  }
111 
116  $source = new \stdClass();
117  $actualResult = $this->viewHelper->render($source);
118  $this->assertSame($source, $actualResult);
119  }
120 }