Example #1
0
 /**
  * @return array
  */
 protected function getConfigFiles()
 {
     $configFiles = [];
     foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
         $configFiles = array_merge($configFiles, $this->fileCollector->getFilesContent($theme, 'layouts.xml'));
     }
     return $configFiles;
 }
 public function testGetByAreaWithOtherAreaAndNumericThemeId()
 {
     $this->designMock->expects($this->once())->method('getDesignTheme')->will($this->returnValue($this->themeMock));
     $this->designMock->expects($this->once())->method('getArea')->will($this->returnValue('design_area'));
     $this->designMock->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue(12));
     $this->themeMock->expects($this->once())->method('getArea')->will($this->returnValue('theme_area'));
     $this->themeCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->themeCollectionMock));
     $this->themeCollectionMock->expects($this->once())->method('getItemById')->with(12)->will($this->returnValue($this->themeMock));
     $this->appStateMock->expects($this->once())->method('getAreaCode')->will($this->returnValue('other_area'));
     $this->assertEquals($this->themeMock, $this->model->get());
 }
Example #3
0
 /**
  * Test get page layouts config
  *
  * @return void
  */
 public function testGetPageLayoutsConfig()
 {
     $files1 = ['content layouts_1.xml', 'content layouts_2.xml'];
     $files2 = ['content layouts_3.xml', 'content layouts_4.xml'];
     $theme1 = $this->getMockBuilder('Magento\\Theme\\Model\\Theme\\Data')->disableOriginalConstructor()->getMock();
     $theme2 = $this->getMockBuilder('Magento\\Theme\\Model\\Theme\\Data')->disableOriginalConstructor()->getMock();
     $this->themeCollection->expects($this->any())->method('loadRegisteredThemes')->willReturn([$theme1, $theme2]);
     $this->fileCollector->expects($this->exactly(2))->method('getFilesContent')->willReturnMap([[$theme1, 'layouts.xml', $files1], [$theme2, 'layouts.xml', $files2]]);
     $config = $this->getMockBuilder('Magento\\Framework\\View\\PageLayout\\Config')->disableOriginalConstructor()->getMock();
     $this->configFactory->expects($this->once())->method('create')->with(['configFiles' => array_merge($files1, $files2)])->willReturn($config);
     $this->assertSame($config, $this->builder->getPageLayoutsConfig());
 }
Example #4
0
 /**
  * Retrieve view configuration data
  *
  * Collect data for 'Magento_Catalog' module from /etc/view.xml files.
  *
  * @return array
  */
 protected function getData()
 {
     if (!$this->data) {
         /** @var \Magento\Theme\Model\Theme $theme */
         foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
             $config = $this->viewConfig->getViewConfig(['area' => Area::AREA_FRONTEND, 'themeModel' => $theme]);
             $images = $config->getMediaEntities('Magento_Catalog', ImageHelper::MEDIA_TYPE_CONFIG_NODE);
             foreach ($images as $imageId => $imageData) {
                 $this->data[$theme->getCode() . $imageId] = array_merge(['id' => $imageId], $imageData);
             }
         }
     }
     return $this->data;
 }
Example #5
0
 /**
  * Update theme data
  *
  * @return void
  */
 protected function updateThemeData()
 {
     $themesData = $this->themeCollection->loadData();
     /** @var \Magento\Theme\Model\Theme $themeData */
     foreach ($themesData as $themeData) {
         if ($themeData->getParentTheme()) {
             $parentTheme = $this->themeLoader->getThemeByFullPath($themeData->getParentTheme()->getFullPath());
             $themeData->setParentId($parentTheme->getId());
         }
         /** @var \Magento\Theme\Model\Theme $theme */
         $theme = $this->themeLoader->getThemeByFullPath($themeData->getArea() . Theme::THEME_PATH_SEPARATOR . $themeData->getThemePath());
         $theme->addData($themeData->toArray())->save();
     }
 }
