protected function setUp() { $this->directoryMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\Read::class)->disableOriginalConstructor()->getMock(); $this->ruleMock = $this->getMockBuilder(\Magento\Framework\View\Design\Fallback\Rule\RuleInterface::class)->getMockForAbstractClass(); $this->rulePoolMock = $this->getMockBuilder(\Magento\Framework\View\Design\Fallback\RulePool::class)->disableOriginalConstructor()->getMock(); $this->readFactoryMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadFactory::class)->disableOriginalConstructor()->getMock(); $this->directoryListMock = $this->getMockBuilder(DirectoryList::class)->disableOriginalConstructor()->getMock(); $this->rulePoolMock->expects($this->any())->method('getRule')->with('type')->willReturn($this->ruleMock); $this->object = (new ObjectManager($this))->getObject(Simple::class, ['readFactory' => $this->readFactoryMock, 'rulePool' => $this->rulePoolMock]); (new ObjectManager($this))->setBackwardCompatibleProperty($this->object, 'directoryList', $this->directoryListMock); }
/** * {@inheritdoc} */ public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null) { $params = ['area' => $area, 'theme' => $theme, 'locale' => $locale]; foreach ($params as $key => $param) { if ($param === null) { unset($params[$key]); } } if (!empty($module)) { $params['module_name'] = $module; } $path = $this->resolveFile($this->rulePool->getRule($type), $file, $params); return $path; }
/** * {@inheritdoc} */ public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null) { self::assertFilePathFormat($file); $themePath = $theme ? $theme->getThemePath() : ''; $path = $this->cache->getFromCache($type, $file, $area, $themePath, $locale, $module); if (false !== $path) { $path = $path ? $this->rootDirectory->getAbsolutePath($path) : false; } else { $params = ['area' => $area, 'theme' => $theme, 'locale' => $locale]; foreach ($params as $key => $param) { if ($param === null) { unset($params[$key]); } } if (!empty($module)) { list($params['namespace'], $params['module']) = explode('_', $module, 2); } $path = $this->resolveFile($this->rulePool->getRule($type), $file, $params); $cachedValue = $path ? $this->rootDirectory->getRelativePath($path) : ''; $this->cache->saveToCache($cachedValue, $type, $file, $area, $themePath, $locale, $module); } return $path; }
/** * @param string $type * @param array $overriddenParams * @param array $expectedResult * * @dataProvider getPatternDirsDataProvider */ public function testGetPatternDirs($type, array $overriddenParams, array $expectedResult) { $actualResult = $this->model->getRule($type)->getPatternDirs($overriddenParams + $this->defaultParams); $this->assertEquals($expectedResult, $actualResult); }
/** * @expectedException \InvalidArgumentException * @expectedException Fallback rule 'unsupported_type' is not supported */ public function testGetRuleUnsupportedType() { $this->model->getRule('unsupported_type'); }