/** * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node. * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body. * * @param NodeInterface $node * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point * @param ParsingState $parsingState the current parsing state. Not needed in this interceptor. * @return NodeInterface */ public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState) { $resolver = $parsingState->getViewHelperResolver(); if ($interceptorPosition === InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) { /** @var ViewHelperNode $node */ if (!$node->getUninitializedViewHelper()->isChildrenEscapingEnabled()) { $this->childrenEscapingEnabled = FALSE; $this->viewHelperNodesWhichDisableTheInterceptor[] = $node; } } elseif ($interceptorPosition === InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) { if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) { array_pop($this->viewHelperNodesWhichDisableTheInterceptor); if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) { $this->childrenEscapingEnabled = TRUE; } } /** @var ViewHelperNode $node */ if ($this->childrenEscapingEnabled && $node->getUninitializedViewHelper()->isOutputEscapingEnabled()) { $node = $this->wrapNode($node, $resolver, $parsingState); } } elseif ($this->childrenEscapingEnabled && $node instanceof ObjectAccessorNode) { $node = $this->wrapNode($node, $resolver, $parsingState); } return $node; }
public function setUp() { $this->escapeInterceptor = $this->getAccessibleMock('TYPO3Fluid\\Fluid\\Core\\Parser\\Interceptor\\Escape', array('dummy')); $this->mockViewHelper = $this->getMockBuilder('TYPO3Fluid\\Fluid\\Core\\ViewHelper\\AbstractViewHelper')->disableOriginalConstructor()->getMock(); $this->mockNode = $this->getMockBuilder('TYPO3Fluid\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode')->disableOriginalConstructor()->getMock(); $this->mockParsingState = $this->getMockBuilder('TYPO3Fluid\\Fluid\\Core\\Parser\\ParsingState')->setMethods(array('getViewHelperResolver'))->disableOriginalConstructor()->getMock(); $this->mockParsingState->expects($this->once())->method('getViewHelperResolver')->willReturn(new ViewHelperResolver()); }
/** * @return ParsingState */ protected function getParsingState() { $rootNode = new RootNode(); $variableProvider = $this->renderingContext->getVariableProvider(); $state = new ParsingState(); $state->setRootNode($rootNode); $state->pushNodeToStack($rootNode); $state->setVariableProvider($variableProvider->getScopeCopy($variableProvider->getAll())); return $state; }
/** * @test */ public function testSetCompilableSetsProperty() { $this->parsingState->setCompilable(FALSE); $this->assertAttributeEquals(FALSE, 'compilable', $this->parsingState); }
/** * @param ParsingState $parsingState * @return string */ protected function generateSectionCodeFromParsingState(ParsingState $parsingState) { $generatedRenderFunctions = ''; if ($parsingState->getVariableContainer()->exists('sections')) { $sections = $parsingState->getVariableContainer()->get('sections'); // TODO: refactor to $parsedTemplate->getSections() foreach ($sections as $sectionName => $sectionRootNode) { $generatedRenderFunctions .= $this->generateCodeForSection($this->nodeConverter->convertListOfSubNodes($sectionRootNode), 'section_' . sha1($sectionName), 'section ' . $sectionName); } } return $generatedRenderFunctions; }
/** * @test */ public function testGenerateSectionCodeFromParsingState() { $foo = new TextNode('foo'); $bar = new TextNode('bar'); $parsingState = new ParsingState(); $container = new StandardVariableProvider(array('1457379500_sections' => array($foo, $bar))); $parsingState->setVariableProvider($container); $nodeConverter = $this->getMock(NodeConverter::class, array('convertListOfSubNodes'), array(), '', FALSE); $nodeConverter->expects($this->at(0))->method('convertListOfSubNodes')->with($foo)->willReturn(array()); $nodeConverter->expects($this->at(1))->method('convertListOfSubNodes')->with($bar)->willReturn(array()); $instance = $this->getMock(TemplateCompiler::class, array('generateCodeForSection')); $instance->expects($this->at(0))->method('generateCodeForSection')->with($this->anything())->willReturn('FOO'); $instance->expects($this->at(1))->method('generateCodeForSection')->with($this->anything())->willReturn('BAR'); $instance->setNodeConverter($nodeConverter); $method = new \ReflectionMethod($instance, 'generateSectionCodeFromParsingState'); $method->setAccessible(TRUE); $result = $method->invokeArgs($instance, array($parsingState)); $this->assertEquals('FOOBAR', $result); }
/** * @return ParsingState */ protected function getParsingState() { $rootNode = new RootNode(); $state = new ParsingState(); $state->setVariableProvider($this->variableProvider); $state->setViewHelperResolver($this->viewHelperResolver); $state->setRootNode($rootNode); $state->pushNodeToStack($rootNode); return $state; }