TYPO3 CMS  TYPO3_6-2
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  public function setUp() {
25  $this->viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\HtmlentitiesViewHelper', array('renderChildren', 'resolveDefaultEncoding'));
26  $this->viewHelper->expects($this->any())->method('resolveDefaultEncoding')->will($this->returnValue('UTF-8'));
27  }
28 
33  $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
34  }
35 
40  $this->viewHelper->expects($this->never())->method('renderChildren');
41  $actualResult = $this->viewHelper->render('Some string');
42  $this->assertEquals('Some string', $actualResult);
43  }
44 
49  $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
50  $actualResult = $this->viewHelper->render();
51  $this->assertEquals('Some string', $actualResult);
52  }
53 
58  $source = 'This is a sample text without special characters.';
59  $actualResult = $this->viewHelper->render($source);
60  $this->assertSame($source, $actualResult);
61  }
62 
66  public function renderDecodesSimpleString() {
67  $source = 'Some special characters: &©"\'';
68  $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
69  $actualResult = $this->viewHelper->render($source);
70  $this->assertEquals($expectedResult, $actualResult);
71  }
72 
76  public function renderRespectsKeepQuoteArgument() {
77  $source = 'Some special characters: &©"\'';
78  $expectedResult = 'Some special characters: &amp;&copy;"\'';
79  $actualResult = $this->viewHelper->render($source, TRUE);
80  $this->assertEquals($expectedResult, $actualResult);
81  }
82 
86  public function renderRespectsEncodingArgument() {
87  $source = utf8_decode('Some special characters: &©"\'');
88  $expectedResult = 'Some special characters: &amp;&copy;&quot;\'';
89  $actualResult = $this->viewHelper->render($source, FALSE, 'ISO-8859-1');
90  $this->assertEquals($expectedResult, $actualResult);
91  }
92 
97  $source = 'already &quot;encoded&quot;';
98  $expectedResult = 'already &amp;quot;encoded&amp;quot;';
99  $actualResult = $this->viewHelper->render($source);
100  $this->assertEquals($expectedResult, $actualResult);
101  }
102 
107  $source = 'already &quot;encoded&quot;';
108  $expectedResult = 'already &quot;encoded&quot;';
109  $actualResult = $this->viewHelper->render($source, FALSE, 'UTF-8', FALSE);
110  $this->assertEquals($expectedResult, $actualResult);
111  }
112 
117  $source = new \stdClass();
118  $actualResult = $this->viewHelper->render($source);
119  $this->assertSame($source, $actualResult);
120  }
121 }