Example #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', [], [], '', 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', [], [], '', 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', [], [], '', 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);
 }
Example #2
0
 public function testProcess()
 {
     $expectedContent = 'updated content';
     $tmpFile = 'tmp/file.ext';
     $this->fileGenerator->expects($this->once())->method('generateFileTree')->with($this->chain)->will($this->returnValue($tmpFile));
     $this->adapter->expects($this->once())->method('process')->with($tmpFile)->will($this->returnValue($expectedContent));
     $this->object->process($this->chain);
     $this->assertEquals($expectedContent, $this->chain->getContent());
     $this->assertEquals('css', $this->chain->getContentType());
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain)
 {
     $chain->setContentType('less');
     $tmpLessFile = $this->fileGenerator->generateFileTree($chain);
     $cssContent = $this->adapter->process($tmpLessFile);
     $cssTrimmedContent = trim($cssContent);
     if (!empty($cssTrimmedContent)) {
         $chain->setContent($cssContent);
     }
     $chain->setContentType('css');
 }
 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));
 }
 /**
  * Launch application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     $this->state->setAreaCode($this->params->getArea());
     $this->objectManager->configure($this->configLoader->load($this->params->getArea()));
     $sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt());
     foreach ($this->params->getFiles() as $file) {
         $file .= '.' . $this->params->getExt();
         $this->logger->logMessage("Gathering {$file} sources.");
         $asset = $this->assetRepo->createAsset($file, ['area' => $this->params->getArea(), 'theme' => $this->params->getTheme(), 'locale' => $this->params->getLocale()]);
         $sourceFile = $this->assetSource->findSource($asset);
         $content = \file_get_contents($sourceFile);
         $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType()]);
         $processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
         $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
         $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
         $source = $rootDir->getRelativePath($processedCoreFile);
         $destination = $asset->getPath();
         $rootDir->copyFile($source, $destination, $targetDir);
         $this->logger->logMessage("Done");
     }
     $this->response->setCode(Response::SUCCESS);
     return $this->response;
 }