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); }
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')); }
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); }
/** * 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); }
/** * 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); }