Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 public function setUp()
 {
     $this->escapeInterceptor = $this->getAccessibleMock('NamelessCoder\\Fluid\\Core\\Parser\\Interceptor\\Escape', array('dummy'));
     $this->mockViewHelper = $this->getMockBuilder('NamelessCoder\\Fluid\\Core\\ViewHelper\\AbstractViewHelper')->disableOriginalConstructor()->getMock();
     $this->mockNode = $this->getMockBuilder('NamelessCoder\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode')->disableOriginalConstructor()->getMock();
     $this->mockParsingState = $this->getMockBuilder('NamelessCoder\\Fluid\\Core\\Parser\\ParsingState')->setMethods(array('getViewHelperResolver'))->disableOriginalConstructor()->getMock();
     $this->mockParsingState->expects($this->once())->method('getViewHelperResolver')->willReturn(new ViewHelperResolver());
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 /**
  * @test
  */
 public function testGenerateSectionCodeFromParsingState()
 {
     $foo = new TextNode('foo');
     $bar = new TextNode('bar');
     $parsingState = new ParsingState();
     $container = new StandardVariableProvider(array('sections' => array($foo, $bar)));
     $parsingState->setVariableProvider($container);
     $nodeConverter = $this->getMock('NamelessCoder\\Fluid\\Core\\Compiler\\NodeConverter', 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('NamelessCoder\\Fluid\\Core\\Compiler\\TemplateCompiler', 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);
 }
 /**
  * @test
  */
 public function testSetCompilableSetsProperty()
 {
     $this->parsingState->setCompilable(FALSE);
     $this->assertAttributeEquals(FALSE, 'compilable', $this->parsingState);
 }