public function testCleanThemeRelatedContentNonObjectTheme()
 {
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->getMock();
     $eventMock->expects($this->any())->method('getData')->with('theme')->willReturn('Theme as a string');
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock);
     $this->themeConfig->expects($this->never())->method('isThemeAssignedToStore');
     $this->themeObserver->execute($observerMock);
 }
 /**
  * Check a theme, it's assigned to any of store
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     $theme = $observer->getEvent()->getData('theme');
     if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) {
         /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
         if ($this->themeConfig->isThemeAssignedToStore($theme)) {
             $this->eventDispatcher->dispatch('assigned_theme_changed', ['theme' => $theme]);
         }
     }
 }
 public function testCheckThemeIsAssigned()
 {
     $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(true);
     $this->eventDispatcher->expects($this->any())->method('dispatch')->with('assigned_theme_changed', ['theme' => $themeMock]);
     $this->themeObserver->execute($observerMock);
 }
 /**
  * Clean related contents to a theme (before save)
  *
  * @param EventObserver $observer
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function execute(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();
 }
Example #5
0
 /**
  * Load layout
  *
  * @return void
  */
 protected function _renderStoreDesigner()
 {
     try {
         $this->_view->loadLayout();
         $this->_setActiveMenu('Magento_DesignEditor::system_design_editor');
         $this->_setTitle();
         if (!$this->_isFirstEntrance()) {
             /** @var $assignedThemeBlock
              * \Magento\DesignEditor\Block\Adminhtml\Theme\Selector\SelectorList\Assigned */
             $assignedThemeBlock = $this->_view->getLayout()->getBlock('assigned.theme.list');
             $assignedThemeBlock->setCollection($this->_customizationConfig->getAssignedThemeCustomizations());
             /** @var $unassignedThemeBlock
              * \Magento\DesignEditor\Block\Adminhtml\Theme\Selector\SelectorList\Unassigned */
             $unassignedThemeBlock = $this->_view->getLayout()->getBlock('unassigned.theme.list');
             $unassignedThemeBlock->setCollection($this->_customizationConfig->getUnassignedThemeCustomizations());
             $unassignedThemeBlock->setHasThemeAssigned($this->_customizationConfig->hasThemeAssigned());
         }
         /** @var $storeViewBlock \Magento\DesignEditor\Block\Adminhtml\Theme\Selector\StoreView */
         $storeViewBlock = $this->_view->getLayout()->getBlock('theme.selector.storeview');
         $storeViewBlock->setData('actionOnAssign', 'refresh');
         $this->_view->renderLayout();
     } catch (\Exception $e) {
         $this->messageManager->addError(__('We can\'t load the list of themes.'));
         $this->getResponse()->setRedirect($this->_redirect->getRefererUrl());
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
     }
 }
Example #6
0
 /**
  * Create a form element with necessary controls
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(array('data' => array('action' => '#', 'method' => 'post')));
     $this->setForm($form);
     $form->setUseContainer(true);
     $form->addType('js_files', 'Magento\\DesignEditor\\Block\\Adminhtml\\Editor\\Form\\Element\\Uploader');
     $jsConfig = array('name' => 'js_files_uploader', 'title' => __('Select JS Files to Upload'), 'accept' => 'application/x-javascript', 'multiple' => '1');
     if ($this->_customizationConfig->isThemeAssignedToStore($this->_themeContext->getEditableTheme())) {
         $confirmMessage = __('These JavaScript files may change the appearance of your live store(s).' . ' Are you sure you want to do this?');
         $jsConfig['onclick'] = "return confirm('{$confirmMessage}');";
     }
     $form->addField('js_files_uploader', 'js_files', $jsConfig);
     parent::_prepareForm();
     return $this;
 }
Example #7
0
 /**
  * Get the flag if there are multiple store-views in Magento
  *
  * @return bool
  */
 protected function _hasMultipleStores()
 {
     $isMultipleMode = false;
     $tmpStore = null;
     foreach ($this->_customizationConfig->getStoresByThemes() as $stores) {
         /** @var $store \Magento\Store\Model\Store */
         foreach ($stores as $store) {
             if ($tmpStore === null) {
                 $tmpStore = $store->getId();
             } elseif ($tmpStore != $store->getId()) {
                 $isMultipleMode = true;
                 break 2;
             }
         }
     }
     return $isMultipleMode;
 }
Example #8
0
 /**
  * Get stores list
  *
  * @return \Magento\Store\Model\Store|null
  */
 public function getStoresList()
 {
     $stores = $this->_customization->getStoresByThemes();
     return isset($stores[$this->_themeContext->getEditableTheme()->getId()]) ? $stores[$this->_themeContext->getEditableTheme()->getId()] : null;
 }
Example #9
0
 /**
  * Check if theme is assigned to ANY store
  *
  * @return bool
  */
 public function isAssigned()
 {
     return $this->_customizationConfig->isThemeAssignedToStore($this->_theme);
 }
 /**
  * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
  */
 public function testIsThemeAssignedToConcreteStore()
 {
     $this->designPackage->expects($this->once())->method('getConfigurationDesignTheme')->willReturn($this->getAssignedTheme()->getId());
     $themeUnassigned = $this->model->isThemeAssignedToStore($this->getUnassignedTheme(), $this->getStore());
     $this->assertEquals(false, $themeUnassigned);
 }