/** * Cached video config * * @return $this */ protected function initConfig() { if ($this->cachedVideoConfig === null) { $this->cachedVideoConfig = $this->viewConfig->getViewConfig(['area' => Area::AREA_FRONTEND, 'themeModel' => $this->currentTheme]); } return $this; }
/** * @param FallbackContext $assetContext * @return \Magento\Framework\Config\View */ public function getConfig(FallbackContext $assetContext) { $themePath = $assetContext->getAreaCode() . '/' . $assetContext->getThemePath(); if (!isset($this->config[$themePath])) { $this->config[$themePath] = $this->viewConfig->getViewConfig(['area' => $assetContext->getAreaCode(), 'themeModel' => $this->getThemeProvider()->getThemeByFullPath($themePath)]); } return $this->config[$themePath]; }
/** * Retrieve view configuration data * * Collect data for 'Magento_Catalog' module from /etc/view.xml files. * * @return array */ protected function getData() { if (!$this->data) { foreach ($this->themeCollection->loadRegisteredThemes() as $theme) { $config = $this->viewConfig->getViewConfig(['area' => Area::AREA_FRONTEND, 'themeModel' => $theme]); $this->data = array_merge($this->data, $this->applyFilters($config->getVars('Magento_Catalog'))); } } return $this->data; }
/** * 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; }
public function testGenerate() { $imageFile = 'image.jpg'; $imageItem = $this->objectManager->getObject('Magento\\Framework\\Object', ['data' => ['file' => $imageFile]]); $this->mediaGalleryCollection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$imageItem])); $this->product->expects($this->any())->method('getMediaGalleryImages')->willReturn($this->mediaGalleryCollection); $this->config->expects($this->once())->method('getVars')->with('Magento_Catalog')->willReturn($this->getTestData()); $this->viewConfig->expects($this->once())->method('getViewConfig')->with(['area' => Area::AREA_FRONTEND, 'themeModel' => 'Magento\\theme'])->willReturn($this->config); $this->themeCollection->expects($this->once())->method('loadRegisteredThemes')->willReturn(['Magento\\theme']); $this->imageHelper->expects($this->exactly(3))->method('init')->will($this->returnValueMap([[$this->product, 'image', $imageFile, $this->imageHelper], [$this->product, 'small_image', $imageFile, $this->imageHelper], [$this->product, 'thumbnail', $imageFile, $this->imageHelper]])); $this->imageHelper->expects($this->exactly(3))->method('resize')->will($this->returnValueMap([[300, 300, $this->imageHelper], [200, 200, $this->imageHelper], [100, 100, $this->imageHelper]])); $this->imageHelper->expects($this->exactly(3))->method('save')->will($this->returnSelf()); $this->model->generate($this->product); }
/** * Get view config object * * @return \Magento\Framework\Config\View */ protected function _getConfigView() { if (null === $this->_configView) { $this->_configView = $this->_viewConfig->getViewConfig(); } return $this->_configView; }
/** * 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; }
/** * @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); }
public function testGetProductThumbnailUrl() { $url = 'pub/media/catalog/product/cache/1/thumbnail/75x/9df78eab33525d08d6e5fb8d27136e95/_/_/__green.gif'; $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); $configView = $this->getMock('Magento\\Framework\\Config\\View', array('getVarValue'), array(), '', false); $configView->expects($this->any())->method('getVarValue')->will($this->returnValue(75)); $this->_configManager->expects($this->any())->method('getViewConfig')->will($this->returnValue($configView)); $product = $this->getMock('Magento\\Catalog\\Model\\Product', array('isConfigurable', '__wakeup'), array(), '', false); $product->expects($this->any())->method('isConfigurable')->will($this->returnValue(true)); $childProduct = $this->getMock('Magento\\Catalog\\Model\\Product', array('getThumbnail', 'getDataByKey', '__wakeup'), array(), '', false); $childProduct->expects($this->any())->method('getThumbnail')->will($this->returnValue('/_/_/__green.gif')); $this->_imageHelper->expects($this->any())->method('init')->will($this->returnValue($this->_imageHelper)); $this->_imageHelper->expects($this->any())->method('resize')->will($this->returnValue($this->_imageHelper)); $this->_imageHelper->expects($this->any())->method('__toString')->will($this->returnValue($url)); $arguments = array('statusListFactory' => $this->getMock('Magento\\Sales\\Model\\Status\\ListFactory', array(), array(), '', false), 'productFactory' => $this->getMock('Magento\\Catalog\\Model\\ProductFactory', array(), array(), '', false), 'itemOptionFactory' => $this->getMock('Magento\\Sales\\Model\\Quote\\Item\\OptionFactory', array(), array(), '', false)); $childItem = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Quote\\Item', $arguments); $childItem->setData('product', $childProduct); $item = $objectManagerHelper->getObject('Magento\\Sales\\Model\\Quote\\Item', $arguments); $item->setData('product', $product); $item->addChild($childItem); $this->_renderer->setItem($item); $configurableUrl = $this->_renderer->getProductThumbnailUrl(); $this->assertNotNull($configurableUrl); }
/** * @magentoAppIsolation enabled */ public function testGetConfigCustomized() { $this->_emulateFixtureTheme(); /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ $theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\DesignInterface')->getDesignTheme(); $customConfigFile = $theme->getCustomization()->getCustomViewConfigPath(); /** @var $filesystem \Magento\Framework\Filesystem */ $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem'); $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $relativePath = $directory->getRelativePath($customConfigFile); try { $directory->writeFile($relativePath, '<?xml version="1.0" encoding="UTF-8"?> <view><vars module="Namespace_Module"><var name="customVar">custom value</var></vars></view>'); $config = $this->_viewConfig->getViewConfig(); $this->assertInstanceOf('Magento\\Framework\\Config\\View', $config); $this->assertEquals(['customVar' => 'custom value'], $config->getVars('Namespace_Module')); } catch (\Exception $e) { $directory->delete($relativePath); throw $e; } $directory->delete($relativePath); }
/** * Get variable value from view configuration * * Module name can be omitted. If omitted, it will be determined automatically. * * @param string $name variable name * @param string|null $module optional module name * @return string|false */ public function getVar($name, $module = null) { $module = $module ?: $this->getModuleName(); return $this->_viewConfig->getViewConfig()->getVarValue($module, $name); }
/** * @param FallbackContext $assetContext * @return \Magento\Framework\Config\View */ public function getConfig(FallbackContext $assetContext) { return $this->viewConfig->getViewConfig(['area' => $assetContext->getAreaCode(), 'themeModel' => $this->themeList->getThemeByFullPath($assetContext->getAreaCode() . '/' . $assetContext->getThemePath())]); }
/** * Retrieve config view * * @return \Magento\Framework\Config\View */ protected function getConfigView() { if (!$this->configView) { $this->configView = $this->viewConfig->getViewConfig(); } return $this->configView; }
/** * Initialize view configurations * * @return $this */ protected function _initViewConfigs() { $this->_viewConfig = $this->_viewConfigLoader->getViewConfig(array('area' => \Magento\Framework\View\DesignInterface::DEFAULT_AREA, 'themeModel' => $this->_theme)); $this->_viewConfigParent = $this->_viewConfigLoader->getViewConfig(array('area' => \Magento\Framework\View\DesignInterface::DEFAULT_AREA, 'themeModel' => $this->_parentTheme)); return $this; }
/** * @param $data * @param $imageId */ protected function prepareAttributes($data, $imageId) { $configViewMock = $this->getMockBuilder('Magento\\Framework\\Config\\View')->disableOriginalConstructor()->getMock(); $configViewMock->expects($this->once())->method('getMediaAttributes')->with('Magento_Catalog', 'images', $imageId)->willReturn($data); $this->viewConfig->expects($this->once())->method('getViewConfig')->willReturn($configViewMock); }
/** * Retrieve quote item data * * @return array */ private function getQuoteItemData() { $quoteItemData = []; $quoteId = $this->checkoutSession->getQuote()->getId(); if ($quoteId) { $quoteItems = $this->quoteItemRepository->getList($quoteId); foreach ($quoteItems as $index => $quoteItem) { $quoteItemData[$index] = $quoteItem->toArray(); $quoteItemData[$index]['options'] = $this->getFormattedOptionValue($quoteItem); $thumbnailSize = $this->viewConfig->getViewConfig()->getVarValue('Magento_Catalog', 'product_thumbnail_image_size'); $quoteItemData[$index]['thumbnail'] = (string) $this->imageHelper->init($quoteItem->getProduct(), 'thumbnail')->resize($thumbnailSize); } } return $quoteItemData; }