TYPO3  7.6
EscapeTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Parser\Interceptor;
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 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 
17 class EscapeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
18 {
22  protected $escapeInterceptor;
23 
27  protected $mockViewHelper;
28 
32  protected $mockNode;
33 
37  protected $mockParsingState;
38 
39  protected function setUp()
40  {
41  $this->escapeInterceptor = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Parser\Interceptor\Escape::class, array('dummy'));
42  $this->mockViewHelper = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class);
43  $this->mockNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, array(), array(), '', false);
44  $this->mockParsingState = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\ParsingState::class);
45  }
46 
51  {
52  $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER;
53  $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(true));
54  $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
55 
56  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
57  $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
58  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
59  }
60 
65  {
66  $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER;
67  $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(false));
68  $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
69 
70  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
71  $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
72  $this->assertFalse($this->escapeInterceptor->_get('interceptorEnabled'));
73  }
74 
79  {
80  $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER;
81 
82  $this->escapeInterceptor->_set('interceptorEnabled', false);
83  $this->escapeInterceptor->_set('viewHelperNodesWhichDisableTheInterceptor', array($this->mockNode));
84 
85  $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
86  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
87  }
88 
93  {
94  $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OBJECTACCESSOR;
95  $mockNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::class, array(), array(), '', false);
96  $mockEscapeViewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlspecialcharsViewHelper::class);
97  $mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
98  $mockObjectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlspecialcharsViewHelper::class)->will($this->returnValue($mockEscapeViewHelper));
99  $mockObjectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, $mockEscapeViewHelper, array('value' => $mockNode))->will($this->returnValue($this->mockNode));
100  $this->escapeInterceptor->_set('objectManager', $mockObjectManager);
101 
102  $actualResult = $this->escapeInterceptor->process($mockNode, $interceptorPosition, $this->mockParsingState);
103  $this->assertSame($this->mockNode, $actualResult);
104  }
105 }