public function testParse() { // fixture token and stream $startToken = new \Twig_Token(\Twig_Token::NAME_TYPE, self::TAG_NAME, 31); $stream = new \Twig_TokenStream(array(new \Twig_Token(\Twig_Token::NAME_TYPE, 'filter', 31), new \Twig_Token(\Twig_Token::OPERATOR_TYPE, '=', 31), new \Twig_Token(\Twig_Token::STRING_TYPE, 'cssrewrite, lessphp, ?cssmin', 31), new \Twig_Token(\Twig_Token::NAME_TYPE, 'debug', 31), new \Twig_Token(\Twig_Token::OPERATOR_TYPE, '=', 31), new \Twig_Token(\Twig_Token::NAME_TYPE, 'false', 31), new \Twig_Token(\Twig_Token::NAME_TYPE, 'combine', 31), new \Twig_Token(\Twig_Token::OPERATOR_TYPE, '=', 31), new \Twig_Token(\Twig_Token::NAME_TYPE, 'false', 31), new \Twig_Token(\Twig_Token::NAME_TYPE, 'output', 31), new \Twig_Token(\Twig_Token::OPERATOR_TYPE, '=', 31), new \Twig_Token(\Twig_Token::STRING_TYPE, 'css/demo.css', 31), new \Twig_Token(\Twig_Token::BLOCK_END_TYPE, '', 31), new \Twig_Token(\Twig_Token::BLOCK_END_TYPE, '', 32), new \Twig_Token(\Twig_Token::BLOCK_START_TYPE, '', 33), new \Twig_Token(\Twig_Token::NAME_TYPE, 'end' . self::TAG_NAME, 33), new \Twig_Token(\Twig_Token::BLOCK_END_TYPE, '', 33), new \Twig_Token(\Twig_Token::EOF_TYPE, '', 31))); $bodyNode = $this->getMockBuilder('\\Twig_Node')->disableOriginalConstructor()->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\Twig_Parser $parser */ $parser = $this->getMockBuilder('Twig_Parser')->disableOriginalConstructor()->getMock(); $parser->expects($this->once())->method('subparse')->will($this->returnValue($bodyNode)); $parser->expects($this->once())->method('getStream')->will($this->returnValue($stream)); $this->assetFactory->expects($this->exactly(2))->method('createAsset')->willReturnCallback(function () { // frontend theme during assets compilation $this->assertEquals(ThemeListener::FRONTEND_THEME, $this->themeRegistry->getActiveTheme()->getName()); return new AssetCollection(); }); $this->assetsConfiguration->expects($this->at(0))->method('getCssFiles')->with(false)->willReturn([]); $this->assetsConfiguration->expects($this->at(1))->method('getCssFiles')->with(true)->willReturn([]); // active theme before parsing $this->assertEquals(self::ACTIVE_THEME, $this->themeRegistry->getActiveTheme()->getName()); $this->parser->setParser($parser); $resultNode = $this->parser->parse($startToken); // active theme after parsing $this->assertEquals(self::ACTIVE_THEME, $this->themeRegistry->getActiveTheme()->getName()); $this->assertEquals(31, $resultNode->getLine()); $nodes = $resultNode->getIterator()->getArrayCopy(); $this->assertCount(2, $nodes); }
public function testParseBrokenStream() { $parser = $this->getMockBuilder('Twig_Parser')->disableOriginalConstructor()->getMock(); $brokenStream = new Twig_TokenStream(array(new Twig_Token(Twig_Token::NAME_TYPE, 'bad', 31), new Twig_Token(Twig_Token::OPERATOR_TYPE, '=', 31), new Twig_Token(Twig_Token::STRING_TYPE, 'bad value', 31))); $parser->expects($this->once())->method('getStream')->will($this->returnValue($brokenStream)); $this->parser->setParser($parser); $this->setExpectedException('Twig_Error_Syntax'); $this->parser->parse(new Twig_Token(Twig_Token::NAME_TYPE, 'oro_css', 31)); }
/** * {@inheritdoc} */ protected function createDebugAsseticNode(\Twig_NodeInterface $body, array $filters, array $attributes, $lineno) { $currentTheme = $this->themeRegistry->getActiveTheme()->getName(); $this->themeRegistry->setActiveTheme(ThemeListener::FRONTEND_THEME); $node = parent::createDebugAsseticNode($body, $filters, $attributes, $lineno); $this->themeRegistry->setActiveTheme($currentTheme); return $node; }