/**
  * @test
  */
 public function processDisablesEscapingInterceptorIfViewHelperDisablesIt()
 {
     $interceptorPosition = \TYPO3\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'));
 }
 /**
  * @test
  */
 public function processReenablesEscapingInterceptorOnClosingViewHelperTagIfItWasDisabledBefore()
 {
     $interceptorPosition = InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER;
     $this->mockViewHelper->expects($this->any())->method('isOutputEscapingEnabled')->will($this->returnValue(false));
     $this->mockNode->expects($this->any())->method('getUninitializedViewHelper')->will($this->returnValue($this->mockViewHelper));
     $this->escapeInterceptor->_set('childrenEscapingEnabled', false);
     $this->escapeInterceptor->_set('viewHelperNodesWhichDisableTheInterceptor', array($this->mockNode));
     $this->escapeInterceptor->process($this->mockNode, $interceptorPosition, $this->mockParsingState);
     $this->assertTrue($this->escapeInterceptor->_get('childrenEscapingEnabled'));
 }
 /**
  * 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);
 }
 /**
  * @test
  */
 public function multipleEvaluateCallsShareTheSameViewHelperInstance()
 {
     /** @var AbstractViewHelper|\PHPUnit_Framework_MockObject_MockObject $mockViewHelper */
     $mockViewHelper = $this->getMock('TYPO3\\Fluid\\Core\\ViewHelper\\AbstractViewHelper', array('render', 'validateArguments', 'prepareArguments', 'setViewHelperVariableContainer'));
     $mockViewHelper->expects($this->exactly(2))->method('render')->will($this->returnValue('String'));
     $viewHelperNode = new ViewHelperNode($mockViewHelper, array());
     $viewHelperNode->evaluate($this->renderingContext);
     $viewHelperNode->evaluate($this->renderingContext);
     // dummy assertion to avoid "risky test" warning
     $this->assertTrue(TRUE);
 }
 /**
  * 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 ViewHelperNode $node
  * @return array
  * @see convert()
  */
 protected function convertViewHelperNode(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;
     }
     /** @var $argumentDefinition ArgumentDefinition */
     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 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));
 }