/** * {@inheritdoc} * * @throws \Magento\Framework\Exception */ public function getTheme() { $theme = $this->_themeFactory->create($this->getData('theme_id')); if (!$theme) { throw new \Magento\Framework\Exception('Theme id should be set'); } return $theme; }
/** * @test * @return void */ public function testGetInheritedThemes() { $inheritedTheme = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $this->_model->setParentId(10); $this->themeFactory->expects($this->once())->method('create')->with(10)->willReturn($inheritedTheme); $this->assertContainsOnlyInstancesOf('Magento\\Framework\\View\\Design\\ThemeInterface', $this->_model->getInheritedThemes()); $this->assertCount(2, $this->_model->getInheritedThemes()); }
/** * Get theme module for custom static files * * @return \Magento\Theme\Model\Theme * @throws \InvalidArgumentException */ protected function _getTheme() { $themeId = $this->_getRequest()->getParam(self::PARAM_THEME_ID); $theme = $this->_themeFactory->create($themeId); if (!$themeId || !$theme) { throw new \InvalidArgumentException('Theme was not found.'); } return $theme; }
/** * @test * @param bool $storeMode * @param string $scope * @dataProvider designThemeDataProvider * @return void */ public function testSetDefaultDesignTheme($storeMode, $scope) { $area = Design::DEFAULT_AREA; $this->state->expects($this->any())->method('getAreaCode')->willReturn($area); $this->storeManager->expects($this->once())->method('isSingleStoreMode')->willReturn($storeMode); $this->config->expects($this->once())->method('getValue')->with(Design::XML_PATH_THEME_ID, $scope, null)->willReturn(null); $this->flyweightThemeFactory->expects($this->once())->method('create')->with($this->defaultTheme, $area); $this->assertInstanceOf(get_class($this->model), $this->model->setDefaultDesignTheme()); }
protected function setUp() { $this->customizationPath = '/' . implode('/', ['var', 'theme']); $this->request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', [], [], '', false); $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->session = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false); $this->contextHelper = $this->getMock('Magento\\Framework\\App\\Helper\\Context', [], [], '', false); $this->directoryWrite = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', [], [], '', false); $this->themeFactory = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory', [], [], '', false); $this->theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $this->customization = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\Customization', [], [], '', false); $this->filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($this->directoryWrite)); $this->directoryWrite->expects($this->any())->method('create')->will($this->returnValue(true)); $this->contextHelper->expects($this->once())->method('getRequest')->will($this->returnValue($this->request)); $this->themeFactory->expects($this->any())->method('create')->will($this->returnValue($this->theme)); $this->theme->expects($this->any())->method('getCustomization')->will($this->returnValue($this->customization)); $this->request->expects($this->at(0))->method('getParam')->with(\Magento\Theme\Helper\Storage::PARAM_THEME_ID)->will($this->returnValue(6)); $this->request->expects($this->at(1))->method('getParam')->with(\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE)->will($this->returnValue(\Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE)); $this->helper = new \Magento\Theme\Helper\Storage($this->contextHelper, $this->filesystem, $this->session, $this->themeFactory); }
/** * 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); }
/** * {@inheritdoc} */ public function getParentTheme() { if ($this->hasData('parent_theme')) { return $this->getData('parent_theme'); } $theme = null; if ($this->getParentId()) { $theme = $this->_themeFactory->create($this->getParentId()); } $this->setParentTheme($theme); return $theme; }
/** * Set theme path * * @param \Magento\Framework\View\Design\ThemeInterface|string $theme * @param string $area * @return $this */ public function setDesignTheme($theme, $area = null) { if ($area) { $this->setArea($area); } else { $area = $this->getArea(); } if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) { $this->_theme = $theme; } else { $this->_theme = $this->_flyweightFactory->create($theme, $area); } return $this; }
/** * Test for the static files fallback according to the themes inheritance * * @param string $file * @param string $themePath * @param string $locale * @param string $module * @param string|null $expectedFilename * * @dataProvider getViewFileDataProvider */ public function testGetViewFile($file, $themePath, $locale, $module, $expectedFilename) { /** @var \Magento\Framework\View\Design\FileResolution\Fallback\StaticFile $model */ $model = Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\FileResolution\\Fallback\\StaticFile'); $themeModel = $this->themeFactory->create($themePath); $actualFilename = $model->getFile('frontend', $themeModel, $locale, $file, $module); if ($expectedFilename) { $this->assertInternalType('string', $actualFilename); $this->assertStringMatchesFormat($expectedFilename, $actualFilename); $this->assertFileExists($actualFilename); } else { $this->assertFalse($actualFilename); } }
public function testExecute() { $themeId = 23; $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface', [], '', false); $jsFile = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\Theme\\FileInterface', [], '', false, true, true, ['setTheme', 'setFileName', 'setData', 'save']); $this->_request->expects($this->at(0))->method('getParam')->with('id')->willReturn($themeId); $this->_objectManagerMock->expects($this->at(0))->method('get')->with('Magento\\Theme\\Model\\Uploader\\Service')->WillReturn($this->serviceModel); $this->_objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->WillReturn($this->themeFactory); $this->_objectManagerMock->expects($this->at(2))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\Customization\\File\\Js')->WillReturn($this->customizationJs); $this->_objectManagerMock->expects($this->at(4))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->WillReturn($this->jsonHelper); $this->themeFactory->expects($this->once())->method('create')->willReturn($theme); $this->serviceModel->expects($this->once())->method('uploadJsFile')->with('js_files_uploader')->willReturn(['filename' => 'filename', 'content' => 'content']); $this->customizationJs->expects($this->once())->method('create')->willReturn($jsFile); $jsFile->expects($this->once())->method('setTheme')->with($theme); $jsFile->expects($this->once())->method('setFileName')->with('filename'); $jsFile->expects($this->once())->method('setData')->with('content', 'content'); $jsFile->expects($this->once())->method('save'); $this->_objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\View\\Design\\Theme\\CustomizationInterface', ['theme' => $theme])->willReturn($this->themeCustomization); $this->themeCustomization->expects($this->once())->method('getFilesByType')->with(\Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE)->willReturn([$jsFile]); $this->themeCustomization->expects($this->once())->method('generateFileInfo')->with([$jsFile])->willReturn(['fileOne' => ['name' => 'name']]); $this->jsonHelper->expects($this->once())->method('jsonEncode')->with(['error' => false, 'files' => ['fileOne' => ['name' => 'name']]])->willReturn('{"error":false,"files":{"fileOne":{"name":"name"}}}'); $this->response->expects($this->once())->method('representJson')->with('{"error":false,"files":{"fileOne":{"name":"name"}}}'); $this->_model->execute(); }
/** * Test for the email template files fallback according to the themes inheritance * * @magentoDataFixture Magento/Store/_files/core_fixturestore.php * @magentoComponentsDir Magento/Email/Model/_files/design * * @param string $file * @param string $themePath * @param string $module * @param string|null $expectedFilename * * @dataProvider getEmailTemplateFileDataProvider */ public function testGetEmailTemplateFile($file, $themePath, $module, $expectedFilename) { $area = \Magento\Framework\App\Area::AREA_FRONTEND; /** @var \Magento\Framework\View\Design\FileResolution\Fallback\EmailTemplateFile $model */ $model = Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\FileResolution\\Fallback\\EmailTemplateFile'); $themeModel = $this->themeFactory->create($themePath); $locale = \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE; $actualFilename = $model->getFile($area, $themeModel, $locale, $file, $module); if ($expectedFilename) { $this->assertInternalType('string', $actualFilename); $this->assertStringMatchesFormat($expectedFilename, $actualFilename); $this->assertFileExists($actualFilename); } else { $this->assertFalse($actualFilename); } }
/** * @test * @return void * @expectedException \InvalidArgumentException * @expectedExceptionMessage Theme was not found */ public function testGetThemeNotFound() { $this->themeFactory->expects($this->once())->method('create')->willReturn(null); $helper = new \Magento\Theme\Helper\Storage($this->contextHelper, $this->filesystem, $this->session, $this->themeFactory); $helper->getStorageRoot(); }
/** * @test * @return void * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Theme id should be set */ public function testGetThemeException() { $this->themeFactory->expects($this->once())->method('create')->with(null, DesignInterface::DEFAULT_AREA)->willReturn(null); $this->model->getTheme(); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Incorrect theme identification key */ public function testNegativeCreate() { $this->factory->create(null); }