Ejemplo n.º 1
0
 public function testGetFile()
 {
     $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $expected = 'some/file.ext';
     $this->resolver->expects($this->once())->method('resolve')->with(RulePool::TYPE_STATIC_FILE, 'file.ext', 'frontend', $theme, 'en_US', 'Magento_Module')->will($this->returnValue($expected));
     $actual = $this->object->getFile('frontend', $theme, 'en_US', 'file.ext', 'Magento_Module');
     $this->assertSame($expected, $actual);
 }
Ejemplo n.º 2
0
 public function testGetViewFile()
 {
     $params = ['area' => 'some_area', 'themeModel' => $this->getMock('Magento\\Framework\\View\\Design\\ThemeInterface', [], [], '', false, false), 'locale' => 'some_locale', 'module' => 'Some_Module'];
     $file = 'Some_Module::some_file.ext';
     $expected = 'path/to/some_file.ext';
     $this->_staticFileResolution->expects($this->once())->method('getFile')->with($params['area'], $params['themeModel'], $params['locale'], 'some_file.ext', 'Some_Module')->will($this->returnValue($expected));
     $actual = $this->_model->getStaticFileName($file, $params);
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 3
0
 /**
  * Find a static view file using fallback mechanism
  *
  * @param string $fileId
  * @param array $params
  * @return string
  */
 public function getStaticFileName($fileId, array $params = [])
 {
     list($module, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule($this->normalizePath($fileId));
     if ($module) {
         $params['module'] = $module;
     }
     $this->_assetRepo->updateDesignParams($params);
     return $this->_staticFileResolution->getFile($params['area'], $params['themeModel'], $params['locale'], $filePath, $params['module']);
 }
Ejemplo n.º 4
0
 /**
  * @param $origFile
  * @param $origPath
  * @param $origContent
  * @param $isMaterialization
  *
  * @dataProvider getFileDataProvider
  */
 public function testGetFile($origFile, $origPath, $origContent, $isMaterialization)
 {
     $filePath = 'some/file.ext';
     $this->viewFileResolution->expects($this->once())->method('getFile')->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')->will($this->returnValue($origFile));
     $this->rootDirRead->expects($this->once())->method('getRelativePath')->with($origFile)->will($this->returnValue($origPath));
     $this->rootDirRead->expects($this->once())->method('readFile')->with($origPath)->will($this->returnValue($origContent));
     $this->preProcessorPool->expects($this->once())->method('process')->with($this->chain);
     if ($isMaterialization) {
         $this->chain->expects($this->once())->method('isChanged')->willReturn(true);
         $this->chain->expects($this->once())->method('getContent')->willReturn('processed');
         $this->chain->expects($this->once())->method('getTargetAssetPath')->willReturn($filePath);
         $this->varDir->expects($this->once())->method('writeFile')->with('view_preprocessed/source/some/file.ext', 'processed');
         $this->varDir->expects($this->once())->method('getAbsolutePath')->with('view_preprocessed/source/some/file.ext')->will($this->returnValue('result'));
     } else {
         $this->varDir->expects($this->never())->method('writeFile');
         $this->rootDirRead->expects($this->once())->method('getAbsolutePath')->with('source/some/file.ext')->will($this->returnValue('result'));
     }
     $this->assertSame('result', $this->object->getFile($this->getAsset()));
 }
Ejemplo n.º 5
0
 /**
  * Get static file through fallback system using specified params
  *
  * @param string $area
  * @param string|\Magento\Framework\View\Design\ThemeInterface $theme - either theme path (string) or theme object
  * @param string $locale
  * @param string $filePath
  * @param string $module
  * @param bool $isExplicit
  * @return bool|string
  */
 private function getStaticFile($area, $theme, $locale, $filePath, $module, $isExplicit = false)
 {
     if (!is_object($theme)) {
         $themePath = $theme ?: $this->getDefaultThemePath($area);
         $theme = $this->themeRepo->create($themePath, $area);
     }
     if ($isExplicit) {
         $type = \Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE;
         return $this->explicitFallback->resolve($type, $filePath, $area, $theme, $locale, $module);
     }
     return $this->fallback->getFile($area, $theme, $locale, $filePath, $module);
 }
Ejemplo n.º 6
0
 /**
  * Find asset file via fallback mechanism
  *
  * @param LocalInterface $asset
  * @param \Magento\Framework\View\Asset\File\FallbackContext $context
  * @return bool|string
  */
 private function findFileThroughFallback(
     LocalInterface $asset,
     \Magento\Framework\View\Asset\File\FallbackContext $context
 ) {
     $themeModel = $this->themeList->getThemeByFullPath($context->getAreaCode() . '/' . $context->getThemePath());
     $sourceFile = $this->fallback->getFile(
         $context->getAreaCode(),
         $themeModel,
         $context->getLocale(),
         $asset->getFilePath(),
         $asset->getModule()
     );
     return $sourceFile;
 }
Ejemplo n.º 7
0
 /**
  * Resolves file to find its fallback'ed paths
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @param string $file
  * @return array
  */
 protected function _getFileResolutions(\Magento\Framework\View\Design\ThemeInterface $theme, $file)
 {
     $found = array();
     $fileResolved = self::$_filesFallback->getFile($theme->getArea(), $theme, $file);
     if (file_exists($fileResolved)) {
         $found[$fileResolved] = $fileResolved;
     }
     foreach (self::$_checkThemeLocales[$theme->getFullPath()] as $locale) {
         $fileResolved = self::$_viewFilesFallback->getFile($theme->getArea(), $theme, $locale, $file);
         if (file_exists($fileResolved)) {
             $found[$fileResolved] = $fileResolved;
         }
     }
     return $found;
 }
Ejemplo n.º 8
0
 /**
  * @param string $origFile
  * @param string $origPath
  * @param string $origContent
  * @param bool $isMaterialization
  * @param bool $isExist
  *
  * @dataProvider getFileDataProvider
  */
 public function testGetFile($origFile, $origPath, $origContent, $isMaterialization, $isExist)
 {
     $filePath = 'some/file.ext';
     $read = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
     $read->expects($this->at(0))->method('readFile')->with($origPath)->willReturn($origContent);
     $this->readFactory->expects($this->atLeastOnce())->method('create')->willReturn($read);
     $this->viewFileResolution->expects($this->once())
         ->method('getFile')
         ->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')
         ->willReturn($origFile);
     $this->preProcessorPool->expects($this->once())
         ->method('process')
         ->with($this->chain);
     $this->staticDirRead->expects($this->any())
         ->method('isExist')
         ->willReturn($isExist);
     if ($isMaterialization || !$isExist) {
         $this->chain
             ->expects($this->once())
             ->method('isChanged')
             ->willReturn(true);
         $this->chain
             ->expects($this->once())
             ->method('getContent')
             ->willReturn('processed');
         $this->chain
             ->expects($this->once())
             ->method('getTargetAssetPath')
             ->willReturn($filePath);
         $this->varDir->expects($this->once())
             ->method('writeFile')
             ->with('view_preprocessed/source/some/file.ext', 'processed');
         $this->varDir->expects($this->once())
             ->method('getAbsolutePath')
             ->willReturn('var');
         $read->expects($this->once())
             ->method('getAbsolutePath')
             ->with('view_preprocessed/source/some/file.ext')
             ->willReturn('result');
     } else {
         $this->varDir->expects($this->never())->method('writeFile');
         $read->expects($this->at(1))
             ->method('getAbsolutePath')
             ->with('file.ext')
             ->willReturn('result');
     }
     $this->assertSame('result', $this->object->getFile($this->getAsset()));
 }
Ejemplo n.º 9
0
 /**
  * @param string $origFile
  * @param string $origPath
  * @param string $origContentType
  * @param string $origContent
  * @param string $isMaterialization
  * @dataProvider getFileDataProvider
  */
 public function testGetFile($origFile, $origPath, $origContentType, $origContent, $isMaterialization)
 {
     $filePath = 'some/file.ext';
     $cacheValue = "{$origPath}:{$filePath}";
     $this->viewFileResolution->expects($this->once())->method('getFile')->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')->will($this->returnValue($origFile));
     $this->rootDirRead->expects($this->once())->method('getRelativePath')->with($origFile)->will($this->returnValue($origPath));
     $this->cache->expects($this->once())->method('load')->will($this->returnValue(false));
     $this->rootDirRead->expects($this->once())->method('readFile')->with($origPath)->will($this->returnValue($origContent));
     $processor = $this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\PreProcessorInterface');
     $this->preProcessorPool->expects($this->once())->method('getPreProcessors')->with($origContentType, 'ext')->will($this->returnValue([$processor]));
     $processor->expects($this->once())->method('process')->will($this->returnCallback(array($this, 'chainTestCallback')));
     if ($isMaterialization) {
         $this->varDir->expects($this->once())->method('writeFile')->with('view_preprocessed/source/some/file.ext', 'processed');
         $this->cache->expects($this->once())->method('save')->with(serialize([\Magento\Framework\App\Filesystem::VAR_DIR, 'view_preprocessed/source/some/file.ext']), $cacheValue);
         $this->varDir->expects($this->once())->method('getAbsolutePath')->with('view_preprocessed/source/some/file.ext')->will($this->returnValue('result'));
     } else {
         $this->varDir->expects($this->never())->method('writeFile');
         $this->cache->expects($this->once())->method('save')->with(serialize([\Magento\Framework\App\Filesystem::ROOT_DIR, 'source/some/file.ext']), $cacheValue);
         $this->rootDirRead->expects($this->once())->method('getAbsolutePath')->with('source/some/file.ext')->will($this->returnValue('result'));
     }
     $this->assertSame('result', $this->object->getFile($this->getAsset()));
 }