Example #1
0
 protected function setUp()
 {
     $this->notationResolver = $this->getMock('\\Magento\\Framework\\View\\Asset\\NotationResolver\\Module', [], [], '', false);
     $this->asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $this->asset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
     $this->object = new \Magento\Framework\Css\PreProcessor\Instruction\Import($this->notationResolver);
 }
Example #2
0
 /**
  * @inheritdoc
  * @throws ContentProcessorException
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         $tmpFilePath = $this->temporaryFile->createFile($path, $content);
         gc_disable();
         $parser->parseFile($tmpFilePath, '');
         $content = $parser->getCss();
         gc_enable();
         if (trim($content) === '') {
             $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
             $this->logger->critical($errorMessage);
             throw new ContentProcessorException(new Phrase($errorMessage));
         }
         return $content;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         throw new ContentProcessorException(new Phrase($errorMessage));
     }
 }
Example #3
0
 protected function setUp()
 {
     $this->notationResolver = $this->getMock('\\Magento\\Framework\\View\\Asset\\NotationResolver\\Module', [], [], '', false);
     $this->asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $this->asset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
     $this->relatedFileGeneratorMock = $this->getMockBuilder(RelatedGenerator::class)->disableOriginalConstructor()->getMock();
     $this->object = new Import($this->notationResolver, $this->relatedFileGeneratorMock);
 }
Example #4
0
 /**
  * @param string $assetRelPath
  * @param string $relatedFieldId
  * @param string $similarRelPath
  * @param string $expectedResult
  * @dataProvider convertModuleNotationToPathModularSeparatorDataProvider
  */
 public function testConvertModuleNotationToPathModularSeparator($assetRelPath, $relatedFieldId, $similarRelPath, $expectedResult)
 {
     $similarAsset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $similarAsset->expects($this->any())->method('getPath')->will($this->returnValue($similarRelPath));
     $this->asset->expects($this->once())->method('getPath')->will($this->returnValue($assetRelPath));
     $this->assetRepo->expects($this->once())->method('createSimilar')->with($relatedFieldId, $this->asset)->will($this->returnValue($similarAsset));
     $this->assertEquals($expectedResult, $this->object->convertModuleNotationToPath($this->asset, $relatedFieldId));
 }
 protected function setUp()
 {
     $this->mergerMock = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\MergeStrategyInterface');
     $this->dirMock = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $filesystem = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false);
     $filesystem->expects($this->once())->method('getDirectoryRead')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dirMock));
     $this->fileExists = new FileExists($this->mergerMock, $filesystem);
     $this->resultAsset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('foo/file'));
 }
 protected function setUp()
 {
     $this->design = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\DesignInterface');
     $this->fileSource = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\File\\CollectorInterface');
     $this->errorHandler = $this->getMockForAbstractClass('\\Magento\\Framework\\Less\\PreProcessor\\ErrorHandlerInterface');
     $this->asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $this->asset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
     $this->assetRepo = $this->getMock('\\Magento\\Framework\\View\\Asset\\Repository', [], [], '', false);
     $this->themeList = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\Theme\\ListInterface');
     $this->object = new \Magento\Framework\Less\PreProcessor\Instruction\MagentoImport($this->design, $this->fileSource, $this->errorHandler, $this->assetRepo, $this->themeList);
 }
 protected function setUp()
 {
     $this->design = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\DesignInterface');
     $this->fileSource = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\File\\CollectorInterface');
     $this->errorHandler = $this->getMockForAbstractClass('\\Magento\\Framework\\Css\\PreProcessor\\ErrorHandlerInterface');
     $this->asset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $this->asset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
     $this->assetRepo = $this->getMock('\\Magento\\Framework\\View\\Asset\\Repository', [], [], '', false);
     $this->themeProvider = $this->getMock(ThemeProviderInterface::class);
     $this->object = (new ObjectManager($this))->getObject(MagentoImport::class, ['design' => $this->design, 'fileSource' => $this->fileSource, 'errorHandler' => $this->errorHandler, 'assetRepo' => $this->assetRepo, 'themeProvider' => $this->themeProvider]);
 }
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $scssIn = $this->assetSource->getContent($asset);
         $compiler = new \Leafo\ScssPhp\Compiler();
         $cssOut = $compiler->compile($scssIn);
         return $cssOut;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
     }
 }
Example #9
0
 /**
  * Process file content
  *
  * @param File $asset
  * @return string
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $compiler = new \scssc();
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         return $compiler->compile($content);
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         return $errorMessage;
     }
 }
Example #10
0
 /**
  * @covers \Magento\Cms\Model\Wysiwyg\Config::getSkinImagePlaceholderPath
  */
 public function testGetSkinImagePlaceholderPath()
 {
     $staticPath = 'pub/static';
     $placeholderPath = 'adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
     $expectedResult = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->any())->method('getBaseStaticDir')->willReturn($staticPath);
     $this->assetRepoMock->expects($this->any())->method('createAsset')->with(\Magento\Cms\Model\Wysiwyg\Config::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->willReturn($this->assetFileMock);
     $this->assetFileMock->expects($this->once())->method('getPath')->willReturn($placeholderPath);
     $this->assertEquals($expectedResult, $this->wysiwygConfig->getSkinImagePlaceholderPath());
 }
 /**
  * Create mocks of assets to merge, as well as a few related necessary mocks
  *
  * @return array
  */
 private function getAssetsToMerge()
 {
     $one = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $one->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/one.txt'));
     $two = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $two->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/two.txt'));
     $this->sourceDir->expects($this->exactly(2))->method('getRelativePath')->will($this->onConsecutiveCalls('file/one.txt', 'file/two.txt'));
     $this->sourceDir->expects($this->exactly(2))->method('stat')->will($this->returnValue(['mtime' => '1']));
     $this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('merged/result.txt'));
     return [$one, $two];
 }
Example #12
0
 public function testSimpleGetters()
 {
     $this->assertEquals('dir/file.css', $this->object->getFilePath());
     $this->assertSame($this->context, $this->object->getContext());
     $this->assertEquals('Magento_Module', $this->object->getModule());
 }