From 6b224456f66673ec9f88492cadb3c0b642069730 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Thu, 4 Jan 2018 14:15:51 +0200 Subject: [PATCH 1/7] 12322: [GitHub] Bug with CDATA in XML layout update --- .../Ui/TemplateEngine/Xhtml/Result.php | 2 +- .../Unit/TemplateEngine/Xhtml/ResultTest.php | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Ui/Test/Unit/TemplateEngine/Xhtml/ResultTest.php diff --git a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php index cda3106a14f49..bd1dde10f8eed 100644 --- a/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php +++ b/app/code/Magento/Ui/TemplateEngine/Xhtml/Result.php @@ -119,7 +119,7 @@ public function __toString() protected function wrapContent($content) { return ''; } } diff --git a/app/code/Magento/Ui/Test/Unit/TemplateEngine/Xhtml/ResultTest.php b/app/code/Magento/Ui/Test/Unit/TemplateEngine/Xhtml/ResultTest.php new file mode 100644 index 0000000000000..e51062e1cb36b --- /dev/null +++ b/app/code/Magento/Ui/Test/Unit/TemplateEngine/Xhtml/ResultTest.php @@ -0,0 +1,97 @@ +template = $this->createPartialMock(Template::class, ['append']); + $this->compiler = $this->createMock(CompilerInterface::class); + $this->component = $this->createMock(UiComponentInterface::class); + $this->structure = $this->createPartialMock(Structure::class, ['generate']); + $this->logger = $this->createMock(LoggerInterface::class); + + $this->objectManager = new ObjectManager($this); + $this->testModel = $this->objectManager->getObject(Result::class, [ + 'template' => $this->template, + 'compiler' => $this->compiler, + 'component' => $this->component, + 'structure' => $this->structure, + 'logger' => $this->logger, + ]); + } + + /** + * Test Append layout configuration method + */ + public function testAppendLayoutConfiguration() + { + $configWithCdata = 'text before '; + $this->structure->expects($this->once()) + ->method('generate') + ->with($this->component) + ->willReturn([$configWithCdata]); + $this->template->expects($this->once()) + ->method('append') + ->with(''); + + $this->testModel->appendLayoutConfiguration(); + } +} From f7baf29d595511b91b4012604d39c6ea5d15b496 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 16 Jan 2018 14:00:56 +0530 Subject: [PATCH 2/7] #12714 - pass parameter for export button url --- .../sales_order_view_creditmemo_grid.xml | 8 +++++- .../sales_order_view_invoice_grid.xml | 8 +++++- .../sales_order_view_shipment_grid.xml | 8 +++++- .../Magento/Ui/Component/ExportButton.php | 25 ++++++++++++++++++- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml index ecc2b5beee321..10b7b1c028c66 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_creditmemo_grid.xml @@ -35,7 +35,13 @@ - + + + + * + + + diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml index 3ec450a570b46..ac1233c5e4961 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_invoice_grid.xml @@ -35,7 +35,13 @@ - + + + + * + + + diff --git a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml index 27cef50742163..6db77a79b8c14 100644 --- a/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml +++ b/app/code/Magento/Sales/view/adminhtml/ui_component/sales_order_view_shipment_grid.xml @@ -35,7 +35,13 @@ - + + + + * + + + diff --git a/app/code/Magento/Ui/Component/ExportButton.php b/app/code/Magento/Ui/Component/ExportButton.php index 9d5f125839003..284362a119bad 100644 --- a/app/code/Magento/Ui/Component/ExportButton.php +++ b/app/code/Magento/Ui/Component/ExportButton.php @@ -54,11 +54,13 @@ public function getComponentName() */ public function prepare() { + $context = $this->getContext(); $config = $this->getData('config'); if (isset($config['options'])) { $options = []; foreach ($config['options'] as $option) { - $option['url'] = $this->urlBuilder->getUrl($option['url']); + $additionalParams = $this->getAdditionalParams($config, $context); + $option['url'] = $this->urlBuilder->getUrl($option['url'], $additionalParams); $options[] = $option; } $config['options'] = $options; @@ -66,4 +68,25 @@ public function prepare() } parent::prepare(); } + + /** + * Get export button additional parameters + * + * @param array $config + * @param ContextInterface $context + * @return array + */ + protected function getAdditionalParams($config, $context) + { + $additionalParams = []; + if (isset($config['additionalParams'])) { + foreach ($config['additionalParams'] as $paramName => $paramValue) { + if ('*' == $paramValue) { + $paramValue = $context->getRequestParam($paramName); + } + $additionalParams[$paramName] = $paramValue; + } + } + return $additionalParams; + } } From 1caaa21448bee406c07d1d4e50b06ff208be1795 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 16 Jan 2018 16:24:27 +0200 Subject: [PATCH 3/7] MAGETWO-84480: Add cache for getimagesize() function for product images --- .../Magento/Catalog/Model/Product/Image.php | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index 91f589f9b5bd7..ada66acaa0905 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -9,6 +9,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ObjectManager; use Magento\Framework\Image as MagentoImage; +use Magento\Framework\Serialize\Serializer\Json; /** * @method string getFile() @@ -172,6 +173,18 @@ class Image extends \Magento\Framework\Model\AbstractModel */ private $imageAsset; + /** + * @var string + */ + private $cachePrefix = 'IMG_INFO'; + + /** + * Json Serializer Instance + * + * @var Json + */ + private $json; + /** * Constructor * @@ -190,6 +203,7 @@ class Image extends \Magento\Framework\Model\AbstractModel * @param array $data * @param \Magento\Catalog\Model\View\Asset\ImageFactory|null $viewAssetImageFactory * @param \Magento\Catalog\Model\View\Asset\PlaceholderFactory|null $viewAssetPlaceholderFactory + * @param Json|null $json * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ @@ -208,7 +222,8 @@ public function __construct( \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [], \Magento\Catalog\Model\View\Asset\ImageFactory $viewAssetImageFactory = null, - \Magento\Catalog\Model\View\Asset\PlaceholderFactory $viewAssetPlaceholderFactory = null + \Magento\Catalog\Model\View\Asset\PlaceholderFactory $viewAssetPlaceholderFactory = null, + Json $json = null ) { $this->_storeManager = $storeManager; $this->_catalogProductMediaConfig = $catalogProductMediaConfig; @@ -223,6 +238,7 @@ public function __construct( ->get(\Magento\Catalog\Model\View\Asset\ImageFactory::class); $this->viewAssetPlaceholderFactory = $viewAssetPlaceholderFactory ?: ObjectManager::getInstance() ->get(\Magento\Catalog\Model\View\Asset\PlaceholderFactory::class); + $this->json = $json ?: ObjectManager::getInstance()->get(Json::class); } /** @@ -418,7 +434,7 @@ protected function _getNeedMemoryForFile($file = null) return 0; } - $imageInfo = getimagesize($this->_mediaDirectory->getAbsolutePath($file)); + $imageInfo = $this->getimagesize($this->_mediaDirectory->getAbsolutePath($file)); if (!isset($imageInfo[0]) || !isset($imageInfo[1])) { return 0; @@ -890,7 +906,7 @@ public function getResizedImageInfo() $image = $this->imageAsset->getPath(); } - $imageProperties = getimagesize($image); + $imageProperties = $this->getimagesize($image); return $imageProperties; } finally { @@ -932,4 +948,26 @@ private function getMiscParams() return $miscParams; } + + /** + * Get image size + * + * @param string $imagePath + * @return array + */ + private function getImageSize($imagePath) + { + $key = $this->cachePrefix . $imagePath; + $size = $this->_cacheManager->load($key); + if (!$size) { + $size = getimagesize($imagePath); + $this->_cacheManager->save( + $this->json->serialize($size), + $key + ); + } else { + $size = $this->json->unserialize($size); + } + return $size; + } } From 27bcb2552aa07c9fff01aef759b4dff8fdcffcc1 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 16 Jan 2018 16:45:45 +0200 Subject: [PATCH 4/7] MAGETWO-84480: Add cache for getimagesize() function for product images --- .../Magento/Catalog/Model/Product/Image.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index ada66acaa0905..6d1d4542b101c 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -9,7 +9,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\ObjectManager; use Magento\Framework\Image as MagentoImage; -use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Serialize\SerializerInterface; /** * @method string getFile() @@ -179,11 +179,11 @@ class Image extends \Magento\Framework\Model\AbstractModel private $cachePrefix = 'IMG_INFO'; /** - * Json Serializer Instance + * serializer Serializer Instance * - * @var Json + * @var SerializerInterface */ - private $json; + private $serializer; /** * Constructor @@ -203,7 +203,7 @@ class Image extends \Magento\Framework\Model\AbstractModel * @param array $data * @param \Magento\Catalog\Model\View\Asset\ImageFactory|null $viewAssetImageFactory * @param \Magento\Catalog\Model\View\Asset\PlaceholderFactory|null $viewAssetPlaceholderFactory - * @param Json|null $json + * @param SerializerInterface|null $serializer * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ @@ -223,7 +223,7 @@ public function __construct( array $data = [], \Magento\Catalog\Model\View\Asset\ImageFactory $viewAssetImageFactory = null, \Magento\Catalog\Model\View\Asset\PlaceholderFactory $viewAssetPlaceholderFactory = null, - Json $json = null + SerializerInterface $serializer = null ) { $this->_storeManager = $storeManager; $this->_catalogProductMediaConfig = $catalogProductMediaConfig; @@ -238,7 +238,7 @@ public function __construct( ->get(\Magento\Catalog\Model\View\Asset\ImageFactory::class); $this->viewAssetPlaceholderFactory = $viewAssetPlaceholderFactory ?: ObjectManager::getInstance() ->get(\Magento\Catalog\Model\View\Asset\PlaceholderFactory::class); - $this->json = $json ?: ObjectManager::getInstance()->get(Json::class); + $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** @@ -962,11 +962,11 @@ private function getImageSize($imagePath) if (!$size) { $size = getimagesize($imagePath); $this->_cacheManager->save( - $this->json->serialize($size), + $this->serializer->serialize($size), $key ); } else { - $size = $this->json->unserialize($size); + $size = $this->serializer->unserialize($size); } return $size; } From f31754dab40d308dea4b0cac5b087d255de27525 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Tue, 16 Jan 2018 16:49:59 +0200 Subject: [PATCH 5/7] MAGETWO-84480: Add cache for getimagesize() function for product images --- app/code/Magento/Catalog/Model/Product/Image.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index 6d1d4542b101c..ca8c2dc575124 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -179,8 +179,6 @@ class Image extends \Magento\Framework\Model\AbstractModel private $cachePrefix = 'IMG_INFO'; /** - * serializer Serializer Instance - * * @var SerializerInterface */ private $serializer; From 164e9469ef39c66019fcbd8fc6e700f54b387d33 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Wed, 17 Jan 2018 09:13:28 +0200 Subject: [PATCH 6/7] MAGETWO-84480: Add cache for getimagesize() function for product images --- .../Magento/Catalog/Model/Product/Image.php | 140 ++++++------------ 1 file changed, 45 insertions(+), 95 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index ca8c2dc575124..77e4383859b56 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -370,86 +370,6 @@ public function setSize($size) return $this; } - /** - * @param string|null $file - * @return bool - */ - protected function _checkMemory($file = null) - { - return $this->_getMemoryLimit() > $this->_getMemoryUsage() + $this->_getNeedMemoryForFile( - $file - ) - || $this->_getMemoryLimit() == -1; - } - - /** - * @return string - */ - protected function _getMemoryLimit() - { - $memoryLimit = trim(strtoupper(ini_get('memory_limit'))); - - if (!isset($memoryLimit[0])) { - $memoryLimit = "128M"; - } - - if (substr($memoryLimit, -1) == 'K') { - return substr($memoryLimit, 0, -1) * 1024; - } - if (substr($memoryLimit, -1) == 'M') { - return substr($memoryLimit, 0, -1) * 1024 * 1024; - } - if (substr($memoryLimit, -1) == 'G') { - return substr($memoryLimit, 0, -1) * 1024 * 1024 * 1024; - } - return $memoryLimit; - } - - /** - * @return int - */ - protected function _getMemoryUsage() - { - if (function_exists('memory_get_usage')) { - return memory_get_usage(); - } - return 0; - } - - /** - * @param string|null $file - * @return float|int - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - protected function _getNeedMemoryForFile($file = null) - { - $file = $file === null ? $this->getBaseFile() : $file; - if (!$file) { - return 0; - } - - if (!$this->_mediaDirectory->isExist($file)) { - return 0; - } - - $imageInfo = $this->getimagesize($this->_mediaDirectory->getAbsolutePath($file)); - - if (!isset($imageInfo[0]) || !isset($imageInfo[1])) { - return 0; - } - if (!isset($imageInfo['channels'])) { - // if there is no info about this parameter lets set it for maximum - $imageInfo['channels'] = 4; - } - if (!isset($imageInfo['bits'])) { - // if there is no info about this parameter lets set it for maximum - $imageInfo['bits'] = 8; - } - return round( - ($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65 - ); - } - /** * Convert array of 3 items (decimal r, g, b) to string of their hex values * @@ -486,9 +406,7 @@ public function setBaseFile($file) 'filePath' => $file, ] ); - if ($file == 'no_selection' || !$this->_fileExists($this->imageAsset->getSourceFile()) - || !$this->_checkMemory($this->imageAsset->getSourceFile()) - ) { + if ($file == 'no_selection' || !$this->_fileExists($this->imageAsset->getSourceFile())) { $this->_isBaseFilePlaceholder = true; $this->imageAsset = $this->viewAssetPlaceholderFactory->create( [ @@ -696,11 +614,14 @@ public function getDestinationSubdir() } /** - * @return bool|void + * @return bool */ public function isCached() { - return file_exists($this->imageAsset->getPath()); + return ( + is_array($this->loadImageInfoFromCache($this->imageAsset->getPath())) || + file_exists($this->imageAsset->getPath()) + ); } /** @@ -955,17 +876,46 @@ private function getMiscParams() */ private function getImageSize($imagePath) { - $key = $this->cachePrefix . $imagePath; - $size = $this->_cacheManager->load($key); - if (!$size) { - $size = getimagesize($imagePath); - $this->_cacheManager->save( - $this->serializer->serialize($size), - $key - ); + $imageInfo = $this->loadImageInfoFromCache($imagePath); + if (!isset($imageInfo['size'])) { + $imageSize = getimagesize($imagePath); + $this->saveImageInfoToCache(['size' => $imageSize], $imagePath); + return $imageSize; + } else { + return $imageInfo['size']; + } + } + + /** + * Save image data to cache + * + * @param array $imageInfo + * @param string $imagePath + * @return void + */ + private function saveImageInfoToCache(array $imageInfo, string $imagePath) + { + $imagePath = $this->cachePrefix . $imagePath; + $this->_cacheManager->save( + $this->serializer->serialize($imageInfo), + $imagePath + ); + } + + /** + * Load image data from cache + * + * @param string $imagePath + * @return array|false + */ + private function loadImageInfoFromCache(string $imagePath) + { + $imagePath = $this->cachePrefix . $imagePath; + $cacheData = $this->_cacheManager->load($imagePath); + if (!$cacheData) { + return false; } else { - $size = $this->serializer->unserialize($size); + return $this->serializer->unserialize($cacheData); } - return $size; } } From 3e86102f05013c94018b365894a907cc215a1595 Mon Sep 17 00:00:00 2001 From: Stanislav Lopukhov Date: Wed, 17 Jan 2018 10:53:36 +0200 Subject: [PATCH 7/7] MAGETWO-84480: Add cache for getimagesize() function for product images --- .../Magento/Catalog/Model/Product/Image.php | 14 ++++- .../Test/Unit/Model/Product/ImageTest.php | 61 ++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Image.php b/app/code/Magento/Catalog/Model/Product/Image.php index 77e4383859b56..971f34e02f9e5 100644 --- a/app/code/Magento/Catalog/Model/Product/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Image.php @@ -791,6 +791,7 @@ public function clearCache() $this->_mediaDirectory->delete($directory); $this->_coreFileStorageDatabase->deleteFolder($this->_mediaDirectory->getAbsolutePath($directory)); + $this->clearImageInfoFromCache(); } /** @@ -898,7 +899,8 @@ private function saveImageInfoToCache(array $imageInfo, string $imagePath) $imagePath = $this->cachePrefix . $imagePath; $this->_cacheManager->save( $this->serializer->serialize($imageInfo), - $imagePath + $imagePath, + [$this->cachePrefix] ); } @@ -918,4 +920,14 @@ private function loadImageInfoFromCache(string $imagePath) return $this->serializer->unserialize($cacheData); } } + + /** + * Clear image data from cache + * + * @return void + */ + private function clearImageInfoFromCache() + { + $this->_cacheManager->clean([$this->cachePrefix]); + } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php index f918692cb2753..627aa1848506e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php @@ -5,12 +5,10 @@ */ namespace Magento\Catalog\Test\Unit\Model\Product; -use Magento\Catalog\Model\View\Asset\Image\ContextFactory; use Magento\Catalog\Model\View\Asset\ImageFactory; use Magento\Catalog\Model\View\Asset\PlaceholderFactory; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\View\Asset\ContextInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -73,10 +71,24 @@ class ImageTest extends \PHPUnit\Framework\TestCase */ private $viewAssetPlaceholderFactory; + /** + * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializer; + + /** + * @var \Magento\Framework\App\CacheInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $cacheManager; + protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->context = $this->createMock(\Magento\Framework\Model\Context::class); + $this->cacheManager = $this->getMockBuilder(\Magento\Framework\App\CacheInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->context->expects($this->any())->method('getCacheManager')->will($this->returnValue($this->cacheManager)); $this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManager::class) ->disableOriginalConstructor() @@ -112,17 +124,36 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); + $this->serializer = $this->getMockBuilder( + \Magento\Framework\Serialize\SerializerInterface::class + )->getMockForAbstractClass(); + $this->serializer->expects($this->any()) + ->method('serialize') + ->willReturnCallback( + function ($value) { + return json_encode($value); + } + ); + $this->serializer->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($value) { + return json_decode($value, true); + } + ); $this->image = $objectManager->getObject( \Magento\Catalog\Model\Product\Image::class, [ + 'context' => $this->context, 'storeManager' => $this->storeManager, 'catalogProductMediaConfig' => $this->config, 'coreFileStorageDatabase' => $this->coreFileHelper, 'filesystem' => $this->filesystem, 'imageFactory' => $this->factory, 'viewAssetImageFactory' => $this->viewAssetImageFactory, - 'viewAssetPlaceholderFactory' => $this->viewAssetPlaceholderFactory + 'viewAssetPlaceholderFactory' => $this->viewAssetPlaceholderFactory, + 'serializer' => $this->serializer ] ); @@ -354,12 +385,16 @@ public function testIsCached() $this->testSetGetBaseFile(); $absolutePath = dirname(dirname(__DIR__)) . '/_files/catalog/product/watermark/somefile.png'; $this->imageAsset->expects($this->any())->method('getPath')->willReturn($absolutePath); + $this->cacheManager->expects($this->once())->method('load')->willReturn( + json_encode(['size' => ['image data']]) + ); $this->assertTrue($this->image->isCached()); } public function testClearCache() { $this->coreFileHelper->expects($this->once())->method('deleteFolder')->will($this->returnValue(true)); + $this->cacheManager->expects($this->once())->method('clean'); $this->image->clearCache(); } @@ -383,4 +418,24 @@ public function testIsBaseFilePlaceholder() { $this->assertFalse($this->image->isBaseFilePlaceholder()); } + + public function testGetResizedImageInfoWithCache() + { + $absolutePath = dirname(dirname(__DIR__)) . '/_files/catalog/product/watermark/somefile.png'; + $this->imageAsset->expects($this->any())->method('getPath')->willReturn($absolutePath); + $this->cacheManager->expects($this->once())->method('load')->willReturn( + json_encode(['size' => ['image data']]) + ); + $this->cacheManager->expects($this->never())->method('save'); + $this->assertEquals(['image data'], $this->image->getResizedImageInfo()); + } + + public function testGetResizedImageInfoEmptyCache() + { + $absolutePath = dirname(dirname(__DIR__)) . '/_files/catalog/product/watermark/somefile.png'; + $this->imageAsset->expects($this->any())->method('getPath')->willReturn($absolutePath); + $this->cacheManager->expects($this->once())->method('load')->willReturn(false); + $this->cacheManager->expects($this->once())->method('save'); + $this->assertTrue(is_array($this->image->getResizedImageInfo())); + } }