[TASK] Sync CMS Fluid with Flow Fluid 1.1 (part1)
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Parser / Interceptor / EscapeTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Parser\Interceptor;
3
4 /* *
5 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13 /**
14 * Testcase for Interceptor\Escape
15 */
16 class EscapeTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
17
18 /**
19 * @var \TYPO3\CMS\Fluid\Core\Parser\Interceptor\Escape
20 */
21 protected $escapeInterceptor;
22
23 /**
24 * @var \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
25 */
26 protected $mockViewHelper;
27
28 /**
29 * @var \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode
30 */
31 protected $mockNode;
32
33 /**
34 * @var \TYPO3\CMS\Fluid\Core\Parser\ParsingState
35 */
36 protected $mockParsingState;
37
38 public function setUp() {
39 $this->escapeInterceptor = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\Interceptor\\Escape', array('dummy'));
40 $this->mockViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\AbstractViewHelper');
41 $this->mockNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array(), array(), '', FALSE);
42 $this->mockParsingState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
43 }
44
45 /**
46 * @test
47 */
48 public function processDoesNotDisableEscapingInterceptorByDefault() {
49 $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER;
50 $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(TRUE));
51 $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
52 $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
53 $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
54 $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
55 }
56
57 /**
58 * @test
59 */
60 public function processDisablesEscapingInterceptorIfViewHelperDisablesIt() {
61 $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER;
62 $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(FALSE));
63 $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
64 $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
65 $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
66 $this->assertFalse($this->escapeInterceptor->_get('interceptorEnabled'));
67 }
68
69 /**
70 * @test
71 */
72 public function processReenablesEscapingInterceptorOnClosingViewHelperTagIfItWasDisabledBefore() {
73 $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER;
74 $this->escapeInterceptor->_set('interceptorEnabled', FALSE);
75 $this->escapeInterceptor->_set('viewHelperNodesWhichDisableTheInterceptor', array($this->mockNode));
76 $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
77 $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
78 }
79
80 /**
81 * @test
82 */
83 public function processWrapsCurrentViewHelperInHtmlentitiesViewHelperOnObjectAccessor() {
84 $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OBJECTACCESSOR;
85 $mockNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array(), array(), '', FALSE);
86 $mockEscapeViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\HtmlspecialcharsViewHelper');
87 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
88 $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\HtmlspecialcharsViewHelper')->will($this->returnValue($mockEscapeViewHelper));
89 $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', $mockEscapeViewHelper, array('value' => $mockNode))->will($this->returnValue($this->mockNode));
90 $this->escapeInterceptor->injectObjectManager($mockObjectManager);
91 $actualResult = $this->escapeInterceptor->process($mockNode, $interceptorPosition, $this->mockParsingState);
92 $this->assertSame($this->mockNode, $actualResult);
93 }
94 }
95
96 ?>