Exemplo n.º 1
0
 /**
  * @test
  */
 public function processDisablesEscapingInterceptorIfViewHelperDisablesIt()
 {
     $interceptorPosition = \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER;
     $this->mockViewHelper->expects($this->once())->method('isEscapingInterceptorEnabled')->will($this->returnValue(FALSE));
     $this->mockNode->expects($this->once())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
     $this->assertTrue($this->escapeInterceptor->_get('interceptorEnabled'));
     $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
     $this->assertFalse($this->escapeInterceptor->_get('interceptorEnabled'));
 }
Exemplo n.º 2
0
 /**
  * Helper method which triggers the rendering of everything between the
  * opening and the closing tag.
  *
  * @return mixed The finally rendered child nodes.
  * @api
  */
 public function renderChildren()
 {
     if ($this->renderChildrenClosure !== null) {
         $closure = $this->renderChildrenClosure;
         return $closure();
     }
     return $this->viewHelperNode->evaluateChildNodes($this->renderingContext);
 }
Exemplo n.º 3
0
 /**
  * @param array $templateVariableContainerArguments
  * @return TemplateVariableContainer
  */
 protected function executeViewHelperClosure($templateVariableContainerArguments = array())
 {
     $instance = $this->objectManager->get('FluidTYPO3\\Flux\\ViewHelpers\\Field\\CustomViewHelper');
     $renderingContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext');
     $container = $renderingContext->getTemplateVariableContainer();
     $arguments = array('name' => 'custom');
     foreach ($templateVariableContainerArguments as $name => $value) {
         $container->add($name, $value);
     }
     $node = new ViewHelperNode($instance, $arguments);
     $childNode = new TextNode('Hello world!');
     $node->addChildNode($childNode);
     $instance->setRenderingContext($renderingContext);
     $instance->setViewHelperNode($node);
     /** @var \Closure $closure */
     $closure = $this->callInaccessibleMethod($instance, 'buildClosure');
     $parameters = array('itemFormElName' => 'test', 'itemFormElLabel' => 'Test label');
     $output = $closure($parameters);
     $this->assertNotEmpty($output);
     $this->assertSame('Hello world!', $output);
     return $instance->getTemplateVariableContainer();
 }