Example #6
0
 /**
  * Update theme data
  *
  * @return void
  */
 protected function updateThemeData()
 {
     $themesFromConfig = $this->themeCollection->loadData();
     /** @var \Magento\Theme\Model\Theme $themeFromConfig */
     foreach ($themesFromConfig as $themeFromConfig) {
         /** @var \Magento\Theme\Model\Theme $themeFromDb */
         $themeFromDb = $this->themeLoader->getThemeByFullPath($themeFromConfig->getArea() . Theme::THEME_PATH_SEPARATOR . $themeFromConfig->getThemePath());
         if ($themeFromConfig->getParentTheme()) {
             $parentThemeFromDb = $this->themeLoader->getThemeByFullPath($themeFromConfig->getParentTheme()->getFullPath());
             $themeFromDb->setParentId($parentThemeFromDb->getId());
         }
         $themeFromDb->setThemeTitle($themeFromConfig->getThemeTitle());
         $themeFromDb->save();
     }
 }
 /**
  * @test
  * @return void
  */
 public function testHasChildThemes()
 {
     $this->_model->setId(1);
     $this->resourceCollection->expects($this->once())->method('addTypeFilter')->with(Theme::TYPE_VIRTUAL)->willReturnSelf();
     $this->resourceCollection->expects($this->once())->method('addFieldToFilter')->with('parent_id', ['eq' => 1])->willReturnSelf();
     $this->resourceCollection->expects($this->once())->method('getSize')->willReturn(10);
     $this->assertTrue($this->_model->hasChildThemes());
 }
