/**
  * Create all asset files, referenced from already processed ones
  *
  * @param Import $importGenerator
  *
  * @return void
  */
 public function generate(Import $importGenerator)
 {
     do {
         $relatedFiles = $importGenerator->getRelatedFiles();
         $importGenerator->resetRelatedFiles();
         foreach ($relatedFiles as $relatedFileInfo) {
             list($relatedFileId, $asset) = $relatedFileInfo;
             $this->generateRelatedFile($relatedFileId, $asset);
         }
     } while ($relatedFiles);
 }
Example #2
0
 /**
  * @covers \Magento\Framework\Css\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', 'path');
     $this->object->process($chain);
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, 'color: #000000;', 'css', 'path');
     $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());
 }
 public function testProcessException()
 {
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, '//@magento_import "some/file.css";', 'css', 'path');
     $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());
 }
 public function testGenerateFileTree()
 {
     $lessDirectory = 'path/to/less';
     $expectedContent = 'updated content';
     $expectedRelativePath = 'some/file.less';
     $expectedPath = $lessDirectory . '/some/file.less';
     $asset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $chain = $this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false);
     $this->config->expects($this->any())->method('getLessDirectory')->willReturn($lessDirectory);
     $this->tmpDirectory->expects($this->once())->method('isExist')->willReturn(true);
     $this->magentoImport->expects($this->once())->method('process')->with($chain);
     $this->import->expects($this->once())->method('process')->with($chain);
     $this->relatedGenerator->expects($this->once())->method('generate')->with($this->import);
     $asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css'));
     $chain->expects($this->once())->method('getContent')->willReturn($expectedContent);
     $chain->expects($this->once())->method('getAsset')->willReturn($asset);
     $chain->expects($this->once())->method('getContentType')->willReturn('less');
     $this->temporaryFile->expects($this->once())->method('createFile')->with($expectedRelativePath, $expectedContent)->willReturn($expectedPath);
     $this->assertSame($expectedPath, $this->object->generateFileTree($chain));
 }
 /**
  * Create a tree of self-sustainable files and return the topmost source file,
  * ready for passing to 3rd party library
  *
  * @param Chain $chain
  * @return string Absolute path of generated topmost source file
  */
 public function generateFileTree(Chain $chain)
 {
     /**
      * wait if generation process has already started
      */
     while ($this->isProcessLocked()) {
         sleep(1);
     }
     $lockFilePath = $this->config->getMaterializationRelativePath() . '/' . self::LOCK_FILE;
     $this->tmpDirectory->writeFile($lockFilePath, time());
     $this->magentoImportProcessor->process($chain);
     $this->importProcessor->process($chain);
     $this->relatedGenerator->generate($this->importProcessor);
     $contentType = $chain->getContentType();
     $relativePath = preg_replace('#\\.css$#', '.' . $contentType, $chain->getAsset()->getPath());
     $tmpFilePath = $this->temporaryFile->createFile($relativePath, $chain->getContent());
     $this->tmpDirectory->delete($lockFilePath);
     return $tmpFilePath;
 }