Exemplo n.º 4
0
 /**
  * Convert a single ViewHelperNode into its cached representation. If the ViewHelper implements the "Compilable" facet,
  * the ViewHelper itself is asked for its cached PHP code representation. If not, a ViewHelper is built and then invoked.
  *
  * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode $node
  * @return array
  * @see convert()
  */
 protected function convertViewHelperNode(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode $node)
 {
     $initializationPhpCode = '// Rendering ViewHelper ' . $node->getViewHelperClassName() . chr(10);
     // Build up $arguments array
     $argumentsVariableName = $this->variableName('arguments');
     $initializationPhpCode .= sprintf('%s = array();', $argumentsVariableName) . chr(10);
     $alreadyBuiltArguments = array();
     foreach ($node->getArguments() as $argumentName => $argumentValue) {
         $converted = $this->convert($argumentValue);
         $initializationPhpCode .= $converted['initialization'];
         $initializationPhpCode .= sprintf('%s[\'%s\'] = %s;', $argumentsVariableName, $argumentName, $converted['execution']) . chr(10);
         $alreadyBuiltArguments[$argumentName] = TRUE;
     }
     foreach ($node->getUninitializedViewHelper()->prepareArguments() as $argumentName => $argumentDefinition) {
         if (!isset($alreadyBuiltArguments[$argumentName])) {
             $initializationPhpCode .= sprintf('%s[\'%s\'] = %s;', $argumentsVariableName, $argumentName, var_export($argumentDefinition->getDefaultValue(), TRUE)) . chr(10);
         }
     }
     // Build up closure which renders the child nodes
     $renderChildrenClosureVariableName = $this->variableName('renderChildrenClosure');
     $initializationPhpCode .= sprintf('%s = %s;', $renderChildrenClosureVariableName, $this->wrapChildNodesInClosure($node)) . chr(10);
     if ($node->getUninitializedViewHelper() instanceof \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface) {
         // ViewHelper is compilable
         $viewHelperInitializationPhpCode = '';
         $convertedViewHelperExecutionCode = $node->getUninitializedViewHelper()->compile($argumentsVariableName, $renderChildrenClosureVariableName, $viewHelperInitializationPhpCode, $node, $this);
         $initializationPhpCode .= $viewHelperInitializationPhpCode;
         if ($convertedViewHelperExecutionCode !== self::SHOULD_GENERATE_VIEWHELPER_INVOCATION) {
             return array('initialization' => $initializationPhpCode, 'execution' => $convertedViewHelperExecutionCode);
         }
     }
     // ViewHelper is not compilable, so we need to instanciate it directly and render it.
     $viewHelperVariableName = $this->variableName('viewHelper');
     $initializationPhpCode .= sprintf('%s = $self->getViewHelper(\'%s\', $renderingContext, \'%s\');', $viewHelperVariableName, $viewHelperVariableName, $node->getViewHelperClassName()) . chr(10);
     $initializationPhpCode .= sprintf('%s->setArguments(%s);', $viewHelperVariableName, $argumentsVariableName) . chr(10);
     $initializationPhpCode .= sprintf('%s->setRenderingContext($renderingContext);', $viewHelperVariableName) . chr(10);
     $initializationPhpCode .= sprintf('%s->setRenderChildrenClosure(%s);', $viewHelperVariableName, $renderChildrenClosureVariableName) . chr(10);
     $initializationPhpCode .= '// End of ViewHelper ' . $node->getViewHelperClassName() . chr(10);
     return array('initialization' => $initializationPhpCode, 'execution' => sprintf('%s->initializeArgumentsAndRender()', $viewHelperVariableName));
 }
Exemplo n.º 5
0
 /**
  * @param array $arguments
  * @param array $variables
  * @param NodeInterface $childNode
  * @param string $extensionName
  * @param string $pluginName
  * @return AbstractViewHelper
  */
 protected function buildViewHelperInstance($arguments = array(), $variables = array(), $childNode = NULL, $extensionName = NULL, $pluginName = NULL)
 {
     $instance = $this->createInstance();
     /** @var TemplateVariableContainer $container */
     $container = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer');
     /** @var ViewHelperVariableContainer $viewHelperContainer */
     $viewHelperContainer = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer');
     if (0 < count($variables)) {
         ObjectAccess::setProperty($container, 'variables', $variables, TRUE);
     }
     $node = new ViewHelperNode($instance, $arguments);
     /** @var UriBuilder $uriBuilder */
     $uriBuilder = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
     /** @var 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 Response $response */
     $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
     /** @var ControllerContext $controllerContext */
     $controllerContext = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext');
     $controllerContext->setRequest($request);
     $controllerContext->setResponse($response);
     $controllerContext->setUriBuilder($uriBuilder);
     /** @var RenderingContext $renderingContext */
     $renderingContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext');
     $renderingContext->setControllerContext($controllerContext);
     ObjectAccess::setProperty($renderingContext, 'viewHelperVariableContainer', $viewHelperContainer, TRUE);
     ObjectAccess::setProperty($renderingContext, 'templateVariableContainer', $container, TRUE);
     $instance->setArguments($arguments);
     $instance->setRenderingContext($renderingContext);
     if (TRUE === $instance instanceof AbstractWidgetViewHelper) {
         /** @var WidgetContext $widgetContext */
         $widgetContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
         ObjectAccess::setProperty($instance, 'widgetContext', $widgetContext, TRUE);
     }
     if (NULL !== $childNode) {
         $node->addChildNode($childNode);
         if ($instance instanceof ChildNodeAccessInterface) {
             $instance->setChildNodes(array($childNode));
         }
     }
     $instance->setViewHelperNode($node);
     return $instance;
 }