Example #1
0
 /**
  * @covers \Magento\Framework\Less\PreProcessor\Instruction\Import::resetRelatedFiles
  */
 public function testGetRelatedFiles()
 {
     $this->assertSame([], $this->object->getRelatedFiles());
     $this->notationResolver->expects($this->once())->method('convertModuleNotationToPath')->with($this->asset, 'Magento_Module::something.css')->will($this->returnValue('Magento_Module/something.css'));
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, '@import (type) "Magento_Module::something.css" media;', 'css');
     $this->object->process($chain);
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, 'color: #000000;', 'css');
     $this->object->process($chain);
     $expected = [['Magento_Module::something.css', $this->asset]];
     $this->assertSame($expected, $this->object->getRelatedFiles());
     $this->object->resetRelatedFiles();
     $this->assertSame([], $this->object->getRelatedFiles());
 }
Example #2
0
 /**
  * Create a tree of self-sustainable files and return the topmost LESS file, ready for passing to 3rd party library
  *
  * @param \Magento\Framework\View\Asset\PreProcessor\Chain $chain
  * @return string Absolute path of generated LESS file
  */
 public function generateLessFileTree(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
 {
     /**
      * @bug This logic is duplicated at \Magento\Framework\View\Asset\PreProcessor\Pool::getPreProcessors()
      * If you need to extend or modify behavior of LESS preprocessing, you must account for both places
      */
     $this->magentoImportProcessor->process($chain);
     $this->importProcessor->process($chain);
     $this->generateRelatedFiles();
     $lessRelativePath = preg_replace('#\\.css$#', '.less', $chain->getAsset()->getPath());
     $tmpFilePath = $this->createFile($lessRelativePath, $chain->getContent());
     return $tmpFilePath;
 }
 public function testProcessException()
 {
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, '//@magento_import "some/file.css";', 'css');
     $exception = new \LogicException('Error happened');
     $this->assetRepo->expects($this->once())->method('createRelated')->will($this->throwException($exception));
     $this->errorHandler->expects($this->once())->method('processException')->with($exception);
     $this->object->process($chain);
     $this->assertEquals('', $chain->getContent());
     $this->assertEquals('css', $chain->getContentType());
 }
 /**
  * Create a tree of self-sustainable files and return the topmost LESS file, ready for passing to 3rd party library
  *
  * @param Chain $chain
  * @return string Absolute path of generated LESS file
  */
 public function generateFileTree(Chain $chain)
 {
     /**
      * @bug This logic is duplicated at \Magento\Framework\View\Asset\PreProcessor\Pool
      * If you need to extend or modify behavior of LESS preprocessing, you must account for both places
      */
     /**
      * wait if generation process has already started
      */
     while ($this->isProcessLocked()) {
         sleep(1);
     }
     $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE;
     $this->tmpDirectory->writeFile($lockFilePath, time());
     $this->magentoImportProcessor->process($chain);
     $this->importProcessor->process($chain);
     $this->relatedGenerator->generate($this->importProcessor);
     $lessRelativePath = preg_replace('#\\.css$#', '.less', $chain->getAsset()->getPath());
     $tmpFilePath = $this->temporaryFile->createFile($lessRelativePath, $chain->getContent());
     $this->tmpDirectory->delete($lockFilePath);
     return $tmpFilePath;
 }