/**
  * @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());
 }
 public function testGetThemes()
 {
     $this->registrar->expects($this->once())->method('getPaths')->with(ComponentRegistrar::THEME)->willReturn(['theme1' => 'path1', 'theme2' => 'path2']);
     $themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false);
     $this->factory->expects($this->exactly(2))->method('create')->withConsecutive(['theme1', 'path1'], ['theme2', 'path2'])->willReturn($themePackage);
     $actual = $this->object->getThemes();
     $this->assertCount(2, $actual);
     foreach ($actual as $themePackage) {
         $this->assertSame($themePackage, $themePackage);
     }
 }
示例#3
0
 /**
  * Find all theme-based email templates for a given template ID
  *
  * @param string $templateId
  * @return array[]
  */
 public function getThemeTemplates($templateId)
 {
     $templates = [];
     $area = $this->getTemplateArea($templateId);
     $module = $this->getTemplateModule($templateId);
     $filename = $this->_getInfo($templateId, 'file');
     foreach ($this->themePackages->getThemes() as $theme) {
         if ($theme->getArea() == $area) {
             $themeDir = $this->readDirFactory->create($theme->getPath());
             $file = "{$module}/email/{$filename}";
             if ($themeDir->isExist($file)) {
                 $templates[] = ['value' => sprintf('%s/%s/%s', $templateId, $theme->getVendor(), $theme->getName()), 'label' => sprintf('%s (%s/%s)', $this->getTemplateLabel($templateId), $theme->getVendor(), $theme->getName()), 'group' => $this->getTemplateModule($templateId)];
             }
         }
     }
     return $templates;
 }
示例#4
0
 public function testGetThemeTemplates()
 {
     $templates = (require __DIR__ . '/Config/_files/email_templates_merged.php');
     $templateId = 'template_one';
     $template = $templates[$templateId];
     $foundThemePath = 'Vendor/custom_theme';
     $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false);
     $theme->expects($this->any())->method('getArea')->willReturn('frontend');
     $theme->expects($this->any())->method('getVendor')->willReturn('Vendor');
     $theme->expects($this->any())->method('getName')->willReturn('custom_theme');
     $theme->expects($this->any())->method('getPath')->willReturn('/theme/path');
     $this->themePackages->expects($this->once())->method('getThemes')->willReturn([$theme]);
     $dir = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $this->readDirFactory->expects($this->once())->method('create')->with('/theme/path')->willReturn($dir);
     $dir->expects($this->once())->method('isExist')->willReturn(true);
     $actualTemplates = $this->model->getThemeTemplates($templateId);
     $this->assertNotEmpty($actualTemplates);
     foreach ($actualTemplates as $templateOptions) {
         $this->assertEquals(sprintf('%s (%s)', $template['label'], $foundThemePath), $templateOptions['label']);
         $this->assertEquals(sprintf('%s/%s', $templateId, $foundThemePath), $templateOptions['value']);
         $this->assertEquals($template['module'], $templateOptions['group']);
     }
 }
 /**
  * Fill collection with theme model loaded from filesystem
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if ($this->isLoaded()) {
         return $this;
     }
     $themes = [];
     foreach ($this->themePackageList->getThemes() as $themePackage) {
         if ($this->isAcceptable(self::CONSTRAINT_AREA, $themePackage->getArea()) && $this->isAcceptable(self::CONSTRAINT_VENDOR, $themePackage->getVendor()) && $this->isAcceptable(self::CONSTRAINT_THEME_NAME, $themePackage->getName())) {
             $themes[] = $themePackage;
         }
     }
     $this->_loadFromFilesystem($themes);
     $this->resetConstraints();
     $this->_updateRelations()->_renderFilters()->_clearFilters();
     return $this;
 }
示例#6
0
 /**
  * Collect templates from themes
  *
  * @param bool $withMetaInfo
  * @param array $result
  * @return void
  */
 private function accumulateThemeTemplateFiles($withMetaInfo, array &$result)
 {
     foreach ($this->themePackageList->getThemes() as $theme) {
         $files = [];
         $this->_accumulateFilesByPatterns([$theme->getPath() . '/*_*/templates'], '*.phtml', $files);
         if ($withMetaInfo) {
             $regex = '#^' . str_replace(DIRECTORY_SEPARATOR, '/', $theme->getPath()) . '/(?P<module>[a-z\\d]+_[a-z\\d]+)/templates/(?P<path>.+)$#i';
             foreach ($files as $file) {
                 if (preg_match($regex, $file, $matches)) {
                     $result[] = [$theme->getArea(), $theme->getVendor() . '/' . $theme->getName(), $matches['module'], $matches['path'], $file];
                 } else {
                     echo $regex . " - " . $file . "\n";
                     throw new \UnexpectedValueException("Could not parse theme template file '{$file}'");
                 }
             }
         } else {
             $result = array_merge($result, $files);
         }
     }
 }