8e239e5bd476211db8007abec65aab460bf5c009
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Format / HtmlentitiesDecodeViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
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
14 /**
15 * Test case
16 */
17 class HtmlentitiesDecodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
18
19 /**
20 * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper
21 */
22 protected $viewHelper;
23
24 protected function setUp() {
25 $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper::class, array('renderChildren'));
26 }
27
28 /**
29 * @test
30 */
31 public function viewHelperDeactivatesEscapingInterceptor() {
32 $this->assertFalse($this->viewHelper->isEscapingInterceptorEnabled());
33 }
34
35 /**
36 * @test
37 */
38 public function renderUsesValueAsSourceIfSpecified() {
39 $this->viewHelper->expects($this->never())->method('renderChildren');
40 $actualResult = $this->viewHelper->render('Some string');
41 $this->assertEquals('Some string', $actualResult);
42 }
43
44 /**
45 * @test
46 */
47 public function renderUsesChildnodesAsSourceIfSpecified() {
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
53 /**
54 * @test
55 */
56 public function renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters() {
57 $source = 'This is a sample text without special characters. <> &©"\'';
58 $actualResult = $this->viewHelper->render($source);
59 $this->assertSame($source, $actualResult);
60 }
61
62 /**
63 * @test
64 */
65 public function renderDecodesSimpleString() {
66 $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
67 $expectedResult = 'Some special characters: & " \' < > *';
68 $actualResult = $this->viewHelper->render($source);
69 $this->assertEquals($expectedResult, $actualResult);
70 }
71
72 /**
73 * @test
74 */
75 public function renderRespectsKeepQuoteArgument() {
76 $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
77 $expectedResult = 'Some special characters: & &quot; \' < > *';
78 $actualResult = $this->viewHelper->render($source, TRUE);
79 $this->assertEquals($expectedResult, $actualResult);
80 }
81
82 /**
83 * @test
84 */
85 public function renderRespectsEncodingArgument() {
86 $source = utf8_decode('Some special characters: &amp; &quot; \' &lt; &gt; *');
87 $expectedResult = 'Some special characters: & " \' < > *';
88 $actualResult = $this->viewHelper->render($source, FALSE, 'ISO-8859-1');
89 $this->assertEquals($expectedResult, $actualResult);
90 }
91
92 /**
93 * @test
94 */
95 public function renderReturnsUnmodifiedSourceIfItIsNoString() {
96 $source = new \stdClass();
97 $actualResult = $this->viewHelper->render($source);
98 $this->assertSame($source, $actualResult);
99 }
100
101 }