/** * @test */ public function multipleEvaluateCallsShareTheSameViewHelperInstance() { $mockViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\AbstractViewHelper', array('render', 'validateArguments', 'prepareArguments', 'setViewHelperVariableContainer')); $mockViewHelper->expects($this->any())->method('render')->will($this->returnValue('String')); $viewHelperNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($mockViewHelper, array()); $viewHelperNode->evaluate($this->renderingContext); $viewHelperNode->evaluate($this->renderingContext); }
/** * @param array $arguments * @param array $variables * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $childNode * @param string $extensionName * @param string $pluginName * @return \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper */ protected function buildViewHelperInstance($arguments = array(), $variables = array(), $childNode = NULL, $extensionName = NULL, $pluginName = NULL) { $instance = $this->createInstance(); /** @var \TYPO3\CMS\Fluid\Core\ViewHelper\TemplateVariableContainer $container */ $container = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer'); /** @var \TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer $viewHelperContainer */ $viewHelperContainer = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer'); if (0 < count($variables)) { \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($container, 'variables', $variables, TRUE); } $node = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode($instance, $arguments); /** @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder $uriBuilder */ $uriBuilder = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder'); /** @var \TYPO3\CMS\Extbase\Mvc\Web\Request $request */ $request = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request'); if (NULL !== $extensionName) { $request->setControllerExtensionName($extensionName); } if (NULL !== $pluginName) { $request->setPluginName($pluginName); } /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */ $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response'); /** @var \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext $controllerContext */ $controllerContext = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext'); $controllerContext->setRequest($request); $controllerContext->setResponse($response); $controllerContext->setUriBuilder($uriBuilder); /** @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext $renderingContext */ $renderingContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext'); $renderingContext->setControllerContext($controllerContext); \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($renderingContext, 'viewHelperVariableContainer', $viewHelperContainer, TRUE); \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($renderingContext, 'templateVariableContainer', $container, TRUE); $instance->setArguments($arguments); $instance->setRenderingContext($renderingContext); if (TRUE === $instance instanceof \Tx_Fluidwidget_Core_Widget_AbstractWidgetViewHelper) { /** @var \TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext */ $widgetContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext'); \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($instance, 'widgetContext', $widgetContext, TRUE); } if (NULL !== $childNode) { $node->addChildNode($childNode); if ($instance instanceof \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface) { $instance->setChildNodes(array($childNode)); } } $instance->setViewHelperNode($node); return $instance; }