diff --git a/app/code/Magento/Catalog/Block/Rss/Category.php b/app/code/Magento/Catalog/Block/Rss/Category.php index f149114f2eab8..50967d2eb8dca 100644 --- a/app/code/Magento/Catalog/Block/Rss/Category.php +++ b/app/code/Magento/Catalog/Block/Rss/Category.php @@ -10,7 +10,9 @@ use Magento\Framework\Exception\NoSuchEntityException; /** - * Category feed block + * Class Category + * + * @package Magento\Catalog\Block\Rss * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ diff --git a/app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php b/app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php index 9ade8b198656c..20c4bef0845d6 100644 --- a/app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php +++ b/app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php @@ -8,7 +8,8 @@ use Magento\Framework\App\Rss\DataProviderInterface; /** - * New products feed block + * Class NewProducts + * @package Magento\Catalog\Block\Rss\Product */ class NewProducts extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface { @@ -54,8 +55,6 @@ public function __construct( } /** - * Init - * * @return void */ protected function _construct() @@ -65,7 +64,7 @@ protected function _construct() } /** - * @inheritdoc + * {@inheritdoc} */ public function isAllowed() { @@ -73,7 +72,7 @@ public function isAllowed() } /** - * @inheritdoc + * {@inheritdoc} */ public function getRssData() { @@ -98,13 +97,10 @@ public function getRssData() $item->setAllowedInRss(true); $item->setAllowedPriceInRss(true); - $this->_eventManager->dispatch( - 'rss_catalog_new_xml_callback', - [ - 'row' => $item->getData(), - 'product' => $item - ] - ); + $this->_eventManager->dispatch('rss_catalog_new_xml_callback', [ + 'row' => $item->getData(), + 'product' => $item + ]); if (!$item->getAllowedInRss()) { continue; @@ -136,8 +132,6 @@ public function getRssData() } /** - * Get store id - * * @return int */ protected function getStoreId() @@ -183,7 +177,7 @@ protected function renderPriceHtml(\Magento\Catalog\Model\Product $product) } /** - * @inheritdoc + * {@inheritdoc} */ public function getCacheLifetime() { @@ -191,8 +185,6 @@ public function getCacheLifetime() } /** - * Get feeds - * * @return array */ public function getFeeds() @@ -207,7 +199,7 @@ public function getFeeds() } /** - * @inheritdoc + * {@inheritdoc} */ public function isAuthRequired() { diff --git a/app/code/Magento/Catalog/Block/Rss/Product/Special.php b/app/code/Magento/Catalog/Block/Rss/Product/Special.php index 5e459413bb5a2..a9107f14cc5e4 100644 --- a/app/code/Magento/Catalog/Block/Rss/Product/Special.php +++ b/app/code/Magento/Catalog/Block/Rss/Product/Special.php @@ -9,7 +9,8 @@ use Magento\Framework\App\Rss\DataProviderInterface; /** - * Special products feed block + * Class Special + * @package Magento\Catalog\Block\Rss\Product * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Special extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface @@ -97,8 +98,6 @@ public function __construct( } /** - * Init - * * @return void */ protected function _construct() @@ -108,8 +107,6 @@ protected function _construct() } /** - * Get RSS data - * * @return array */ public function getRssData() @@ -159,8 +156,6 @@ public function getRssData() } /** - * Get entry data - * * @param \Magento\Catalog\Model\Product $item * @return array */ @@ -250,7 +245,7 @@ public function isAllowed() } /** - * @inheritdoc + * {@inheritdoc} */ public function getCacheLifetime() { @@ -258,8 +253,6 @@ public function getCacheLifetime() } /** - * Get feeds - * * @return array */ public function getFeeds() @@ -273,7 +266,7 @@ public function getFeeds() } /** - * @inheritdoc + * {@inheritdoc} */ public function isAuthRequired() { diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php index 3e7cc3ee962b9..d43b313c43b3e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php @@ -11,7 +11,7 @@ use Magento\Framework\Exception\LocalizedException; /** - * Upload product image action controller + * Class Upload */ class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterface { diff --git a/app/code/Magento/Catalog/Helper/Image.php b/app/code/Magento/Catalog/Helper/Image.php index 5b0aa0c496ecd..110b798df9df9 100644 --- a/app/code/Magento/Catalog/Helper/Image.php +++ b/app/code/Magento/Catalog/Helper/Image.php @@ -5,19 +5,14 @@ */ namespace Magento\Catalog\Helper; -use Magento\Catalog\Model\Config\CatalogMediaConfig; -use Magento\Catalog\Model\View\Asset\PlaceholderFactory; use Magento\Framework\App\Helper\AbstractHelper; -use Magento\Framework\App\ObjectManager; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Element\Block\ArgumentInterface; /** - * Catalog image helper. + * Catalog image helper * * @api * @SuppressWarnings(PHPMD.TooManyFields) - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @since 100.0.2 */ class Image extends AbstractHelper implements ArgumentInterface @@ -45,7 +40,6 @@ class Image extends AbstractHelper implements ArgumentInterface * Scheduled for rotate image * * @var bool - * @deprecated unused */ protected $_scheduleRotate = false; @@ -53,7 +47,6 @@ class Image extends AbstractHelper implements ArgumentInterface * Angle * * @var int - * @deprecated unused */ protected $_angle; @@ -136,38 +129,31 @@ class Image extends AbstractHelper implements ArgumentInterface protected $attributes = []; /** - * @var PlaceholderFactory + * @var \Magento\Catalog\Model\View\Asset\PlaceholderFactory */ private $viewAssetPlaceholderFactory; - /** - * @var CatalogMediaConfig - */ - private $mediaConfig; - /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Catalog\Model\Product\ImageFactory $productImageFactory * @param \Magento\Framework\View\Asset\Repository $assetRepo * @param \Magento\Framework\View\ConfigInterface $viewConfig - * @param PlaceholderFactory $placeholderFactory - * @param CatalogMediaConfig $mediaConfig + * @param \Magento\Catalog\Model\View\Asset\PlaceholderFactory $placeholderFactory */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product\ImageFactory $productImageFactory, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\View\ConfigInterface $viewConfig, - PlaceholderFactory $placeholderFactory = null, - CatalogMediaConfig $mediaConfig = null + \Magento\Catalog\Model\View\Asset\PlaceholderFactory $placeholderFactory = null ) { $this->_productImageFactory = $productImageFactory; parent::__construct($context); $this->_assetRepo = $assetRepo; $this->viewConfig = $viewConfig; $this->viewAssetPlaceholderFactory = $placeholderFactory - ?: ObjectManager::getInstance()->get(PlaceholderFactory::class); - $this->mediaConfig = $mediaConfig ?: ObjectManager::getInstance()->get(CatalogMediaConfig::class); + ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Catalog\Model\View\Asset\PlaceholderFactory::class); } /** @@ -396,10 +382,9 @@ public function constrainOnly($flag) */ public function backgroundColor($colorRGB) { - $args = func_get_args(); // assume that 3 params were given instead of array if (!is_array($colorRGB)) { - $colorRGB = $args; + $colorRGB = func_get_args(); } $this->_getModel()->setBackgroundColor($colorRGB); return $this; @@ -410,7 +395,6 @@ public function backgroundColor($colorRGB) * * @param int $angle * @return $this - * @deprecated unused */ public function rotate($angle) { @@ -542,16 +526,7 @@ protected function isScheduledActionsAllowed() public function getUrl() { try { - switch ($this->mediaConfig->getMediaUrlFormat()) { - case CatalogMediaConfig::IMAGE_OPTIMIZATION_PARAMETERS: - $this->initBaseFile(); - break; - case CatalogMediaConfig::HASH: - $this->applyScheduledActions(); - break; - default: - throw new LocalizedException(__("The specified Catalog media URL format is not supported.")); - } + $this->applyScheduledActions(); return $this->_getModel()->getUrl(); } catch (\Exception $e) { return $this->getDefaultPlaceholderUrl(); @@ -620,7 +595,6 @@ protected function _getModel() * * @param int $angle * @return $this - * @deprecated unused */ protected function setAngle($angle) { @@ -632,7 +606,6 @@ protected function setAngle($angle) * Get Rotation Angle * * @return int - * @deprecated unused */ protected function getAngle() { diff --git a/app/code/Magento/Catalog/Model/Config/CatalogMediaConfig.php b/app/code/Magento/Catalog/Model/Config/CatalogMediaConfig.php deleted file mode 100644 index 9e5394f0d6585..0000000000000 --- a/app/code/Magento/Catalog/Model/Config/CatalogMediaConfig.php +++ /dev/null @@ -1,50 +0,0 @@ -scopeConfig = $scopeConfig; - } - - /** - * Get media URL format for catalog images - * - * @param string $scopeType - * @param null|int|string $scopeCode - * @return string - */ - public function getMediaUrlFormat($scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null) - { - return $this->scopeConfig->getValue( - CatalogMediaConfig::XML_PATH_CATALOG_MEDIA_URL_FORMAT, - $scopeType, - $scopeCode - ); - } -} diff --git a/app/code/Magento/Catalog/Model/Config/Source/Web/CatalogMediaUrlFormat.php b/app/code/Magento/Catalog/Model/Config/Source/Web/CatalogMediaUrlFormat.php deleted file mode 100644 index f24044fc92c95..0000000000000 --- a/app/code/Magento/Catalog/Model/Config/Source/Web/CatalogMediaUrlFormat.php +++ /dev/null @@ -1,30 +0,0 @@ - CatalogMediaConfig::IMAGE_OPTIMIZATION_PARAMETERS, - 'label' => __('Image optimization based on query parameters') - ], - ['value' => CatalogMediaConfig::HASH, 'label' => __('Unique hash per image variant (Legacy mode)')] - ]; - } -} diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index 7c2a53768fd47..a0be36c5a327c 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -10,11 +10,9 @@ use Magento\Catalog\Model\View\Asset\PlaceholderFactory; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ObjectManager; -use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Image as MagentoImage; use Magento\Framework\Serialize\SerializerInterface; use Magento\Catalog\Model\Product\Image\ParamsBuilder; -use Magento\Framework\Filesystem\Driver\File as FilesystemDriver; /** * Image operations @@ -103,7 +101,6 @@ class Image extends \Magento\Framework\Model\AbstractModel /** * @var int - * @deprecated unused */ protected $_angle; @@ -202,11 +199,6 @@ class Image extends \Magento\Framework\Model\AbstractModel */ private $serializer; - /** - * @var FilesystemDriver - */ - private $filesystemDriver; - /** * Constructor * @@ -227,8 +219,6 @@ class Image extends \Magento\Framework\Model\AbstractModel * @param array $data * @param SerializerInterface $serializer * @param ParamsBuilder $paramsBuilder - * @param FilesystemDriver $filesystemDriver - * @throws \Magento\Framework\Exception\FileSystemException * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ @@ -249,8 +239,7 @@ public function __construct( \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], SerializerInterface $serializer = null, - ParamsBuilder $paramsBuilder = null, - FilesystemDriver $filesystemDriver = null + ParamsBuilder $paramsBuilder = null ) { $this->_storeManager = $storeManager; $this->_catalogProductMediaConfig = $catalogProductMediaConfig; @@ -265,7 +254,6 @@ public function __construct( $this->viewAssetPlaceholderFactory = $viewAssetPlaceholderFactory; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->paramsBuilder = $paramsBuilder ?: ObjectManager::getInstance()->get(ParamsBuilder::class); - $this->filesystemDriver = $filesystemDriver ?: ObjectManager::getInstance()->get(FilesystemDriver::class); } /** @@ -536,7 +524,6 @@ public function resize() * * @param int $angle * @return $this - * @deprecated unused */ public function rotate($angle) { @@ -552,7 +539,6 @@ public function rotate($angle) * * @param int $angle * @return $this - * @deprecated unused */ public function setAngle($angle) { @@ -677,12 +663,7 @@ public function getDestinationSubdir() public function isCached() { $path = $this->imageAsset->getPath(); - try { - $isCached = is_array($this->loadImageInfoFromCache($path)) || $this->filesystemDriver->isExists($path); - } catch (FileSystemException $e) { - $isCached = false; - } - return $isCached; + return is_array($this->loadImageInfoFromCache($path)) || file_exists($path); } /** diff --git a/app/code/Magento/Catalog/Model/View/Asset/Image.php b/app/code/Magento/Catalog/Model/View/Asset/Image.php index da1009ab1125c..c547ec612bb94 100644 --- a/app/code/Magento/Catalog/Model/View/Asset/Image.php +++ b/app/code/Magento/Catalog/Model/View/Asset/Image.php @@ -6,16 +6,11 @@ namespace Magento\Catalog\Model\View\Asset; -use Magento\Catalog\Model\Config\CatalogMediaConfig; use Magento\Catalog\Model\Product\Media\ConfigInterface; use Magento\Framework\Encryption\Encryptor; use Magento\Framework\Encryption\EncryptorInterface; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\View\Asset\ContextInterface; use Magento\Framework\View\Asset\LocalInterface; -use Magento\Catalog\Helper\Image as ImageHelper; -use Magento\Framework\App\ObjectManager; -use Magento\Store\Model\StoreManagerInterface; /** * A locally available image file asset that can be referred with a file path @@ -63,21 +58,6 @@ class Image implements LocalInterface */ private $encryptor; - /** - * @var ImageHelper - */ - private $imageHelper; - - /** - * @var CatalogMediaConfig - */ - private $catalogMediaConfig; - - /** - * @var StoreManagerInterface - */ - private $storeManager; - /** * Image constructor. * @@ -86,19 +66,13 @@ class Image implements LocalInterface * @param EncryptorInterface $encryptor * @param string $filePath * @param array $miscParams - * @param ImageHelper $imageHelper - * @param CatalogMediaConfig $catalogMediaConfig - * @param StoreManagerInterface $storeManager */ public function __construct( ConfigInterface $mediaConfig, ContextInterface $context, EncryptorInterface $encryptor, $filePath, - array $miscParams, - ImageHelper $imageHelper = null, - CatalogMediaConfig $catalogMediaConfig = null, - StoreManagerInterface $storeManager = null + array $miscParams ) { if (isset($miscParams['image_type'])) { $this->sourceContentType = $miscParams['image_type']; @@ -111,72 +85,14 @@ public function __construct( $this->filePath = $filePath; $this->miscParams = $miscParams; $this->encryptor = $encryptor; - $this->imageHelper = $imageHelper ?: ObjectManager::getInstance()->get(ImageHelper::class); - $this->catalogMediaConfig = $catalogMediaConfig ?: ObjectManager::getInstance()->get(CatalogMediaConfig::class); - $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class); } /** - * Get catalog image URL. - * - * @return string - * @throws LocalizedException + * @inheritdoc */ public function getUrl() { - $mediaUrlFormat = $this->catalogMediaConfig->getMediaUrlFormat(); - switch ($mediaUrlFormat) { - case CatalogMediaConfig::IMAGE_OPTIMIZATION_PARAMETERS: - return $this->getUrlWithTransformationParameters(); - case CatalogMediaConfig::HASH: - return $this->context->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getImageInfo(); - default: - throw new LocalizedException( - __("The specified Catalog media URL format '$mediaUrlFormat' is not supported.") - ); - } - } - - /** - * Get image URL with transformation parameters - * - * @return string - */ - private function getUrlWithTransformationParameters() - { - return $this->getOriginalImageUrl() . '?' . http_build_query($this->getImageTransformationParameters()); - } - - /** - * The list of parameters to be used during image transformations (e.g. resizing or applying watermarks). - * - * This method can be used as an extension point. - * - * @return string[] - */ - public function getImageTransformationParameters() - { - return [ - 'width' => $this->miscParams['image_width'], - 'height' => $this->miscParams['image_height'], - 'store' => $this->storeManager->getStore()->getCode(), - 'image-type' => $this->sourceContentType - ]; - } - - /** - * Get URL to the original version of the product image. - * - * @return string - */ - private function getOriginalImageUrl() - { - $originalImageFile = $this->getSourceFile(); - if (!$originalImageFile) { - return $this->imageHelper->getDefaultPlaceholderUrl(); - } else { - return $this->context->getBaseUrl() . $this->getFilePath(); - } + return $this->context->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getImageInfo(); } /** diff --git a/app/code/Magento/Catalog/Observer/ImageResizeAfterProductSave.php b/app/code/Magento/Catalog/Observer/ImageResizeAfterProductSave.php index 54b655a217a08..91d2868afab8c 100644 --- a/app/code/Magento/Catalog/Observer/ImageResizeAfterProductSave.php +++ b/app/code/Magento/Catalog/Observer/ImageResizeAfterProductSave.php @@ -10,11 +10,7 @@ use Magento\Framework\Event\ObserverInterface; use Magento\Framework\App\State; use Magento\MediaStorage\Service\ImageResize; -use Magento\Catalog\Model\Config\CatalogMediaConfig; -/** - * Resize product images after the product is saved - */ class ImageResizeAfterProductSave implements ObserverInterface { /** @@ -27,26 +23,17 @@ class ImageResizeAfterProductSave implements ObserverInterface */ private $state; - /** - * @var CatalogMediaConfig - */ - private $catalogMediaConfig; - /** * Product constructor. - * * @param ImageResize $imageResize * @param State $state - * @param CatalogMediaConfig $catalogMediaConfig */ public function __construct( ImageResize $imageResize, - State $state, - CatalogMediaConfig $catalogMediaConfig + State $state ) { $this->imageResize = $imageResize; $this->state = $state; - $this->catalogMediaConfig = $catalogMediaConfig; } /** @@ -57,12 +44,6 @@ public function __construct( */ public function execute(\Magento\Framework\Event\Observer $observer) { - $catalogMediaUrlFormat = $this->catalogMediaConfig->getMediaUrlFormat(); - if ($catalogMediaUrlFormat == CatalogMediaConfig::IMAGE_OPTIMIZATION_PARAMETERS) { - // Skip image resizing on the Magento side when it is offloaded to a web server or CDN - return; - } - /** @var $product \Magento\Catalog\Model\Product */ $product = $observer->getEvent()->getProduct(); diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php new file mode 100644 index 0000000000000..9a2199859a1df --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php @@ -0,0 +1,442 @@ +fileSystemMock = $this->createPartialMock( + \Magento\Framework\Filesystem::class, + ['stat', 'getDirectoryRead'] + ); + $this->readMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class); + $this->galleryMock = $this->createMock(\Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery::class); + $this->mediaConfigMock = $this->createPartialMock( + \Magento\Catalog\Model\Product\Media\Config::class, + ['getMediaUrl', 'getMediaPath'] + ); + $this->jsonEncoderMock = $this->getMockBuilder(\Magento\Framework\Json\EncoderInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->databaseMock = $this->getMockBuilder(Database::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->content = $this->objectManager->getObject( + \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content::class, + [ + 'mediaConfig' => $this->mediaConfigMock, + 'jsonEncoder' => $this->jsonEncoderMock, + 'filesystem' => $this->fileSystemMock, + 'fileStorageDatabase' => $this->databaseMock + ] + ); + } + + public function testGetImagesJson() + { + $url = [ + ['file_1.jpg', 'url_to_the_image/image_1.jpg'], + ['file_2.jpg', 'url_to_the_image/image_2.jpg'] + ]; + $mediaPath = [ + ['file_1.jpg', 'catalog/product/image_1.jpg'], + ['file_2.jpg', 'catalog/product/image_2.jpg'] + ]; + + $sizeMap = [ + ['catalog/product/image_1.jpg', ['size' => 399659]], + ['catalog/product/image_2.jpg', ['size' => 879394]] + ]; + + $imagesResult = [ + [ + 'value_id' => '2', + 'file' => 'file_2.jpg', + 'media_type' => 'image', + 'position' => '0', + 'url' => 'url_to_the_image/image_2.jpg', + 'size' => 879394 + ], + [ + 'value_id' => '1', + 'file' => 'file_1.jpg', + 'media_type' => 'image', + 'position' => '1', + 'url' => 'url_to_the_image/image_1.jpg', + 'size' => 399659 + ] + ]; + + $images = [ + 'images' => [ + [ + 'value_id' => '1', + 'file' => 'file_1.jpg', + 'media_type' => 'image', + 'position' => '1' + ] , + [ + 'value_id' => '2', + 'file' => 'file_2.jpg', + 'media_type' => 'image', + 'position' => '0' + ] + ] + ]; + + $this->content->setElement($this->galleryMock); + $this->galleryMock->expects($this->once())->method('getImages')->willReturn($images); + $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock); + + $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url); + $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath); + $this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap); + $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode'); + + $this->readMock->expects($this->any()) + ->method('isFile') + ->will($this->returnValue(true)); + $this->databaseMock->expects($this->any()) + ->method('checkDbUsage') + ->will($this->returnValue(false)); + + $this->assertSame(json_encode($imagesResult), $this->content->getImagesJson()); + } + + public function testGetImagesJsonWithoutImages() + { + $this->content->setElement($this->galleryMock); + $this->galleryMock->expects($this->once())->method('getImages')->willReturn(null); + + $this->assertSame('[]', $this->content->getImagesJson()); + } + + public function testGetImagesJsonWithException() + { + $this->imageHelper = $this->getMockBuilder(\Magento\Catalog\Helper\Image::class) + ->disableOriginalConstructor() + ->setMethods(['getDefaultPlaceholderUrl']) + ->getMock(); + + $this->objectManager->setBackwardCompatibleProperty( + $this->content, + 'imageHelper', + $this->imageHelper + ); + + $placeholderUrl = 'url_to_the_placeholder/placeholder.jpg'; + + $imagesResult = [ + [ + 'value_id' => '2', + 'file' => 'file_2.jpg', + 'media_type' => 'image', + 'position' => '0', + 'url' => 'url_to_the_placeholder/placeholder.jpg', + 'size' => 0 + ], + [ + 'value_id' => '1', + 'file' => 'file_1.jpg', + 'media_type' => 'image', + 'position' => '1', + 'url' => 'url_to_the_placeholder/placeholder.jpg', + 'size' => 0 + ] + ]; + + $images = [ + 'images' => [ + [ + 'value_id' => '1', + 'file' => 'file_1.jpg', + 'media_type' => 'image', + 'position' => '1' + ], + [ + 'value_id' => '2', + 'file' => 'file_2.jpg', + 'media_type' => 'image', + 'position' => '0' + ] + ] + ]; + + $this->content->setElement($this->galleryMock); + $this->galleryMock->expects($this->once())->method('getImages')->willReturn($images); + $this->fileSystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($this->readMock); + $this->mediaConfigMock->expects($this->any())->method('getMediaUrl'); + $this->mediaConfigMock->expects($this->any())->method('getMediaPath'); + + $this->readMock->expects($this->any()) + ->method('isFile') + ->will($this->returnValue(true)); + $this->databaseMock->expects($this->any()) + ->method('checkDbUsage') + ->will($this->returnValue(false)); + + $this->readMock->expects($this->any())->method('stat')->willReturnOnConsecutiveCalls( + $this->throwException( + new \Magento\Framework\Exception\FileSystemException(new Phrase('test')) + ), + $this->throwException( + new \Magento\Framework\Exception\FileSystemException(new Phrase('test')) + ) + ); + $this->imageHelper->expects($this->any())->method('getDefaultPlaceholderUrl')->willReturn($placeholderUrl); + $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode'); + + $this->assertSame(json_encode($imagesResult), $this->content->getImagesJson()); + } + + /** + * Test GetImageTypes() will return value for given attribute from data persistor. + * + * @return void + */ + public function testGetImageTypesFromDataPersistor() + { + $attributeCode = 'thumbnail'; + $value = 'testImageValue'; + $scopeLabel = 'testScopeLabel'; + $label = 'testLabel'; + $name = 'testName'; + $expectedTypes = [ + $attributeCode => [ + 'code' => $attributeCode, + 'value' => $value, + 'label' => $label, + 'name' => $name, + ], + ]; + $product = $this->getMockBuilder(Product::class) + ->disableOriginalConstructor() + ->getMock(); + $product->expects($this->once()) + ->method('getData') + ->with($this->identicalTo($attributeCode)) + ->willReturn(null); + $mediaAttribute = $this->getMediaAttribute($label, $attributeCode); + $product->expects($this->once()) + ->method('getMediaAttributes') + ->willReturn([$mediaAttribute]); + $this->galleryMock->expects($this->exactly(2)) + ->method('getDataObject') + ->willReturn($product); + $this->galleryMock->expects($this->once()) + ->method('getImageValue') + ->with($this->identicalTo($attributeCode)) + ->willReturn($value); + $this->galleryMock->expects($this->once()) + ->method('getScopeLabel') + ->with($this->identicalTo($mediaAttribute)) + ->willReturn($scopeLabel); + $this->galleryMock->expects($this->once()) + ->method('getAttributeFieldName') + ->with($this->identicalTo($mediaAttribute)) + ->willReturn($name); + $this->getImageTypesAssertions($attributeCode, $scopeLabel, $expectedTypes); + } + + /** + * Test GetImageTypes() will return value for given attribute from product. + * + * @return void + */ + public function testGetImageTypesFromProduct() + { + $attributeCode = 'thumbnail'; + $value = 'testImageValue'; + $scopeLabel = 'testScopeLabel'; + $label = 'testLabel'; + $name = 'testName'; + $expectedTypes = [ + $attributeCode => [ + 'code' => $attributeCode, + 'value' => $value, + 'label' => $label, + 'name' => $name, + ], + ]; + $product = $this->getMockBuilder(Product::class) + ->disableOriginalConstructor() + ->getMock(); + $product->expects($this->once()) + ->method('getData') + ->with($this->identicalTo($attributeCode)) + ->willReturn($value); + $mediaAttribute = $this->getMediaAttribute($label, $attributeCode); + $product->expects($this->once()) + ->method('getMediaAttributes') + ->willReturn([$mediaAttribute]); + $this->galleryMock->expects($this->exactly(2)) + ->method('getDataObject') + ->willReturn($product); + $this->galleryMock->expects($this->never()) + ->method('getImageValue'); + $this->galleryMock->expects($this->once()) + ->method('getScopeLabel') + ->with($this->identicalTo($mediaAttribute)) + ->willReturn($scopeLabel); + $this->galleryMock->expects($this->once()) + ->method('getAttributeFieldName') + ->with($this->identicalTo($mediaAttribute)) + ->willReturn($name); + $this->getImageTypesAssertions($attributeCode, $scopeLabel, $expectedTypes); + } + + /** + * Perform assertions. + * + * @param string $attributeCode + * @param string $scopeLabel + * @param array $expectedTypes + * @return void + */ + private function getImageTypesAssertions(string $attributeCode, string $scopeLabel, array $expectedTypes) + { + $this->content->setElement($this->galleryMock); + $result = $this->content->getImageTypes(); + $scope = $result[$attributeCode]['scope']; + $this->assertSame($scopeLabel, $scope->getText()); + unset($result[$attributeCode]['scope']); + $this->assertSame($expectedTypes, $result); + } + + /** + * Get media attribute mock. + * + * @param string $label + * @param string $attributeCode + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function getMediaAttribute(string $label, string $attributeCode) + { + $frontend = $this->getMockBuilder(Product\Attribute\Frontend\Image::class) + ->disableOriginalConstructor() + ->getMock(); + $frontend->expects($this->once()) + ->method('getLabel') + ->willReturn($label); + $mediaAttribute = $this->getMockBuilder(Attribute::class) + ->disableOriginalConstructor() + ->getMock(); + $mediaAttribute->expects($this->any()) + ->method('getAttributeCode') + ->willReturn($attributeCode); + $mediaAttribute->expects($this->once()) + ->method('getFrontend') + ->willReturn($frontend); + + return $mediaAttribute; + } + + /** + * Test GetImagesJson() calls MediaStorage functions to obtain image from DB prior to stat call + * + * @return void + */ + public function testGetImagesJsonMediaStorageMode() + { + $images = [ + 'images' => [ + [ + 'value_id' => '0', + 'file' => 'file_1.jpg', + 'media_type' => 'image', + 'position' => '0' + ] + ] + ]; + + $mediaPath = [ + ['file_1.jpg', 'catalog/product/image_1.jpg'] + ]; + + $this->content->setElement($this->galleryMock); + + $this->galleryMock->expects($this->once()) + ->method('getImages') + ->willReturn($images); + $this->fileSystemMock->expects($this->once()) + ->method('getDirectoryRead') + ->willReturn($this->readMock); + $this->mediaConfigMock->expects($this->any()) + ->method('getMediaPath') + ->willReturnMap($mediaPath); + + $this->readMock->expects($this->any()) + ->method('isFile') + ->will($this->returnValue(false)); + $this->databaseMock->expects($this->any()) + ->method('checkDbUsage') + ->will($this->returnValue(true)); + + $this->databaseMock->expects($this->once()) + ->method('saveFileToFilesystem') + ->with('catalog/product/image_1.jpg'); + + $this->content->getImagesJson(); + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ImageUploaderTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ImageUploaderTest.php new file mode 100644 index 0000000000000..6552e85440008 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/ImageUploaderTest.php @@ -0,0 +1,154 @@ +coreFileStorageDatabaseMock = $this->createMock( + \Magento\MediaStorage\Helper\File\Storage\Database::class + ); + $this->mediaDirectoryMock = $this->createMock( + \Magento\Framework\Filesystem::class + ); + $this->mediaWriteDirectoryMock = $this->createMock( + \Magento\Framework\Filesystem\Directory\WriteInterface::class + ); + $this->mediaDirectoryMock->expects($this->any())->method('getDirectoryWrite')->willReturn( + $this->mediaWriteDirectoryMock + ); + $this->uploaderFactoryMock = $this->createMock( + \Magento\MediaStorage\Model\File\UploaderFactory::class + ); + $this->storeManagerMock = $this->createMock( + \Magento\Store\Model\StoreManagerInterface::class + ); + $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); + $this->baseTmpPath = 'base/tmp/'; + $this->basePath = 'base/real/'; + $this->allowedExtensions = ['.jpg']; + $this->allowedMimeTypes = ['image/jpg', 'image/jpeg', 'image/gif', 'image/png']; + + $this->imageUploader = + new \Magento\Catalog\Model\ImageUploader( + $this->coreFileStorageDatabaseMock, + $this->mediaDirectoryMock, + $this->uploaderFactoryMock, + $this->storeManagerMock, + $this->loggerMock, + $this->baseTmpPath, + $this->basePath, + $this->allowedExtensions, + $this->allowedMimeTypes + ); + } + + public function testSaveFileToTmpDir() + { + $fileId = 'file.jpg'; + $allowedMimeTypes = [ + 'image/jpg', + 'image/jpeg', + 'image/gif', + 'image/png', + ]; + /** @var \Magento\MediaStorage\Model\File\Uploader|\PHPUnit_Framework_MockObject_MockObject $uploader */ + $uploader = $this->createMock(\Magento\MediaStorage\Model\File\Uploader::class); + $this->uploaderFactoryMock->expects($this->once())->method('create')->willReturn($uploader); + $uploader->expects($this->once())->method('setAllowedExtensions')->with($this->allowedExtensions); + $uploader->expects($this->once())->method('setAllowRenameFiles')->with(true); + $this->mediaWriteDirectoryMock->expects($this->once())->method('getAbsolutePath')->with($this->baseTmpPath) + ->willReturn($this->basePath); + $uploader->expects($this->once())->method('save')->with($this->basePath) + ->willReturn(['tmp_name' => $this->baseTmpPath, 'file' => $fileId, 'path' => $this->basePath]); + $uploader->expects($this->atLeastOnce())->method('checkMimeType')->with($allowedMimeTypes)->willReturn(true); + $storeMock = $this->createPartialMock( + \Magento\Store\Model\Store::class, + ['getBaseUrl'] + ); + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); + $storeMock->expects($this->once())->method('getBaseUrl'); + $this->coreFileStorageDatabaseMock->expects($this->once())->method('saveFile'); + + $result = $this->imageUploader->saveFileToTmpDir($fileId); + + $this->assertArrayNotHasKey('path', $result); + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/View/Asset/Image/ContextTest.php b/app/code/Magento/Catalog/Test/Unit/Model/View/Asset/Image/ContextTest.php new file mode 100644 index 0000000000000..e73a2f30e2b10 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/View/Asset/Image/ContextTest.php @@ -0,0 +1,76 @@ +mediaConfig = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass(); + $this->mediaConfig->expects($this->any())->method('getBaseMediaPath')->willReturn('catalog/product'); + $this->mediaDirectory = $this->getMockBuilder(WriteInterface::class)->getMockForAbstractClass(); + $this->mediaDirectory->expects($this->once())->method('create')->with('catalog/product'); + $this->filesystem = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + $this->filesystem->expects($this->once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::MEDIA) + ->willReturn($this->mediaDirectory); + $this->model = new Context( + $this->mediaConfig, + $this->filesystem + ); + } + + public function testGetPath() + { + $path = '/var/www/html/magento2ce/pub/media/catalog/product'; + $this->mediaDirectory->expects($this->once()) + ->method('getAbsolutePath') + ->with('catalog/product') + ->willReturn($path); + + $this->assertEquals($path, $this->model->getPath()); + } + + public function testGetUrl() + { + $baseUrl = 'http://localhost/pub/media/catalog/product'; + $this->mediaConfig->expects($this->once())->method('getBaseMediaUrl')->willReturn($baseUrl); + + $this->assertEquals($baseUrl, $this->model->getBaseUrl()); + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/View/Asset/ImageTest.php b/app/code/Magento/Catalog/Test/Unit/Model/View/Asset/ImageTest.php new file mode 100644 index 0000000000000..6832d5b3399d7 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/View/Asset/ImageTest.php @@ -0,0 +1,213 @@ +mediaConfig = $this->createMock(ConfigInterface::class); + $this->encryptor = $this->createMock(EncryptorInterface::class); + $this->context = $this->createMock(ContextInterface::class); + $this->assetRepo = $this->createMock(Repository::class); + $this->objectManager = new ObjectManager($this); + $this->model = $this->objectManager->getObject( + Image::class, + [ + 'mediaConfig' => $this->mediaConfig, + 'imageContext' => $this->context, + 'encryptor' => $this->encryptor, + 'filePath' => '/somefile.png', + 'assetRepo' => $this->assetRepo, + 'miscParams' => [ + 'image_width' => 100, + 'image_height' => 50, + 'constrain_only' => false, + 'keep_aspect_ratio' => false, + 'keep_frame' => true, + 'keep_transparency' => false, + 'background' => '255,255,255', + 'image_type' => 'image', //thumbnail,small_image,image,swatch_image,swatch_thumb + 'quality' => 80, + 'angle' => null + ] + ] + ); + } + + public function testModuleAndContentAndContentType() + { + $contentType = 'image'; + $this->assertEquals($contentType, $this->model->getContentType()); + $this->assertEquals($contentType, $this->model->getSourceContentType()); + $this->assertNull($this->model->getContent()); + $this->assertEquals('cache', $this->model->getModule()); + } + + public function testGetFilePath() + { + $this->assertEquals('/somefile.png', $this->model->getFilePath()); + } + + public function testGetSoureFile() + { + $this->mediaConfig->expects($this->once())->method('getBaseMediaPath')->willReturn('catalog/product'); + $this->assertEquals('catalog/product/somefile.png', $this->model->getSourceFile()); + } + + public function testGetContext() + { + $this->assertInstanceOf(ContextInterface::class, $this->model->getContext()); + } + + /** + * @param string $filePath + * @param array $miscParams + * @param string $readableParams + * @dataProvider getPathDataProvider + */ + public function testGetPath($filePath, $miscParams, $readableParams) + { + $imageModel = $this->objectManager->getObject( + Image::class, + [ + 'mediaConfig' => $this->mediaConfig, + 'context' => $this->context, + 'encryptor' => $this->encryptor, + 'filePath' => $filePath, + 'assetRepo' => $this->assetRepo, + 'miscParams' => $miscParams + ] + ); + $absolutePath = '/var/www/html/magento2ce/pub/media/catalog/product'; + $hashPath = 'somehash'; + $this->context->method('getPath')->willReturn($absolutePath); + $this->encryptor->expects(static::once()) + ->method('hash') + ->with($readableParams, $this->anything()) + ->willReturn($hashPath); + static::assertEquals( + $absolutePath . '/cache/'. $hashPath . $filePath, + $imageModel->getPath() + ); + } + + /** + * @param string $filePath + * @param array $miscParams + * @param string $readableParams + * @dataProvider getPathDataProvider + */ + public function testGetUrl($filePath, $miscParams, $readableParams) + { + $imageModel = $this->objectManager->getObject( + Image::class, + [ + 'mediaConfig' => $this->mediaConfig, + 'context' => $this->context, + 'encryptor' => $this->encryptor, + 'filePath' => $filePath, + 'assetRepo' => $this->assetRepo, + 'miscParams' => $miscParams + ] + ); + $absolutePath = 'http://localhost/pub/media/catalog/product'; + $hashPath = 'somehash'; + $this->context->expects(static::once())->method('getBaseUrl')->willReturn($absolutePath); + $this->encryptor->expects(static::once()) + ->method('hash') + ->with($readableParams, $this->anything()) + ->willReturn($hashPath); + static::assertEquals( + $absolutePath . '/cache/' . $hashPath . $filePath, + $imageModel->getUrl() + ); + } + + /** + * @return array + */ + public function getPathDataProvider() + { + return [ + [ + '/some_file.png', + [], //default value for miscParams, + 'h:empty_w:empty_q:empty_r:empty_nonproportional_noframe_notransparency_notconstrainonly_nobackground', + ], + [ + '/some_file_2.png', + [ + 'image_type' => 'thumbnail', + 'image_height' => 75, + 'image_width' => 75, + 'keep_aspect_ratio' => true, + 'keep_frame' => true, + 'keep_transparency' => true, + 'constrain_only' => true, + 'background' => [233,1,0], + 'angle' => null, + 'quality' => 80, + ], + 'h:75_w:75_proportional_frame_transparency_doconstrainonly_rgb233,1,0_r:empty_q:80', + ], + [ + '/some_file_3.png', + [ + 'image_type' => 'thumbnail', + 'image_height' => 75, + 'image_width' => 75, + 'keep_aspect_ratio' => false, + 'keep_frame' => false, + 'keep_transparency' => false, + 'constrain_only' => false, + 'background' => [233,1,0], + 'angle' => 90, + 'quality' => 80, + ], + 'h:75_w:75_nonproportional_noframe_notransparency_notconstrainonly_rgb233,1,0_r:90_q:80', + ], + ]; + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Listing/Collector/ImageTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Listing/Collector/ImageTest.php index bd08a39fb2bed..009cd690d4cd4 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Listing/Collector/ImageTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Listing/Collector/ImageTest.php @@ -99,6 +99,9 @@ public function testGet() ->method('create') ->willReturn($image); + $imageHelper->expects($this->once()) + ->method('getResizedImageInfo') + ->willReturn([11, 11]); $this->state->expects($this->once()) ->method('emulateAreaCode') ->with( @@ -108,14 +111,12 @@ public function testGet() ) ->willReturn($imageHelper); - $width = 5; - $height = 10; $imageHelper->expects($this->once()) ->method('getHeight') - ->willReturn($height); + ->willReturn(10); $imageHelper->expects($this->once()) ->method('getWidth') - ->willReturn($width); + ->willReturn(10); $imageHelper->expects($this->once()) ->method('getLabel') ->willReturn('Label'); @@ -131,10 +132,10 @@ public function testGet() ->with(); $image->expects($this->once()) ->method('setResizedHeight') - ->with($height); + ->with(11); $image->expects($this->once()) ->method('setResizedWidth') - ->with($width); + ->with(11); $productRenderInfoDto->expects($this->once()) ->method('setImages') diff --git a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Thumbnail.php b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Thumbnail.php index 52773b4580256..09c9782fc0e32 100644 --- a/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Thumbnail.php +++ b/app/code/Magento/Catalog/Ui/Component/Listing/Columns/Thumbnail.php @@ -9,7 +9,7 @@ use Magento\Framework\View\Element\UiComponent\ContextInterface; /** - * Column with thumbnail images + * Class Thumbnail * * @api * @since 100.0.2 @@ -20,16 +20,6 @@ class Thumbnail extends \Magento\Ui\Component\Listing\Columns\Column const ALT_FIELD = 'name'; - /** - * @var \Magento\Catalog\Helper\Image - */ - private $imageHelper; - - /** - * @var \Magento\Framework\UrlInterface - */ - private $urlBuilder; - /** * @param ContextInterface $context * @param UiComponentFactory $uiComponentFactory diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Related.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Related.php index b822a5e3ef88a..b4acb93dcd14f 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Related.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Related.php @@ -25,7 +25,7 @@ use Magento\Catalog\Model\Product\Attribute\Source\Status; /** - * Related products modifier + * Class Related * * @api * @@ -143,7 +143,7 @@ public function __construct( } /** - * @inheritdoc + * {@inheritdoc} * @since 101.0.0 */ public function modifyMeta(array $meta) @@ -182,7 +182,7 @@ public function modifyMeta(array $meta) } /** - * @inheritdoc + * {@inheritdoc} * @since 101.0.0 */ public function modifyData(array $data) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Image.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Image.php index 45383ed51f6fc..d8f76c40e8fad 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Image.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Image.php @@ -118,14 +118,18 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ [$product, $imageCode, (int) $productRender->getStoreId(), $image] ); + try { + $resizedInfo = $helper->getResizedImageInfo(); + } catch (NotLoadInfoImageException $exception) { + $resizedInfo = [$helper->getWidth(), $helper->getHeight()]; + } + $image->setCode($imageCode); - $height = $helper->getHeight(); - $image->setHeight($height); - $width = $helper->getWidth(); - $image->setWidth($width); + $image->setHeight($helper->getHeight()); + $image->setWidth($helper->getWidth()); $image->setLabel($helper->getLabel()); - $image->setResizedHeight($height); - $image->setResizedWidth($width); + $image->setResizedHeight($resizedInfo[1]); + $image->setResizedWidth($resizedInfo[0]); $images[] = $image; } diff --git a/app/code/Magento/Catalog/etc/adminhtml/system.xml b/app/code/Magento/Catalog/etc/adminhtml/system.xml index f59990cdcea96..80b323cfdb250 100644 --- a/app/code/Magento/Catalog/etc/adminhtml/system.xml +++ b/app/code/Magento/Catalog/etc/adminhtml/system.xml @@ -208,13 +208,6 @@ Magento\Catalog\Model\Config\Source\LayoutList - - - - Magento\Catalog\Model\Config\Source\Web\CatalogMediaUrlFormat - Learn more about catalog URL formats.

Warning! If you switch back to legacy mode, you must use the CLI to regenerate images.]]>
-
-
separator-top diff --git a/app/code/Magento/Catalog/etc/config.xml b/app/code/Magento/Catalog/etc/config.xml index 68289904db0cf..59fc4b6d947d9 100644 --- a/app/code/Magento/Catalog/etc/config.xml +++ b/app/code/Magento/Catalog/etc/config.xml @@ -80,11 +80,6 @@ stretch - - - hash - - diff --git a/app/code/Magento/Checkout/CustomerData/DefaultItem.php b/app/code/Magento/Checkout/CustomerData/DefaultItem.php index 23d5827dc1916..21580d1275d0c 100644 --- a/app/code/Magento/Checkout/CustomerData/DefaultItem.php +++ b/app/code/Magento/Checkout/CustomerData/DefaultItem.php @@ -10,7 +10,7 @@ use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface; /** - * Default item in checkout customer data + * Default item */ class DefaultItem extends AbstractItem { @@ -78,7 +78,7 @@ public function __construct( } /** - * @inheritdoc + * {@inheritdoc} */ protected function doGetItemData() { @@ -121,8 +121,6 @@ protected function getOptionList() } /** - * Get product for thumbnail - * * @return \Magento\Catalog\Model\Product * @codeCoverageIgnore */ @@ -132,8 +130,6 @@ protected function getProductForThumbnail() } /** - * Get product - * * @return \Magento\Catalog\Model\Product * @codeCoverageIgnore */ diff --git a/app/code/Magento/Checkout/Model/DefaultConfigProvider.php b/app/code/Magento/Checkout/Model/DefaultConfigProvider.php index 87585e4bf327f..fdf49d6765a29 100644 --- a/app/code/Magento/Checkout/Model/DefaultConfigProvider.php +++ b/app/code/Magento/Checkout/Model/DefaultConfigProvider.php @@ -31,7 +31,7 @@ use Magento\Ui\Component\Form\Element\Multiline; /** - * Default Config Provider for checkout + * Default Config Provider * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) diff --git a/app/code/Magento/MediaStorage/Console/Command/ImagesResizeCommand.php b/app/code/Magento/MediaStorage/Console/Command/ImagesResizeCommand.php index d592a004e111a..4ed84829c2ad0 100644 --- a/app/code/Magento/MediaStorage/Console/Command/ImagesResizeCommand.php +++ b/app/code/Magento/MediaStorage/Console/Command/ImagesResizeCommand.php @@ -84,11 +84,7 @@ public function __construct( protected function configure() { $this->setName('catalog:images:resize') - ->setDescription( - 'Creates resized product images ' . - '(Not relevant when image resizing is offloaded from Magento. ' . - 'See https://docs.magento.com/m2/ee/user_guide/configuration/general/web.html#url-options )' - ) + ->setDescription('Creates resized product images') ->setDefinition($this->getOptionsList()); } diff --git a/app/code/Magento/Wishlist/CustomerData/Wishlist.php b/app/code/Magento/Wishlist/CustomerData/Wishlist.php index 2f6b57a8650c4..ae54289d4b1c9 100644 --- a/app/code/Magento/Wishlist/CustomerData/Wishlist.php +++ b/app/code/Magento/Wishlist/CustomerData/Wishlist.php @@ -68,7 +68,7 @@ public function __construct( } /** - * @inheritdoc + * {@inheritdoc} */ public function getSectionData() { @@ -80,8 +80,6 @@ public function getSectionData() } /** - * Get counter - * * @return string */ protected function getCounter() @@ -158,6 +156,7 @@ protected function getItemData(\Magento\Wishlist\Model\Item $wishlistItem) * * @param \Magento\Catalog\Model\Product $product * @return array + * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function getImageData($product) { @@ -165,11 +164,27 @@ protected function getImageData($product) $helper = $this->imageHelperFactory->create() ->init($product, 'wishlist_sidebar_block'); + $template = 'Magento_Catalog/product/image_with_borders'; + + try { + $imagesize = $helper->getResizedImageInfo(); + } catch (NotLoadInfoImageException $exception) { + $imagesize = [$helper->getWidth(), $helper->getHeight()]; + } + + $width = $helper->getFrame() + ? $helper->getWidth() + : $imagesize[0]; + + $height = $helper->getFrame() + ? $helper->getHeight() + : $imagesize[1]; + return [ - 'template' => 'Magento_Catalog/product/image_with_borders', + 'template' => $template, 'src' => $helper->getUrl(), - 'width' => $helper->getWidth(), - 'height' => $helper->getHeight(), + 'width' => $width, + 'height' => $height, 'alt' => $helper->getLabel(), ]; } diff --git a/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php b/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php index 3ef2833ded21f..325922f0bc4e3 100644 --- a/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/CustomerData/WishlistTest.php @@ -193,6 +193,9 @@ public function testGetSectionData() $this->catalogImageHelperMock->expects($this->any()) ->method('getFrame') ->willReturn(true); + $this->catalogImageHelperMock->expects($this->once()) + ->method('getResizedImageInfo') + ->willReturn([]); $this->wishlistHelperMock->expects($this->once()) ->method('getProductUrl') @@ -391,6 +394,9 @@ public function testGetSectionDataWithTwoItems() $this->catalogImageHelperMock->expects($this->any()) ->method('getFrame') ->willReturn(true); + $this->catalogImageHelperMock->expects($this->exactly(2)) + ->method('getResizedImageInfo') + ->willReturn([]); $this->wishlistHelperMock->expects($this->exactly(2)) ->method('getProductUrl') diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/GalleryTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/GalleryTest.php index a3545e4a39e80..9bcdb00eebe7c 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/GalleryTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/GalleryTest.php @@ -120,23 +120,9 @@ public function testGetGalleryImagesJsonWithoutImages(): void $this->assertImages(reset($result), $this->placeholderExpectation); } - /** - * @magentoDataFixture Magento/Catalog/_files/product_simple.php - * @magentoConfigFixture default/web/url/catalog_media_url_format image_optimization_parameters - * @magentoDbIsolation enabled - * @return void - */ - public function testGetGalleryImagesJsonWithoutImagesWithImageOptimizationParametersInUrl(): void - { - $this->block->setData('product', $this->getProduct()); - $result = $this->serializer->unserialize($this->block->getGalleryImagesJson()); - $this->assertImages(reset($result), $this->placeholderExpectation); - } - /** * @dataProvider galleryDisabledImagesDataProvider * @magentoDataFixture Magento/Catalog/_files/product_with_multiple_images.php - * @magentoConfigFixture default/web/url/catalog_media_url_format hash * @magentoDbIsolation enabled * @param array $images * @param array $expectation @@ -155,7 +141,6 @@ public function testGetGalleryImagesJsonWithDisabledImage(array $images, array $ * @dataProvider galleryDisabledImagesDataProvider * @magentoDataFixture Magento/Catalog/_files/product_with_multiple_images.php * @magentoDataFixture Magento/Store/_files/second_store.php - * @magentoConfigFixture default/web/url/catalog_media_url_format hash * @magentoDbIsolation disabled * @param array $images * @param array $expectation @@ -188,8 +173,6 @@ public function galleryDisabledImagesDataProvider(): array } /** - * Test default image generation format. - * * @dataProvider galleryImagesDataProvider * @magentoDataFixture Magento/Catalog/_files/product_with_multiple_images.php * @magentoDbIsolation enabled @@ -247,95 +230,10 @@ public function galleryImagesDataProvider(): array ]; } - /** - * @dataProvider galleryImagesWithImageOptimizationParametersInUrlDataProvider - * @magentoDataFixture Magento/Catalog/_files/product_with_multiple_images.php - * @magentoConfigFixture default/web/url/catalog_media_url_format image_optimization_parameters - * @magentoDbIsolation enabled - * @param array $images - * @param array $expectation - * @return void - */ - public function testGetGalleryImagesJsonWithImageOptimizationParametersInUrl( - array $images, - array $expectation - ): void { - $product = $this->getProduct(); - $this->setGalleryImages($product, $images); - $this->block->setData('product', $this->getProduct()); - [$firstImage, $secondImage] = $this->serializer->unserialize($this->block->getGalleryImagesJson()); - [$firstExpectedImage, $secondExpectedImage] = $expectation; - $this->assertImages($firstImage, $firstExpectedImage); - $this->assertImages($secondImage, $secondExpectedImage); - } - - /** - * @return array - */ - public function galleryImagesWithImageOptimizationParametersInUrlDataProvider(): array - { - - $imageExpectation = [ - 'thumb' => '/m/a/magento_image.jpg?width=88&height=110&store=default&image-type=thumbnail', - 'img' => '/m/a/magento_image.jpg?width=700&height=700&store=default&image-type=image', - 'full' => '/m/a/magento_image.jpg?store=default&image-type=image', - 'caption' => 'Image Alt Text', - 'position' => '1', - 'isMain' => false, - 'type' => 'image', - 'videoUrl' => null, - ]; - - $thumbnailExpectation = [ - 'thumb' => '/m/a/magento_thumbnail.jpg?width=88&height=110&store=default&image-type=thumbnail', - 'img' => '/m/a/magento_thumbnail.jpg?width=700&height=700&store=default&image-type=image', - 'full' => '/m/a/magento_thumbnail.jpg?store=default&image-type=image', - 'caption' => 'Thumbnail Image', - 'position' => '2', - 'isMain' => false, - 'type' => 'image', - 'videoUrl' => null, - ]; - - return [ - 'with_main_image' => [ - 'images' => [ - '/m/a/magento_image.jpg' => [], - '/m/a/magento_thumbnail.jpg' => ['main' => true], - ], - 'expectation' => [ - $imageExpectation, - array_merge($thumbnailExpectation, ['isMain' => true]), - ], - ], - 'without_main_image' => [ - 'images' => [ - '/m/a/magento_image.jpg' => [], - '/m/a/magento_thumbnail.jpg' => [], - ], - 'expectation' => [ - array_merge($imageExpectation, ['isMain' => true]), - $thumbnailExpectation, - ], - ], - 'with_changed_position' => [ - 'images' => [ - '/m/a/magento_image.jpg' => ['position' => '2'], - '/m/a/magento_thumbnail.jpg' => ['position' => '1'], - ], - 'expectation' => [ - array_merge($thumbnailExpectation, ['position' => '1']), - array_merge($imageExpectation, ['position' => '2', 'isMain' => true]), - ], - ], - ]; - } - /** * @dataProvider galleryImagesOnStoreViewDataProvider * @magentoDataFixture Magento/Catalog/_files/product_with_multiple_images.php * @magentoDataFixture Magento/Store/_files/second_store.php - * @magentoConfigFixture default/web/url/catalog_media_url_format hash * @magentoDbIsolation disabled * @param array $images * @param array $expectation diff --git a/dev/tests/integration/testsuite/Magento/Sitemap/Model/ResourceModel/Catalog/ProductTest.php b/dev/tests/integration/testsuite/Magento/Sitemap/Model/ResourceModel/Catalog/ProductTest.php index 7d5e919880d3b..d6388b188a5fd 100644 --- a/dev/tests/integration/testsuite/Magento/Sitemap/Model/ResourceModel/Catalog/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/Sitemap/Model/ResourceModel/Catalog/ProductTest.php @@ -52,7 +52,6 @@ public function testGetCollectionNone() * 3) Check thumbnails when no thumbnail selected * * @magentoConfigFixture default_store sitemap/product/image_include all - * @magentoConfigFixture default/web/url/catalog_media_url_format hash */ public function testGetCollectionAll() { @@ -121,7 +120,6 @@ public function testGetCollectionAll() * 3) Check thumbnails when no thumbnail selected * * @magentoConfigFixture default_store sitemap/product/image_include base - * @magentoConfigFixture default/web/url/catalog_media_url_format hash */ public function testGetCollectionBase() { diff --git a/lib/internal/Magento/Framework/Image.php b/lib/internal/Magento/Framework/Image.php index 64cd009a84a3c..b3867c0197b79 100644 --- a/lib/internal/Magento/Framework/Image.php +++ b/lib/internal/Magento/Framework/Image.php @@ -49,7 +49,7 @@ public function open() $this->_adapter->checkDependencies(); if (!file_exists($this->_fileName)) { - throw new \RuntimeException("File '{$this->_fileName}' does not exist."); + throw new \Exception("File '{$this->_fileName}' does not exist."); } $this->_adapter->open($this->_fileName); @@ -85,7 +85,6 @@ public function save($destination = null, $newFileName = null) * @param int $angle * @access public * @return void - * @deprecated unused */ public function rotate($angle) { @@ -95,7 +94,7 @@ public function rotate($angle) /** * Crop an image. * - * @param int $top Default value is 0 + * @param int $top Default value is 0 * @param int $left Default value is 0 * @param int $right Default value is 0 * @param int $bottom Default value is 0 @@ -195,7 +194,7 @@ public function quality($value) * @param int $watermarkImageOpacity Watermark image opacity. * @param bool $repeat Enable or disable watermark brick. * @access public - * @throws \RuntimeException + * @throws \Exception * @return void */ public function watermark( @@ -206,7 +205,7 @@ public function watermark( $repeat = false ) { if (!file_exists($watermarkImage)) { - throw new \RuntimeException("Required file '{$watermarkImage}' does not exists."); + throw new \Exception("Required file '{$watermarkImage}' does not exists."); } $this->_adapter->watermark($watermarkImage, $positionX, $positionY, $watermarkImageOpacity, $repeat); } @@ -233,19 +232,16 @@ public function getImageType() return $this->_adapter->getImageType(); } - // phpcs:disable Magento2.CodeAnalysis.EmptyBlock /** * Process * - * @access public, + * @access public * @return void */ public function process() { } - // phpcs:enable Magento2.CodeAnalysis.EmptyBlock - // phpcs:disable Magento2.CodeAnalysis.EmptyBlock /** * Instruction * @@ -255,7 +251,6 @@ public function process() public function instruction() { } - // phpcs:enable Magento2.CodeAnalysis.EmptyBlock /** * Set image background color diff --git a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php index 88dbd69405471..b06f2f9e62397 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php @@ -41,6 +41,9 @@ abstract class AbstractAdapter implements AdapterInterface const POSITION_CENTER = 'center'; + /** + * Default font size + */ const DEFAULT_FONT_SIZE = 15; /** @@ -201,7 +204,6 @@ abstract public function resize($width = null, $height = null); * * @param int $angle * @return void - * @deprecated unused */ abstract public function rotate($angle); diff --git a/lib/internal/Magento/Framework/Image/Adapter/AdapterInterface.php b/lib/internal/Magento/Framework/Image/Adapter/AdapterInterface.php index 736686968b374..b31ed5c773495 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AdapterInterface.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AdapterInterface.php @@ -28,8 +28,6 @@ interface AdapterInterface public function getColorAt($x, $y); /** - * Render image and return its binary contents - * * @see \Magento\Framework\Image\Adapter\AbstractAdapter::getImage * @return string */ @@ -101,7 +99,6 @@ public function crop($top = 0, $left = 0, $right = 0, $bottom = 0); /** * Save image to specific path. - * * If some folders of path does not exist they will be created * * @param null|string $destination @@ -116,7 +113,6 @@ public function save($destination = null, $newName = null); * * @param int $angle * @return void - * @deprecated unused */ public function rotate($angle); } diff --git a/lib/internal/Magento/Framework/Image/Adapter/Gd2.php b/lib/internal/Magento/Framework/Image/Adapter/Gd2.php index df236faf8173b..6a7a11846334d 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/Gd2.php +++ b/lib/internal/Magento/Framework/Image/Adapter/Gd2.php @@ -401,7 +401,6 @@ public function resize($frameWidth = null, $frameHeight = null) * * @param int $angle * @return void - * @deprecated unused */ public function rotate($angle) { diff --git a/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php b/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php index a08d83d33b0ef..cd49f283d33a7 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php +++ b/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php @@ -5,11 +5,6 @@ */ namespace Magento\Framework\Image\Adapter; -/** - * Wrapper for Imagick image processing PHP Extension. - * - * @link https://www.php.net/manual/en/book.imagick.php - */ class ImageMagick extends \Magento\Framework\Image\Adapter\AbstractAdapter { /** @@ -82,11 +77,7 @@ public function open($filename) try { $this->_imageHandler = new \Imagick($this->_fileName); } catch (\ImagickException $e) { - throw new \RuntimeException( - sprintf('Unsupported image format. File: %s', $this->_fileName), - $e->getCode(), - $e - ); + throw new \Exception(sprintf('Unsupported image format. File: %s', $this->_fileName), $e->getCode(), $e); } $this->backgroundColor(); @@ -95,7 +86,6 @@ public function open($filename) /** * Save image to specific path. - * * If some folders of path does not exist they will be created * * @param null|string $destination @@ -134,8 +124,6 @@ protected function _applyOptions() } /** - * Render image binary content and return it. - * * @see \Magento\Framework\Image\Adapter\AbstractAdapter::getImage * @return string */ @@ -207,7 +195,6 @@ public function resize($frameWidth = null, $frameHeight = null) * * @param int $angle * @return void - * @deprecated unused */ public function rotate($angle) { @@ -346,7 +333,7 @@ public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity = ); } } catch (\ImagickException $e) { - throw new \RuntimeException('Unable to create watermark.', $e->getCode(), $e); + throw new \Exception('Unable to create watermark.', $e->getCode(), $e); } // merge layers @@ -359,12 +346,12 @@ public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity = * Checks required dependencies * * @return void - * @throws \RuntimeException If some of dependencies are missing + * @throws \Exception If some of dependencies are missing */ public function checkDependencies() { if (!class_exists('\Imagick', false)) { - throw new \RuntimeException("Required PHP extension 'Imagick' was not loaded."); + throw new \Exception("Required PHP extension 'Imagick' was not loaded."); } } diff --git a/nginx.conf.sample b/nginx.conf.sample index f045edb46a1c2..9219400f6aacd 100644 --- a/nginx.conf.sample +++ b/nginx.conf.sample @@ -26,9 +26,6 @@ ## ## In production mode, you should uncomment the 'expires' directive in the /static/ location block -# Modules can be loaded only at the very beginning of the Nginx config file, please move the line below to the main config file -# load_module /etc/nginx/modules/ngx_http_image_filter_module.so; - root $MAGE_ROOT/pub; index index.php; @@ -137,28 +134,6 @@ location /static/ { } location /media/ { - -## The following section allows to offload image resizing from Magento instance to the Nginx. -## Catalog image URL format should be set accordingly. -## See https://docs.magento.com/m2/ee/user_guide/configuration/general/web.html#url-options -# location ~* ^/media/catalog/.* { -# -# # Replace placeholders and uncomment the line below to serve product images from public S3 -# # See examples of S3 authentication at https://github.com/anomalizer/ngx_aws_auth -# # proxy_pass https://..amazonaws.com; -# -# set $width "-"; -# set $height "-"; -# if ($arg_width != '') { -# set $width $arg_width; -# } -# if ($arg_height != '') { -# set $height $arg_height; -# } -# image_filter resize $width $height; -# image_filter_jpeg_quality 90; -# } - try_files $uri $uri/ /get.php$is_args$args; location ~ ^/media/theme_customization/.*\.xml {