/** * Test if theme present in file system * * @magentoAppIsolation enabled * @covers \Magento\Theme\Model\Theme\Collection::hasTheme */ public function testHasThemeInCollection() { /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */ $themeModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\ThemeInterface'); $themeModel->setData(['area' => 'space_area', 'theme_title' => 'Space theme', 'parent_id' => null, 'is_featured' => false, 'theme_path' => 'default_space', 'preview_image' => 'images/preview.png', 'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL]); $this->_model->addConstraint(Collection::CONSTRAINT_AREA, Area::AREA_FRONTEND); $this->assertFalse($this->_model->hasTheme($themeModel)); }
/** * Update theme data * * @return void */ protected function updateThemeData() { $themesData = $this->themeCollection->loadData(); /** @var \Magento\Theme\Model\Theme $themeData */ foreach ($themesData as $themeData) { if ($themeData->getParentTheme()) { $parentTheme = $this->themeLoader->getThemeByFullPath($themeData->getParentTheme()->getFullPath()); $themeData->setParentId($parentTheme->getId()); } /** @var \Magento\Theme\Model\Theme $theme */ $theme = $this->themeLoader->getThemeByFullPath($themeData->getArea() . Theme::THEME_PATH_SEPARATOR . $themeData->getThemePath()); $theme->addData($themeData->toArray())->save(); } }
/** * Update theme data * * @return void */ protected function updateThemeData() { $themesFromConfig = $this->themeCollection->loadData(); /** @var \Magento\Theme\Model\Theme $themeFromConfig */ foreach ($themesFromConfig as $themeFromConfig) { /** @var \Magento\Theme\Model\Theme $themeFromDb */ $themeFromDb = $this->themeLoader->getThemeByFullPath($themeFromConfig->getArea() . Theme::THEME_PATH_SEPARATOR . $themeFromConfig->getThemePath()); if ($themeFromConfig->getParentTheme()) { $parentThemeFromDb = $this->themeLoader->getThemeByFullPath($themeFromConfig->getParentTheme()->getFullPath()); $themeFromDb->setParentId($parentThemeFromDb->getId()); } $themeFromDb->setThemeTitle($themeFromConfig->getThemeTitle()); $themeFromDb->save(); } }
public function testBeforeDispatch() { $theme = $this->getMock('Magento\\Theme\\Model\\Theme', ['setParentId', 'getArea', 'getThemePath', 'getParentTheme', 'getId', 'getFullPath', 'toArray', 'addData', 'save'], [], '', false); $this->appState->expects($this->once())->method('getMode')->willReturn('default'); $this->themeRegistration->expects($this->once())->method('register'); $this->themeCollection->expects($this->once())->method('loadData')->willReturn([$theme]); $theme->expects($this->once())->method('getArea')->willReturn('frontend'); $theme->expects($this->once())->method('getThemePath')->willReturn('Magento/luma'); $theme->expects($this->exactly(2))->method('getParentTheme')->willReturnSelf(); $theme->expects($this->once())->method('getId')->willReturn(1); $theme->expects($this->once())->method('getFullPath')->willReturn('frontend/Magento/blank'); $theme->expects($this->once())->method('setParentId')->with(1); $this->themeLoader->expects($this->exactly(2))->method('getThemeByFullPath')->withConsecutive(['frontend/Magento/blank'], ['frontend/Magento/luma'])->will($this->onConsecutiveCalls($theme, $theme)); $theme->expects($this->once())->method('toArray')->willReturn(['title' => 'Magento Luma']); $theme->expects($this->once())->method('addData')->with(['title' => 'Magento Luma'])->willReturnSelf(); $theme->expects($this->once())->method('save'); $this->plugin->beforeDispatch($this->abstractAction, $this->request); }
/** * @param array $inputValues * @param array $expected * * @dataProvider addConstraintDataProvider */ public function testAddConstraint(array $inputValues, array $expected) { foreach ($inputValues as $data) { $type = $data[0]; $value = $data[1]; $this->model->addConstraint($type, $value); } $default = [Collection::CONSTRAINT_AREA => [], Collection::CONSTRAINT_VENDOR => [], Collection::CONSTRAINT_THEME_NAME => []]; $expected = array_merge($default, $expected); $this->assertAttributeSame($expected, 'constraints', $this->model); }
/** * Checks all physical themes that they were not deleted * * @return $this */ public function checkPhysicalThemes() { $themes = $this->_collectionFactory->create()->addTypeFilter(ThemeInterface::TYPE_PHYSICAL); /** @var $theme ThemeInterface */ foreach ($themes as $theme) { if (!$this->_themeCollection->hasTheme($theme)) { $theme->setType(ThemeInterface::TYPE_VIRTUAL)->save(); } } return $this; }
public static function setUpBeforeClass() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->configure(['preferences' => ['Magento\\Theme\\Model\\Theme' => 'Magento\\Theme\\Model\\Theme\\Data']]); /** @var $fallbackPool \Magento\Framework\View\Design\Fallback\RulePool */ $fallbackPool = $objectManager->get('Magento\\Framework\\View\\Design\\Fallback\\RulePool'); self::$_fallbackRule = $fallbackPool->getRule(\Magento\Framework\View\Design\Fallback\RulePool::TYPE_STATIC_FILE); self::$_viewFilesFallback = $objectManager->get('Magento\\Framework\\View\\Design\\FileResolution\\Fallback\\StaticFile'); self::$_filesFallback = $objectManager->get('Magento\\Framework\\View\\Design\\FileResolution\\Fallback\\File'); // Themes to be checked self::$_themeCollection = $objectManager->get('Magento\\Theme\\Model\\Theme\\Collection'); self::$_themeCollection->addDefaultPattern('*'); // Compose list of locales, needed to be checked for themes self::$_checkThemeLocales = []; foreach (self::$_themeCollection as $theme) { $themeLocales = self::_getThemeLocales($theme); $themeLocales[] = null; // Default non-localized file will need to be checked as well self::$_checkThemeLocales[$theme->getFullPath()] = $themeLocales; } }
/** * @param bool $hasParentTheme * @dataProvider dataProviderBeforeDispatch * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testBeforeDispatch($hasParentTheme) { $themeId = 1; $themeTitle = 'Theme title'; $themeFromConfigMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->setMethods(['getArea', 'getThemePath', 'getParentTheme', 'getThemeTitle'])->getMock(); $themeFromDbMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->setMethods(['setParentId', 'setThemeTitle', 'save'])->getMock(); $parentThemeFromDbMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $parentThemeFromConfigMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $this->appState->expects($this->once())->method('getMode')->willReturn('default'); $this->themeRegistration->expects($this->once())->method('register'); $this->themeCollection->expects($this->once())->method('loadData')->willReturn([$themeFromConfigMock]); $this->themeLoader->expects($hasParentTheme ? $this->exactly(2) : $this->once())->method('getThemeByFullPath')->willReturnMap([['frontend/Magento/blank', $parentThemeFromDbMock], ['frontend/Magento/luma', $themeFromDbMock]]); $themeFromConfigMock->expects($this->once())->method('getArea')->willReturn('frontend'); $themeFromConfigMock->expects($this->once())->method('getThemePath')->willReturn('Magento/luma'); $themeFromConfigMock->expects($hasParentTheme ? $this->exactly(2) : $this->once())->method('getParentTheme')->willReturn($hasParentTheme ? $parentThemeFromConfigMock : null); $themeFromConfigMock->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle); $parentThemeFromDbMock->expects($hasParentTheme ? $this->once() : $this->never())->method('getId')->willReturn($themeId); $parentThemeFromConfigMock->expects($hasParentTheme ? $this->once() : $this->never())->method('getFullPath')->willReturn('frontend/Magento/blank'); $themeFromDbMock->expects($hasParentTheme ? $this->once() : $this->never())->method('setParentId')->with($themeId)->willReturnSelf(); $themeFromDbMock->expects($this->once())->method('setThemeTitle')->with($themeTitle)->willReturnSelf(); $themeFromDbMock->expects($this->once())->method('save')->willReturnSelf(); $this->plugin->beforeDispatch($this->abstractAction, $this->request); }
/** * @test * @return void * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please specify at least one target pattern to theme config file. */ public function testGetTargetPatternsException() { $this->model->getTargetPatterns(); }