Ejemplo n.º 1
0
 public function testGenerateLessFileTree()
 {
     $originalContent = 'original content';
     $expectedContent = 'updated content';
     $expectedRelativePath = 'view_preprocessed/less/some/file.less';
     $expectedPath = '/var/view_preprocessed/less/some/file.less';
     $asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false);
     $asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css'));
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($asset, $originalContent, 'less');
     $this->magentoImport->expects($this->once())->method('process')->with($chain);
     $this->import->expects($this->once())->method('process')->with($chain);
     $relatedAssetOne = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false);
     $relatedAssetOne->expects($this->any())->method('getPath')->will($this->returnValue('related/file_one.css'));
     $relatedAssetOne->expects($this->any())->method('getContent')->will($this->returnValue("content of 'related/file_one.css'"));
     $relatedAssetTwo = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', array(), array(), '', false);
     $relatedAssetTwo->expects($this->any())->method('getPath')->will($this->returnValue('related/file_two.css'));
     $relatedAssetTwo->expects($this->any())->method('getContent')->will($this->returnValue("content of 'related/file_two.css'"));
     $assetsMap = [['related/file_one.css', $asset, $relatedAssetOne], ['related/file_two.css', $asset, $relatedAssetTwo]];
     $this->assetRepo->expects($this->any())->method('createRelated')->will($this->returnValueMap($assetsMap));
     $relatedFilesOne = [['related/file_one.css', $asset]];
     $this->import->expects($this->at(1))->method('getRelatedFiles')->will($this->returnValue($relatedFilesOne));
     $relatedFilesTwo = [['related/file_two.css', $asset]];
     $this->import->expects($this->at(3))->method('getRelatedFiles')->will($this->returnValue($relatedFilesTwo));
     $this->import->expects($this->at(5))->method('getRelatedFiles')->will($this->returnValue([]));
     $writeMap = [[$expectedRelativePath, $expectedContent], ['related/file_one.css', "content of 'related/file_one.css'"], ['related/file_two.css', "content of 'related/file_two.css'"]];
     $pathsMap = [[$expectedRelativePath, $expectedPath], ['related/file_one.css', '/var/view_preprocessed/less/related/file_one.css'], ['related/file_two.css', '/var/view_preprocessed/less/related/file_two.css']];
     $this->tmpDirectory->expects($this->any())->method('writeFile')->will($this->returnValueMap($writeMap));
     $this->tmpDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap($pathsMap));
     $actual = $this->object->generateLessFileTree($chain);
     $this->assertSame($expectedPath, $actual);
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
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());
 }
Ejemplo n.º 4
0
 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());
 }
Ejemplo n.º 5
0
 public function testGenerateLessFileTree()
 {
     $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);
     $this->temporaryFile->expects($this->once())->method('createFile')->with($expectedRelativePath, $expectedContent)->willReturn($expectedPath);
     $this->assertSame($expectedPath, $this->object->generateFileTree($chain));
 }
Ejemplo n.º 6
0
 /**
  * Create all asset files, referenced from already processed ones
  *
  * @return void
  */
 protected function generateRelatedFiles()
 {
     do {
         $relatedFiles = $this->importProcessor->getRelatedFiles();
         $this->importProcessor->resetRelatedFiles();
         foreach ($relatedFiles as $relatedFileInfo) {
             list($relatedFileId, $asset) = $relatedFileInfo;
             $this->generateRelatedFile($relatedFileId, $asset);
         }
     } while ($relatedFiles);
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }