Пример #1
0
 /**
  * @covers \Magento\DesignEditor\Block\Adminhtml\Editor\Tools\Code\Js::getFiles
  */
 public function testGetJsFiles()
 {
     $customization = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\Customization', [], [], '', false);
     $this->_theme->expects($this->any())->method('getCustomization')->will($this->returnValue($customization));
     $customization->expects($this->once())->method('getFilesByType')->with(\Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE)->will($this->returnValue([]));
     $customization->expects($this->once())->method('generateFileInfo')->with([])->will($this->returnValue(['js' => 'files']));
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['js' => 'files'])->will($this->returnValue('someData'));
     $this->assertEquals('someData', $this->_model->getFiles());
 }
Пример #2
0
 protected function setUp()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_model = $objectManager->create('Magento\\Theme\\Model\\Theme\\File');
     /** @var $themeModel \Magento\Framework\View\Design\ThemeInterface */
     $themeModel = $objectManager->create('Magento\\Framework\\View\\Design\\ThemeInterface');
     $this->_theme = $themeModel->getCollection()->getFirstItem();
     $this->_data = ['file_path' => 'main.css', 'file_type' => 'css', 'content' => 'content files', 'order' => 0, 'theme' => $this->_theme, 'theme_id' => $this->_theme->getId()];
 }
Пример #3
0
 public function testGetCacheKeyInfo()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $context = $objectManager->get('Magento\\Framework\\App\\Http\\Context');
     $context->setValue(Context::CONTEXT_AUTH, false, false);
     $block = $objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Theme\\Block\\Html\\Footer');
     $storeId = $objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore()->getId();
     $this->assertEquals(['PAGE_FOOTER', $storeId, 0, $this->_theme->getId(), null], $block->getCacheKeyInfo());
 }
Пример #4
0
 /**
  * Set theme which will be editable in store designer
  *
  * @param int $themeId
  * @return $this
  * @throws CoreException
  */
 public function setEditableThemeById($themeId)
 {
     $this->_theme = $this->_themeFactory->create();
     if (!$this->_theme->load($themeId)->getId()) {
         throw new CoreException(__('We can\'t find theme "%1".', $themeId));
     }
     if ($this->_theme->getType() === \Magento\Framework\View\Design\ThemeInterface::TYPE_STAGING) {
         throw new CoreException(__('Wrong theme type set as editable'));
     }
     return $this;
 }
Пример #5
0
 public function testGetCustomCssContent()
 {
     $expectedContent = 'New file content';
     $customization = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\Customization', [], [], '', false);
     $this->_theme->expects($this->any())->method('getCustomization')->will($this->returnValue($customization));
     /** @var $cssFile \Magento\Framework\View\Design\Theme\Customization\File\Css */
     $cssFile = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\Customization\\File\\Css', ['getContent'], [], '', false);
     $customization->expects($this->once())->method('getFilesByType')->with(\Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE)->will($this->returnValue([$cssFile]));
     $cssFile->expects($this->once())->method('getContent')->will($this->returnValue('New file content'));
     $this->assertEquals($expectedContent, $this->_model->getCustomCssContent());
 }
Пример #6
0
 public function toArray()
 {
     $themes = $this->_collectionThemeFactory->create();
     $file = $this->_filesystem->getDirectoryRead(DirectoryList::APP)->getAbsolutePath('design/frontend/');
     $vesPackagePaths = glob($file . '*/*/config.xml');
     $output = [];
     foreach ($vesPackagePaths as $k => $v) {
         $v = str_replace("/config.xml", "", $v);
         $output[str_replace($file, "", $v)] = ucfirst(str_replace($file, "", $v));
     }
     return $output;
 }
Пример #7
0
 /**
  * Save customized DOM of view configuration
  *
  * @param \DOMDocument $config
  * @return $this
  */
 protected function _saveViewConfiguration(\DOMDocument $config)
 {
     $targetPath = $this->_theme->getCustomization()->getCustomViewConfigPath();
     $directory = $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $directory->writeFile($directory->getRelativePath($targetPath), $config->saveXML());
     return $this;
 }
 /**
  * Apply customized static files to frontend
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var $themeFile \Magento\Theme\Model\Theme\File */
     foreach ($this->currentTheme->getCustomization()->getFiles() as $themeFile) {
         try {
             $service = $themeFile->getCustomizationService();
             if ($service instanceof \Magento\Framework\View\Design\Theme\Customization\FileAssetInterface) {
                 $identifier = $themeFile->getData('file_path');
                 $dirPath = \Magento\Framework\View\Design\Theme\Customization\Path::DIR_NAME . '/' . $this->currentTheme->getId();
                 $asset = $this->assetRepo->createArbitrary($identifier, $dirPath, DirectoryList::MEDIA, \Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
                 $this->pageAssets->add($identifier, $asset);
             }
         } catch (\InvalidArgumentException $e) {
             $this->logger->critical($e);
         }
     }
 }
Пример #9
0
 /**
  * @dataProvider themeDataProvider
  */
 public function testGetVisibleTheme($isVirtual)
 {
     $this->_setEditableTheme();
     $this->_theme->expects($this->atLeastOnce())->method('isVirtual')->will($this->returnValue($isVirtual));
     if ($isVirtual) {
         $themeObject = $this->_setStagingTheme();
         $this->assertEquals($themeObject, $this->_model->getVisibleTheme());
     } else {
         $this->assertEquals($this->_theme, $this->_model->getVisibleTheme());
     }
 }
Пример #10
0
 protected function setUp()
 {
     $this->customizationPath = '/' . implode('/', ['var', 'theme']);
     $this->request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $this->session = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false);
     $this->contextHelper = $this->getMock('Magento\\Framework\\App\\Helper\\Context', [], [], '', false);
     $this->directoryWrite = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', [], [], '', false);
     $this->themeFactory = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory', [], [], '', false);
     $this->theme = $this->getMock('Magento\\Theme\\Model\\Theme', [], [], '', false);
     $this->customization = $this->getMock('Magento\\Framework\\View\\Design\\Theme\\Customization', [], [], '', false);
     $this->filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($this->directoryWrite));
     $this->directoryWrite->expects($this->any())->method('create')->will($this->returnValue(true));
     $this->contextHelper->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
     $this->themeFactory->expects($this->any())->method('create')->will($this->returnValue($this->theme));
     $this->theme->expects($this->any())->method('getCustomization')->will($this->returnValue($this->customization));
     $this->request->expects($this->at(0))->method('getParam')->with(\Magento\Theme\Helper\Storage::PARAM_THEME_ID)->will($this->returnValue(6));
     $this->request->expects($this->at(1))->method('getParam')->with(\Magento\Theme\Helper\Storage::PARAM_CONTENT_TYPE)->will($this->returnValue(\Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE));
     $this->helper = new \Magento\Theme\Helper\Storage($this->contextHelper, $this->filesystem, $this->session, $this->themeFactory);
 }
Пример #11
0
 public function getExportPackages()
 {
     $themes = $this->_collectionThemeFactory->create();
     $file = $this->_filesystem->getDirectoryRead(DirectoryList::APP)->getAbsolutePath('design/frontend/');
     $vesPackagePaths = glob($file . '*/config.xml');
     $output = [];
     foreach ($vesPackagePaths as $k => $v) {
         $v = str_replace("config.xml", "", $v);
         $themes = array_filter(glob($v . '*'), 'is_dir');
         foreach ($themes as $k => $v) {
             $output[] = array('label' => ucfirst(str_replace($file, "", $v)), 'value' => str_replace($file, "", $v));
         }
     }
     return $output;
 }
Пример #12
0
 /**
  * @param mixed $originalCode
  * @param string $expectedCode
  * @dataProvider getCodeDataProvider
  */
 public function testGetCode($originalCode, $expectedCode)
 {
     $this->_model->setCode($originalCode);
     $this->assertSame($expectedCode, $this->_model->getCode());
 }
Пример #13
0
 /**
  * @test
  * @return void
  */
 public function getParentTheme()
 {
     $this->_model->setParentTheme('parent_theme');
     $this->assertEquals('parent_theme', $this->_model->getParentTheme());
 }
Пример #14
0
 /**
  * @covers \Magento\Framework\View\Design\Theme\Image::getPreviewImageUrl
  */
 public function testGetDefaultPreviewImageUrl()
 {
     $this->_themeMock->setData($this->_getThemeSampleData());
     $this->_themeMock->setData('preview_image', null);
     $this->assertEquals('http://localhost/media_path/test_default_preview.png', $this->_model->getPreviewImageUrl());
 }
Пример #15
0
 /**
  * Retrieve cache identifier taking into account current area/package/theme/store
  *
  * @param string $suffix
  * @return string
  */
 protected function _getCacheId($suffix = '')
 {
     return "LAYOUT_{$this->_theme->getArea()}_STORE{$this->_store->getId()}_{$this->_theme->getId()}{$suffix}";
 }
Пример #16
0
 /**
  * Use this method only with database isolation
  *
  * @return \Magento\Theme\Model\Theme
  */
 protected function _getTestTheme()
 {
     $theme = $this->_theme->getCollection()->getThemeByFullPath(implode(\Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR, ['frontend', 'Test/test_theme']));
     $this->assertNotEmpty($theme->getId());
     return $theme;
 }
Пример #17
0
 /**
  * @covers \Magento\Framework\View\Design\Theme\Customization\Path::getCustomViewConfigPath
  */
 public function testGetCustomViewConfigPathNoId()
 {
     $this->_theme->expects($this->once())->method('getId')->will($this->returnValue(null));
     $this->assertNull($this->_model->getCustomViewConfigPath($this->_theme));
 }