Ejemplo n.º 1
0
 /**
  * Replace @magento_import to @import less instructions
  *
  * @param array $matchedContent
  * @param LocalInterface $asset
  * @return string
  */
 protected function replace(array $matchedContent, LocalInterface $asset)
 {
     $importsContent = '';
     try {
         $matchedFileId = $matchedContent['path'];
         $relatedAsset = $this->assetRepo->createRelated($matchedFileId, $asset);
         $resolvedPath = $relatedAsset->getFilePath();
         $importFiles = $this->fileSource->getFiles($this->getTheme($relatedAsset), $resolvedPath);
         /** @var $importFile \Magento\Framework\View\File */
         foreach ($importFiles as $importFile) {
             $importsContent .= $importFile->getModule() ? "@import '{$importFile->getModule()}::{$resolvedPath}';\n" : "@import '{$matchedFileId}';\n";
         }
     } catch (\LogicException $e) {
         $this->errorHandler->processException($e);
     }
     return $importsContent;
 }
Ejemplo n.º 2
0
 /**
  * @param string $filePath
  * @param string $resultFilePath
  * @param string $module
  * @return void
  * @dataProvider createRelatedDataProvider
  */
 public function testCreateRelated($filePath, $resultFilePath, $module)
 {
     $originalContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\ContextInterface')->disableOriginalConstructor()->getMock();
     $originalAssetMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File')->disableOriginalConstructor()->setMethods(['getModule', 'getContext'])->getMock();
     $originalAssetMock->expects($this->any())->method('getContext')->willReturn($originalContextMock);
     $assetMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File')->disableOriginalConstructor()->getMock();
     $this->fileFactoryMock->expects($this->once())->method('create')->with(['source' => $this->sourceMock, 'context' => $originalContextMock, 'filePath' => $resultFilePath, 'module' => $module, 'contentType' => ''])->willReturn($assetMock);
     $this->assertEquals($assetMock, $this->repository->createRelated($filePath, $originalAssetMock));
 }
Ejemplo n.º 3
0
 /**
  * @param string $fileId
  * @param string $relFilePath
  * @param string $relModule
  * @param string $expFilePath
  * @param string $expType
  * @param string $expModule
  * @dataProvider createRelatedDataProvider
  */
 public function testCreateRelated($fileId, $relFilePath, $relModule, $expFilePath, $expType, $expModule)
 {
     $relativeTo = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface');
     $context = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\ContextInterface');
     $relativeTo->expects($this->once())->method('getContext')->will($this->returnValue($context));
     $relativeTo->expects($this->any())->method('getModule')->will($this->returnValue($relModule));
     $relativeTo->expects($this->any())->method('getFilePath')->will($this->returnValue($relFilePath));
     $asset = $this->object->createRelated($fileId, $relativeTo);
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File', $asset);
     $this->assertSame($context, $asset->getContext());
     $this->assertEquals($expFilePath, $asset->getFilePath());
     $this->assertEquals($expType, $asset->getContentType());
     $this->assertEquals($expModule, $asset->getModule());
 }
Ejemplo n.º 4
0
 /**
  * Create file, referenced relatively to an asset
  *
  * @param string $relatedFileId
  * @param LocalInterface $asset
  * @return \Magento\Framework\View\Asset\File
  */
 protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
 {
     $relatedAsset = $this->assetRepo->createRelated($relatedFileId, $asset);
     $this->temporaryFile->createFile($relatedAsset->getPath(), $relatedAsset->getContent());
     return $relatedAsset;
 }