TYPO3 CMS  TYPO3_7-6
ViewHelperNodeTest.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 {
24  protected $renderingContext;
25 
31  protected $mockObjectManager;
32 
39 
43  protected $controllerContext;
44 
49 
53  protected function setUp()
54  {
55  $this->renderingContext = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContext::class);
56 
57  $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class);
58  $this->renderingContext->_set('objectManager', $this->mockObjectManager);
59 
60  $this->templateVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer::class);
61  $this->renderingContext->injectTemplateVariableContainer($this->templateVariableContainer);
62 
63  $this->controllerContext = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class, [], [], '', false);
64  $this->renderingContext->setControllerContext($this->controllerContext);
65 
66  $this->viewHelperVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class);
67  $this->renderingContext->_set('viewHelperVariableContainer', $this->viewHelperVariableContainer);
68  }
69 
74  {
75  $viewHelper = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class);
76  $arguments = ['foo' => 'bar'];
77  $viewHelperNode = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, ['dummy'], [$viewHelper, $arguments]);
78 
79  $this->assertEquals(get_class($viewHelper), $viewHelperNode->getViewHelperClassName());
80  $this->assertEquals($arguments, $viewHelperNode->_get('arguments'));
81  }
82 
87  {
88  $childNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode::class, [], ['prepareArguments']);
89 
90  $mockViewHelper = $this->getMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Parser\Fixtures\ChildNodeAccessFacetViewHelper::class, ['setChildNodes', 'initializeArguments', 'render', 'prepareArguments']);
91  $mockViewHelper->expects($this->any())->method('prepareArguments')->willReturn([]);
92 
93  $viewHelperNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($mockViewHelper, []);
94  $viewHelperNode->addChildNode($childNode);
95 
96  $mockViewHelper->expects($this->once())->method('setChildNodes')->with($this->equalTo([$childNode]));
97 
98  $viewHelperNode->evaluate($this->renderingContext);
99  }
100 
105  {
106  $mockViewHelper = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class, ['initializeArgumentsAndRender', 'prepareArguments']);
107  $mockViewHelper->expects($this->once())->method('initializeArgumentsAndRender');
108  $mockViewHelper->expects($this->any())->method('prepareArguments')->willReturn([]);
109 
110  $viewHelperNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($mockViewHelper, []);
111 
112  $viewHelperNode->evaluate($this->renderingContext);
113  }
114 
119  {
120  $arguments = [
121  'param0' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param1', 'string', 'Hallo', true, null, false),
122  'param1' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param1', 'string', 'Hallo', true, null, true),
123  'param2' => new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('param2', 'string', 'Hallo', true, null, true)
124  ];
125 
126  $mockViewHelper = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class, ['initializeArgumentsAndRender', 'prepareArguments']);
127  $mockViewHelper->expects($this->any())->method('prepareArguments')->will($this->returnValue($arguments));
128  $mockViewHelper->expects($this->once())->method('initializeArgumentsAndRender');
129 
130  $viewHelperNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($mockViewHelper, [
131  'param2' => new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('b'),
132  'param1' => new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('a')
133  ]);
134 
135  $viewHelperNode->evaluate($this->renderingContext);
136  }
137 
142  {
143  $mockViewHelper = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class, ['render', 'validateArguments', 'prepareArguments', 'setRenderingContext']);
144  $mockViewHelper->expects($this->once())->method('setRenderingContext')->with($this->renderingContext);
145  $mockViewHelper->expects($this->any())->method('prepareArguments')->willReturn([]);
146 
147  $viewHelperNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($mockViewHelper, []);
148 
149  $viewHelperNode->evaluate($this->renderingContext);
150  }
151 
156  {
157  $mockViewHelper = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class, ['render', 'validateArguments', 'prepareArguments', 'setViewHelperVariableContainer']);
158  $mockViewHelper->expects($this->any())->method('render')->will($this->returnValue('String'));
159  $mockViewHelper->expects($this->any())->method('prepareArguments')->willReturn([]);
160 
161  $viewHelperNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($mockViewHelper, []);
162 
163  $viewHelperNode->evaluate($this->renderingContext);
164  $viewHelperNode->evaluate($this->renderingContext);
165  }
166 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)