/** * Clean related contents to a theme (before save) * * @param EventObserver $observer * @return void * @throws Exception */ public function cleanThemeRelatedContent(EventObserver $observer) { $theme = $observer->getEvent()->getData('theme'); if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) { return; } /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ if ($this->_themeConfig->isThemeAssignedToStore($theme)) { throw new Exception(__('Theme isn\'t deletable.')); } $this->_themeImageFactory->create(array('theme' => $theme))->removePreviewImage(); $this->_updateCollection->addThemeFilter($theme->getId())->delete(); }
public function testCleanThemeRelatedContent() { $themeMock = $this->getMockBuilder('Magento\\Framework\\View\\Design\\ThemeInterface')->getMockForAbstractClass(); $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->getMock(); $eventMock->expects($this->any())->method('getData')->with('theme')->willReturn($themeMock); $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock); $this->themeConfig->expects($this->any())->method('isThemeAssignedToStore')->with($themeMock)->willReturn(false); $this->themeImageFactory->expects($this->once())->method('create')->with(['theme' => $themeMock])->willReturnSelf(); $this->themeImageFactory->expects($this->once())->method('removePreviewImage'); $this->updateCollection->expects($this->once())->method('addThemeFilter')->willReturnSelf(); $this->updateCollection->expects($this->once())->method('delete'); $this->themeObserver->execute($observerMock); }
/** * Get theme image model * * @return \Magento\Framework\View\Design\Theme\Image */ public function getThemeImage() { return $this->_imageFactory->create(['theme' => $this]); }