/** * Uninstall theme from database registry * * @param OutputInterface $output * @param array $themePaths * @return void */ public function uninstallRegistry(OutputInterface $output, array $themePaths) { $output->writeln('<info>Removing ' . implode(', ', $themePaths) . ' from database'); foreach ($themePaths as $themePath) { $this->themeProvider->getThemeByFullPath($themePath)->delete(); } }
/** * Check theme if has child virtual and physical theme * * @param string[] $themePaths * @return string[] */ public function checkChildTheme($themePaths) { $messages = []; $themeHasVirtualChildren = []; $themeHasPhysicalChildren = []; $parentChildMap = $this->getParentChildThemeMap(); foreach ($themePaths as $themePath) { $theme = $this->themeProvider->getThemeByFullPath($themePath); if ($theme->hasChildThemes()) { $themeHasVirtualChildren[] = $themePath; } if (isset($parentChildMap[$themePath])) { $themeHasPhysicalChildren[] = $themePath; } } if (!empty($themeHasVirtualChildren)) { $text = count($themeHasVirtualChildren) > 1 ? ' are parents of' : ' is a parent of'; $messages[] = implode(', ', $themeHasVirtualChildren) . $text . ' virtual theme.' . ' Parent themes cannot be uninstalled.'; } if (!empty($themeHasPhysicalChildren)) { $text = count($themeHasPhysicalChildren) > 1 ? ' are parents of' : ' is a parent of'; $messages[] = implode(', ', $themeHasPhysicalChildren) . $text . ' physical theme.' . ' Parent themes cannot be uninstalled.'; } return $messages; }
/** * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore */ public function testIsThemeAssignedToDefaultStore() { $this->storeManager->expects($this->once())->method('getStores')->willReturn([$this->getStore()]); $this->designPackage->expects($this->once())->method('getConfigurationDesignTheme')->willReturn($this->getAssignedTheme()->getId()); $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(Area::AREA_FRONTEND)->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]); $themeAssigned = $this->model->isThemeAssignedToStore($this->getAssignedTheme()); $this->assertEquals(true, $themeAssigned); }
public function testUninstallCode() { $this->output->expects($this->atLeastOnce())->method('writeln'); $this->themePackageInfo->expects($this->at(0))->method('getPackageName')->willReturn('packageA'); $this->themePackageInfo->expects($this->at(1))->method('getPackageName')->willReturn('packageB'); $this->themePackageInfo->expects($this->at(2))->method('getPackageName')->willReturn('packageC'); $this->remove->expects($this->once())->method('remove')->with(['packageA', 'packageB', 'packageC'])->willReturn(''); $this->themeProvider->expects($this->never())->method($this->anything()); $this->themeUninstaller->uninstallCode($this->output, ['frontend/Magento/ThemeA', 'frontend/Magento/ThemeB', 'frontend/Magento/ThemeC']); }
public function testGetById() { $themeId = 755; $collectionFactory = $this->getMock('Magento\\Theme\\Model\\Resource\\Theme\\CollectionFactory', [], [], '', false); $theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $theme->expects($this->once())->method('load')->with($themeId)->will($this->returnSelf()); $themeFactory = $this->getMock('\\Magento\\Theme\\Model\\ThemeFactory', ['create'], [], '', false); $themeFactory->expects($this->once())->method('create')->will($this->returnValue($theme)); $themeProvider = new ThemeProvider($collectionFactory, $themeFactory); $this->assertSame($theme, $themeProvider->getThemeById($themeId)); }
public function testGetThemeCustomizations() { $collectionFactory = $this->getMockBuilder('Magento\\Theme\\Model\\ResourceModel\\Theme\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $themeFactory = $this->getMockBuilder('Magento\\Theme\\Model\\ThemeFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $collection = $this->getMockBuilder('Magento\\Theme\\Model\\ResourceModel\\Theme\\Collection')->disableOriginalConstructor()->getMock(); $collectionFactory->expects($this->once())->method('create')->willReturn($collection); $collection->expects($this->once())->method('addAreaFilter')->with(Area::AREA_FRONTEND)->willReturnSelf(); $collection->expects($this->once())->method('addTypeFilter')->with(ThemeInterface::TYPE_VIRTUAL)->willReturnSelf(); /** @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $collectionFactory */ /** @var \Magento\Theme\Model\ThemeFactory $themeFactory */ $themeProvider = new ThemeProvider($collectionFactory, $themeFactory); $this->assertInstanceOf(get_class($collection), $themeProvider->getThemeCustomizations()); }
public function setUpExecute() { $this->setUpPassValidation(); $this->setupPassChildThemeCheck(); $this->dependencyChecker->expects($this->once())->method('checkDependencies')->willReturn([]); $this->remove->expects($this->once())->method('remove'); $this->cache->expects($this->once())->method('clean'); $theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme); }
/** * @dataProvider executeFailedChildThemeCheckDataProvider * @param bool $hasVirtual * @param bool $hasPhysical * @param array $input * @param string $expected * @return void */ public function testExecuteFailedChildThemeCheck($hasVirtual, $hasPhysical, array $input, $expected) { $theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $theme->expects($this->any())->method('hasChildThemes')->willReturn($hasVirtual); $parentThemeA = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $parentThemeA->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/a'); $parentThemeB = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $parentThemeB->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/b'); $childThemeC = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $childThemeC->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/c'); $childThemeD = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false); $childThemeD->expects($this->any())->method('getFullPath')->willReturn('frontend/Magento/d'); if ($hasPhysical) { $childThemeC->expects($this->any())->method('getParentTheme')->willReturn($parentThemeA); $childThemeD->expects($this->any())->method('getParentTheme')->willReturn($parentThemeB); } $this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturn($theme); $this->themeCollection->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([$childThemeC, $childThemeD])); $this->assertEquals($expected, $this->themeDependencyChecker->checkChildTheme($input)); }
/** * Remove all records related to the theme(s) in the database * * @param string[] $themePaths * @return void */ private function removeFromDb(array $themePaths) { foreach ($themePaths as $themePath) { $this->themeProvider->getThemeByFullPath($themePath)->delete(); } }