Example #8
0
 /**
  * Merged config from view.xml
  *
  * @return array
  */
 public function getImageConfig()
 {
     $imageConfig = [];
     foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
         $config = $this->viewConfig->getViewConfig(['area' => Area::AREA_FRONTEND, 'themeModel' => $theme]);
         $imageConfig = array_merge($imageConfig, $config->getMediaEntities('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE));
     }
     return $imageConfig;
 }
Example #9
0
 public function testBeforeDispatch()
 {
     $theme = $this->getMock('Magento\\Theme\\Model\\Theme', ['setParentId', 'getArea', 'getThemePath', 'getParentTheme', 'getId', 'getFullPath', 'toArray', 'addData', 'save'], [], '', false);
     $this->appState->expects($this->once())->method('getMode')->willReturn('default');
     $this->themeRegistration->expects($this->once())->method('register');
     $this->themeCollection->expects($this->once())->method('loadData')->willReturn([$theme]);
     $theme->expects($this->once())->method('getArea')->willReturn('frontend');
     $theme->expects($this->once())->method('getThemePath')->willReturn('Magento/luma');
     $theme->expects($this->exactly(2))->method('getParentTheme')->willReturnSelf();
     $theme->expects($this->once())->method('getId')->willReturn(1);
     $theme->expects($this->once())->method('getFullPath')->willReturn('frontend/Magento/blank');
     $theme->expects($this->once())->method('setParentId')->with(1);
     $this->themeLoader->expects($this->exactly(2))->method('getThemeByFullPath')->withConsecutive(['frontend/Magento/blank'], ['frontend/Magento/luma'])->will($this->onConsecutiveCalls($theme, $theme));
     $theme->expects($this->once())->method('toArray')->willReturn(['title' => 'Magento Luma']);
     $theme->expects($this->once())->method('addData')->with(['title' => 'Magento Luma'])->willReturnSelf();
     $theme->expects($this->once())->method('save');
     $this->plugin->beforeDispatch($this->abstractAction, $this->request);
 }
Example #10
0
 protected function generateImageConfig()
 {
     $themeMock = $this->getMock('\\Magento\\Theme\\Model\\Theme', [], [], '', false);
     $themesArrayMock = [$themeMock];
     $this->themeCollectionMock->expects($this->any())->method('loadRegisteredThemes')->willReturn($themesArrayMock);
     $configMock = $this->getMock('\\Magento\\Framework\\Config\\View', [], [], '', false);
     $this->viewConfigMock->expects($this->atLeastOnce())->method('getViewConfig')->willReturn($configMock);
     $imageConfig = ['swatch_image' => ['width' => 30, 'height' => 20], 'swatch_thumb' => ['width' => 110, 'height' => 90]];
     $configMock->expects($this->any())->method('getMediaEntities')->willReturn($imageConfig);
 }
Example #11
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGenerate()
 {
     $imageFile = 'image.jpg';
     $imageItem = $this->objectManager->getObject('Magento\\Framework\\DataObject', ['data' => ['file' => $imageFile]]);
     $this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem]));
     $this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection);
     $data = $this->getTestData();
     $this->config->expects($this->once())->method('getMediaEntities')->with('Magento_Catalog')->willReturn($data);
     $themeMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $themeMock->expects($this->exactly(3))->method('getCode')->willReturn('Magento\\theme');
     $this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn([$themeMock]);
     $this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => $themeMock])->willReturn($this->config);
     $this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'product_image', $this->getImageData('product_image'), $this->imageHelper], [$this->product, 'product_small_image', $this->getImageData('product_small_image'), $this->imageHelper], [$this->product, 'product_thumbnail', $this->getImageData('product_thumbnail'), $this->imageHelper]]));
     $this->imageHelper->expects($this->exactly(3))->method('setImageFile')->with($imageFile)->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepAspectRatio')->with($data['product_image']['aspect_ratio'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepFrame')->with($data['product_image']['frame'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('keepTransparency')->with($data['product_image']['transparency'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('constrainOnly')->with($data['product_image']['constrain'])->willReturnSelf();
     $this->imageHelper->expects($this->any())->method('backgroundColor')->with($data['product_image']['background'])->willReturnSelf();
     $this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf());
     $this->model->generate($this->product);
 }
 /**
  * @param bool $hasParentTheme
  * @dataProvider dataProviderBeforeDispatch
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function testBeforeDispatch($hasParentTheme)
 {
     $themeId = 1;
     $themeTitle = 'Theme title';
     $themeFromConfigMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->setMethods(['getArea', 'getThemePath', 'getParentTheme', 'getThemeTitle'])->getMock();
     $themeFromDbMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->setMethods(['setParentId', 'setThemeTitle', 'save'])->getMock();
     $parentThemeFromDbMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $parentThemeFromConfigMock = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $this->appState->expects($this->once())->method('getMode')->willReturn('default');
     $this->themeRegistration->expects($this->once())->method('register');
     $this->themeCollection->expects($this->once())->method('loadData')->willReturn([$themeFromConfigMock]);
     $this->themeLoader->expects($hasParentTheme ? $this->exactly(2) : $this->once())->method('getThemeByFullPath')->willReturnMap([['frontend/Magento/blank', $parentThemeFromDbMock], ['frontend/Magento/luma', $themeFromDbMock]]);
     $themeFromConfigMock->expects($this->once())->method('getArea')->willReturn('frontend');
     $themeFromConfigMock->expects($this->once())->method('getThemePath')->willReturn('Magento/luma');
     $themeFromConfigMock->expects($hasParentTheme ? $this->exactly(2) : $this->once())->method('getParentTheme')->willReturn($hasParentTheme ? $parentThemeFromConfigMock : null);
     $themeFromConfigMock->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
     $parentThemeFromDbMock->expects($hasParentTheme ? $this->once() : $this->never())->method('getId')->willReturn($themeId);
     $parentThemeFromConfigMock->expects($hasParentTheme ? $this->once() : $this->never())->method('getFullPath')->willReturn('frontend/Magento/blank');
     $themeFromDbMock->expects($hasParentTheme ? $this->once() : $this->never())->method('setParentId')->with($themeId)->willReturnSelf();
     $themeFromDbMock->expects($this->once())->method('setThemeTitle')->with($themeTitle)->willReturnSelf();
     $themeFromDbMock->expects($this->once())->method('save')->willReturnSelf();
     $this->plugin->beforeDispatch($this->abstractAction, $this->request);
 }
 /**
  * Add area filter
  *
  * @return \Magento\Theme\Model\ResourceModel\Theme\Collection
  */
 protected function _initSelect()
 {
     \Magento\Theme\Model\ResourceModel\Theme\Collection::_initSelect();
     $this->filterVisibleThemes()->addAreaFilter(\Magento\Framework\App\Area::AREA_FRONTEND)->addParentTitle();
     return $this;
 }
Example #14
0
 /**
  * Get virtual theme title
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @return string
  */
 protected function _getVirtualThemeTitle($theme)
 {
     $themeCopyCount = $this->_themeCollection->addAreaFilter(\Magento\Framework\App\Area::AREA_FRONTEND)->addTypeFilter(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL)->addFilter('parent_id', $theme->getId())->count();
     $title = sprintf("%s - %s #%s", $theme->getThemeTitle(), __('Copy'), $themeCopyCount + 1);
     return $title;
 }