Esempio 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);
 }
Esempio n. 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 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));
 }
Esempio n. 4
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;
 }