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);
 }
Exemplo n.º 2
0
 /**
  * @param LoadCssEvent $event
  */
 public function onLoadCss(LoadCssEvent $event)
 {
     $activeTheme = $this->themeRegistry->getActiveTheme();
     if ($activeTheme) {
         $event->addCss('theme', $activeTheme->getStyles());
     }
 }
 /**
  * {@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;
 }
Exemplo n.º 4
0
 public function testGetActiveTheme()
 {
     $this->assertNull($this->themeRegistry->getActiveTheme());
     $this->themeRegistry->setActiveTheme('foo');
     $activeTheme = $this->themeRegistry->getActiveTheme();
     $this->assertInstanceOf('Oro\\Bundle\\ThemeBundle\\Model\\Theme', $activeTheme);
     $this->assertEquals('foo', $activeTheme->getName());
 }
Exemplo n.º 5
0
 /**
  * Get theme icon
  *
  * @return string
  */
 public function getThemeIcon()
 {
     $result = '';
     $activeTheme = $this->themeRegistry->getActiveTheme();
     if ($activeTheme) {
         $result = $activeTheme->getIcon();
     }
     return $result;
 }
 /**
  * @param boolean $installed
  * @param int $requestType
  * @param boolean $isFrontendRequest
  * @param string $expectedTheme
  *
  * @dataProvider onKernelRequestProvider
  */
 public function testOnKernelRequest($installed, $requestType, $isFrontendRequest, $expectedTheme)
 {
     $this->themeRegistry->setActiveTheme('oro');
     $request = new Request();
     $event = new GetResponseEvent($this->kernel, $request, $requestType);
     $this->helper->expects($this->any())->method('isFrontendRequest')->with($request)->willReturn($isFrontendRequest);
     $listener = new ThemeListener($this->themeRegistry, $this->helper, $installed);
     $listener->onKernelRequest($event);
     $this->assertEquals($expectedTheme, $this->themeRegistry->getActiveTheme()->getName());
 }
Exemplo n.º 7
0
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$this->installed) {
         return;
     }
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     if ($this->helper->isFrontendRequest($event->getRequest())) {
         $this->themeRegistry->setActiveTheme(self::FRONTEND_THEME);
     }
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $themes = $this->themeRegistry->getAllThemes();
     $activeTheme = $this->themeRegistry->getActiveTheme();
     if ($themes) {
         $output->writeln('<info>List of available themes:</info>');
         foreach ($themes as $theme) {
             $this->outputTheme($output, $theme, $theme === $activeTheme);
         }
     } else {
         $output->writeln('<info>No themes are available.</info>');
     }
 }
Exemplo n.º 9
0
 /**
  * @param string $theme
  * @param bool $isDefaultTheme
  * @param bool $isDemoTheme
  *
  * @dataProvider isThemeDataProvider
  */
 public function testIsTheme($theme, $isDefaultTheme, $isDemoTheme)
 {
     $this->themeRegistry->setActiveTheme($theme);
     $this->assertEquals($isDefaultTheme, $this->filter->isDefaultTheme());
     $this->assertEquals($isDemoTheme, $this->filter->isDemoTheme());
 }
Exemplo n.º 10
0
 /**
  * @return bool
  */
 public function isDemoTheme()
 {
     $activeTheme = $this->themeRegistry->getActiveTheme();
     return $activeTheme ? $activeTheme->getName() === ThemeListener::FRONTEND_THEME : false;
 }