示例#1
0
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Unable to load theme by specified key: '0'
  */
 public function testCreateDummy()
 {
     $themeId = 0;
     $theme = $this->getMock('Magento\\Core\\Model\\Theme', array(), array(), '', false);
     $theme->expects($this->once())->method('getId')->will($this->returnValue($themeId));
     $this->themeProviderMock->expects($this->once())->method('getThemeById')->with($themeId)->will($this->returnValue($theme));
     $this->assertNull($this->factory->create($themeId));
 }
示例#2
0
 /**
  * Retrieves a unique list of pairs representing the theme/locale for each store view
  *
  * @return array
  */
 public function retrieveThemeLocalePairs()
 {
     $stores = $this->storeManager->getStores();
     $localeThemeData = [];
     /** @var \Magento\Store\Api\Data\StoreInterface $store */
     foreach ($stores as $store) {
         $code = $store->getCode();
         $themeId = $this->scopeConfig->getValue(DesignInterface::XML_PATH_THEME_ID, ScopeInterface::SCOPE_STORE, $code);
         $localeThemeData[] = ['theme' => $this->themeProvider->getThemeById($themeId)->getCode(), 'locale' => $this->scopeConfig->getValue(Data::XML_PATH_DEFAULT_LOCALE, ScopeInterface::SCOPE_STORE, $code)];
     }
     return $this->removeDuplicates($localeThemeData);
 }
 public function testValidateIsThemeInUse()
 {
     $theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false);
     $theme->expects($this->once())->method('getId')->willReturn(6);
     $defaultEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'default', 'scope_id' => 8]);
     $websitesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'websites', 'scope_id' => 8]);
     $storesEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope' => 'stores', 'scope_id' => 8]);
     $this->themeProvider->expects($this->once())->method('getThemeByFullPath')->willReturn($theme);
     $this->configData->expects($this->once())->method('getCollection')->willReturn($this->configData);
     $this->configData->expects($this->at(1))->method('addFieldToFilter')->willReturn($this->configData);
     $this->configData->expects($this->at(2))->method('addFieldToFilter')->willReturn([$defaultEntity, $websitesEntity, $storesEntity]);
     $website = $this->getMock('Magento\\Store\\Model\\Website', ['getName'], [], '', false);
     $website->expects($this->once())->method('getName')->willReturn('websiteA');
     $store = $this->getMock('Magento\\Store\\Model\\Store', ['getName'], [], '', false);
     $store->expects($this->once())->method('getName')->willReturn('storeA');
     $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($website);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $result = $this->themeValidator->validateIsThemeInUse(['frontend/Magento/a']);
     $this->assertEquals(['<error>frontend/Magento/a is in use in default config</error>', '<error>frontend/Magento/a is in use in website websiteA</error>', '<error>frontend/Magento/a is in use in store storeA</error>'], $result);
 }
 /**
  * Validate the theme if being in use in default, website, or store.
  *
  * @param string[] $themePaths
  * @return array
  */
 public function validateIsThemeInUse($themePaths)
 {
     $messages = [];
     $themesById = [];
     foreach ($themePaths as $themePath) {
         $theme = $this->themeProvider->getThemeByFullPath($themePath);
         $themesById[$theme->getId()] = $themePath;
     }
     $configData = $this->configData->getCollection()->addFieldToFilter('path', DesignInterface::XML_PATH_THEME_ID)->addFieldToFilter('value', ['in' => array_keys($themesById)]);
     foreach ($configData as $row) {
         switch ($row['scope']) {
             case 'default':
                 $messages[] = '<error>' . $themesById[$row['value']] . ' is in use in default config' . '</error>';
                 break;
             case ScopeInterface::SCOPE_WEBSITES:
                 $messages[] = '<error>' . $themesById[$row['value']] . ' is in use in website ' . $this->storeManager->getWebsite($row['scope_id'])->getName() . '</error>';
                 break;
             case ScopeInterface::SCOPE_STORES:
                 $messages[] = '<error>' . $themesById[$row['value']] . ' is in use in store ' . $this->storeManager->getStore($row['scope_id'])->getName() . '</error>';
                 break;
         }
     }
     return $messages;
 }
示例#5
0
 /**
  * Fetch theme customization and sort them out to arrays:
  * self::_assignedTheme and self::_unassignedTheme.
  *
  * NOTE: To get into "assigned" list theme customization not necessary should be assigned to store-view directly.
  * It can be set to website or as default theme and be used by store-view via config fallback mechanism.
  *
  * @return $this
  */
 protected function _prepareThemeCustomizations()
 {
     /** @var \Magento\Core\Model\Resource\Theme\Collection $themeCollection */
     $themeCollection = $this->themeProvider->getThemeCustomizations(\Magento\Framework\App\Area::AREA_FRONTEND);
     $assignedThemes = $this->getStoresByThemes();
     $this->_assignedTheme = array();
     $this->_unassignedTheme = array();
     /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
     foreach ($themeCollection as $theme) {
         if (isset($assignedThemes[$theme->getId()])) {
             $theme->setAssignedStores($assignedThemes[$theme->getId()]);
             $this->_assignedTheme[$theme->getId()] = $theme;
         } else {
             $this->_unassignedTheme[$theme->getId()] = $theme;
         }
     }
     return $this;
 }