TYPO3 CMS  TYPO3_6-2
EscapeTest.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 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 
18 
22  protected $escapeInterceptor;
23 
27  protected $mockViewHelper;
28 
32  protected $mockNode;
33 
37  protected $mockParsingState;
38 
39  public function setUp() {
40  $this->escapeInterceptor = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\Interceptor\\Escape', array('dummy'));
41  $this->mockViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\AbstractViewHelper');
42  $this->mockNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array(), array(), '', FALSE);
43  $this->mockParsingState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
44  }
45 
51  $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(TRUE));
52  $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
53 
54  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
55  $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
56  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
57  }
58 
64  $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(FALSE));
65  $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
66 
67  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
68  $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
69  $this->assertFalse($this->escapeInterceptor->_get('interceptorEnabled'));
70  }
71 
77 
78  $this->escapeInterceptor->_set('interceptorEnabled', FALSE);
79  $this->escapeInterceptor->_set('viewHelperNodesWhichDisableTheInterceptor', array($this->mockNode));
80 
81  $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
82  $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
83  }
84 
90  $mockNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array(), array(), '', FALSE);
91  $mockEscapeViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\HtmlspecialcharsViewHelper');
92  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
93  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\HtmlspecialcharsViewHelper')->will($this->returnValue($mockEscapeViewHelper));
94  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', $mockEscapeViewHelper, array('value' => $mockNode))->will($this->returnValue($this->mockNode));
95  $this->escapeInterceptor->_set('objectManager', $mockObjectManager);
96 
97  $actualResult = $this->escapeInterceptor->process($mockNode, $interceptorPosition, $this->mockParsingState);
98  $this->assertSame($this->mockNode, $actualResult);
99  }
100 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)