Ejemplo n.º 1
0
 /**
  * @test
  * @return void
  */
 public function testLoadData()
 {
     $fileContent = 'content file';
     $media = ['preview_image' => 'preview.jpg'];
     $themeTitle = 'Theme title';
     $themeConfigFile = 'theme.xml';
     $themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock();
     $theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $parentTheme = ['parentThemeCode'];
     $parentThemePath = 'frontend/parent/theme';
     $themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false);
     $themePackage->expects($this->any())->method('getArea')->will($this->returnValue('frontend'));
     $themePackage->expects($this->any())->method('getVendor')->will($this->returnValue('theme'));
     $themePackage->expects($this->any())->method('getName')->will($this->returnValue('code'));
     $this->themePackageList->expects($this->once())->method('getThemes')->will($this->returnValue([$themePackage]));
     $this->directory->expects($this->once())->method('isExist')->with($themeConfigFile)->willReturn(true);
     $this->directory->expects($this->once())->method('readFile')->with($themeConfigFile)->willReturn($fileContent);
     $this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig);
     $this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme);
     $themeConfig->expects($this->once())->method('getMedia')->willReturn($media);
     $themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme);
     $themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
     $theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme/code', 'code' => 'theme/code', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => 'theme/parentThemeCode'])->willReturnSelf();
     $theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath);
     $theme->expects($this->once())->method('getArea')->willReturn('frontend');
     $this->assertInstanceOf(get_class($this->model), $this->model->loadData());
 }
Ejemplo n.º 2
0
 /**
  * @test
  * @return void
  */
 public function testLoadData()
 {
     $relativeDir = 'dir';
     $fileContent = 'content file';
     $media = ['preview_image' => 'preview.jpg'];
     $themeTitle = 'Theme title';
     $themeConfigs = ['frontend/theme/code'];
     $themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock();
     $theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $parentTheme = ['parentThemeCode'];
     $parentThemePath = 'frontend/parent/theme';
     $this->directory->expects($this->once())->method('search')->with($relativeDir)->willReturn($themeConfigs);
     $this->directory->expects($this->any())->method('isExist')->with($themeConfigs[0])->willReturn(true);
     $this->directory->expects($this->any())->method('readFile')->with($themeConfigs[0])->willReturn($fileContent);
     $this->directory->expects($this->any())->method('getRelativePath')->with($themeConfigs[0])->willReturn($themeConfigs[0]);
     $this->directory->expects($this->any())->method('getAbsolutePath')->willReturnMap([[$themeConfigs[0], $themeConfigs[0]], [null, '']]);
     $this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig);
     $this->directory->expects($this->at(1))->method('getAbsolutePath')->willReturn('');
     $this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme);
     $themeConfig->expects($this->once())->method('getMedia')->willReturn($media);
     $themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme);
     $themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
     $theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme', 'code' => 'theme', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => $parentTheme[0]])->willReturnSelf();
     $theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath);
     $theme->expects($this->once())->method('getArea')->willReturn('frontend');
     $this->model->addTargetPattern($relativeDir);
     $this->assertInstanceOf(get_class($this->model), $this->model->loadData());
 }
Ejemplo n.º 3
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();
     }
 }
Ejemplo n.º 4
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();
     }
 }