public function testResolve()
 {
     $requestedFile = 'file.css';
     $expected = 'some/dir/file.less';
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->any())->method('getFullPath')->will($this->returnValue('magento_theme'));
     $this->rule->expects($this->atLeastOnce())->method('getPatternDirs')->will($this->returnValue(['some/dir']));
     $fileExistsMap = [['file.css', false], ['file.less', true]];
     $this->directory->expects($this->any())->method('isExist')->will($this->returnValueMap($fileExistsMap));
     $actual = $this->object->resolve('type', $requestedFile, 'frontend', $theme, 'en_US', 'Magento_Module');
     $this->assertSame($expected, $actual);
 }
Exemplo n.º 2
0
 public function testResolveNonexistentFile()
 {
     $this->readFactoryMock->expects($this->any())->method('create')->willReturn($this->directoryMock);
     $this->ruleMock->expects($this->once())->method('getPatternDirs')->willReturn(['some/dir']);
     $this->directoryMock->expects($this->once())->method('isExist')->willReturn(false);
     $this->assertFalse($this->object->resolve('type', 'file.ext', 'frontend', $this->getMockForTheme('magento_theme'), 'en_US', 'Magento_Module'));
 }
Exemplo n.º 3
0
 public function testResolveFromCache()
 {
     $expectedPath = '/some/dir/file.ext';
     $this->cache->expects($this->once())->method('getFromCache')->with('type', 'file.ext', 'frontend', 'magento_theme', 'en_US', 'Magento_Module')->will($this->returnValue($expectedPath));
     $this->directory->expects($this->once())->method('getAbsolutePath')->with($expectedPath)->will($this->returnValue($expectedPath));
     $this->rule->expects($this->never())->method('getPatternDirs');
     $this->cache->expects($this->never())->method('saveToCache');
     $actualPath = $this->object->resolve('type', 'file.ext', 'frontend', $this->getMockForTheme('magento_theme'), 'en_US', 'Magento_Module');
     $this->assertSame($expectedPath, $actualPath);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function resolveFile(RuleInterface $fallbackRule, $file, array $params = [])
 {
     $path = parent::resolveFile($fallbackRule, $file, $params);
     if (!$path) {
         $extension = pathinfo($file, PATHINFO_EXTENSION);
         if (isset($this->alternativeExtensions[$extension])) {
             foreach ($this->alternativeExtensions[$extension] as $newExtension) {
                 $newFile = substr($file, 0, strlen($file) - strlen($extension)) . $newExtension;
                 $result = parent::resolveFile($fallbackRule, $newFile, $params);
                 if ($result) {
                     $path = $result;
                     break;
                 }
             }
         }
     }
     return $path;
 }
Exemplo n.º 6
0
 /**
  * Find asset file by simply appending its path to the directory in context
  *
  * @param LocalInterface $asset
  * @param \Magento\Framework\View\Asset\File\Context $context
  * @return string
  */
 private function findFile(LocalInterface $asset, \Magento\Framework\View\Asset\File\Context $context)
 {
     $dir = $this->filesystem->getDirectoryRead($context->getBaseDirType());
     Simple::assertFilePathFormat($asset->getFilePath());
     return $dir->getAbsolutePath($asset->getPath());
 }
 /**
  * Get file name, using fallback mechanism
  *
  * @param string $area
  * @param ThemeInterface $themeModel
  * @param string $locale
  * @param string $file
  * @param string|null $module
  * @return bool|string
  */
 public function getFile($area, ThemeInterface $themeModel, $locale, $file, $module = null)
 {
     return $this->resolver->resolve($this->getFallbackType(), $file, $area, $themeModel, $locale, $module);
 }