Esempio n. 1
0
 /**
  * Clean related contents to a theme (before save)
  *
  * @param EventObserver $observer
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 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 \Magento\Framework\Exception\LocalizedException(__('Theme isn\'t deletable.'));
     }
     $this->themeImageFactory->create(['theme' => $theme])->removePreviewImage();
     $this->updateCollection->addThemeFilter($theme->getId())->delete();
 }
Esempio n. 2
0
 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->cleanThemeRelatedContent($observerMock);
 }