Skip to content

Commit c751336

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-94455' into 2.2-develop-pr61
2 parents 0873a70 + f08c195 commit c751336

File tree

2 files changed

+49
-14
lines changed
  • app/code/Magento/Catalog
    • Test/Unit/Ui/DataProvider/Product/Listing/Collector
    • Ui/DataProvider/Product/Listing/Collector

2 files changed

+49
-14
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Listing/Collector/ImageTest.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Listing\Collector;
88

9+
use Magento\Catalog\Api\Data\ProductInterface;
10+
use Magento\Catalog\Api\Data\ProductRender\ImageInterface;
911
use Magento\Catalog\Api\Data\ProductRenderInterface;
12+
use Magento\Catalog\Helper\Image as ImageHelper;
13+
use Magento\Catalog\Helper\ImageFactory;
1014
use Magento\Catalog\Model\Product;
11-
use Magento\Catalog\Api\Data\ProductInterface;
1215
use Magento\Catalog\Ui\DataProvider\Product\Listing\Collector\Image;
1316
use Magento\Framework\View\DesignInterface;
17+
use Magento\Framework\View\DesignLoader;
1418
use Magento\Store\Model\StoreManagerInterface;
15-
use Magento\Catalog\Helper\ImageFactory;
16-
use Magento\Catalog\Api\Data\ProductRender\ImageInterface;
17-
use Magento\Catalog\Helper\Image as ImageHelper;
1819

1920
/**
2021
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -42,8 +43,21 @@ class ImageTest extends \PHPUnit\Framework\TestCase
4243
/** @var \Magento\Catalog\Api\Data\ProductRender\ImageInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */
4344
private $imageInterfaceFactory;
4445

46+
/** @var DesignLoader|\PHPUnit_Framework_MockObject_MockObject */
47+
private $designLoader;
48+
49+
/**
50+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
51+
*/
52+
protected $objectManager;
53+
54+
/**
55+
* @inheritdoc
56+
*/
4557
public function setUp()
4658
{
59+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
60+
4761
$this->imageFactory = $this->getMockBuilder(ImageFactory::class)
4862
->disableOriginalConstructor()
4963
->getMock();
@@ -60,14 +74,21 @@ public function setUp()
6074
->getMock();
6175
$this->storeManager = $this->createMock(StoreManagerInterface::class);
6276
$this->design = $this->createMock(DesignInterface::class);
63-
$this->model = new Image(
64-
$this->imageFactory,
65-
$this->state,
66-
$this->storeManager,
67-
$this->design,
68-
$this->imageInterfaceFactory,
69-
$this->imageCodes
70-
);
77+
$this->designLoader = $this->createMock(DesignLoader::class);
78+
79+
$this->model = $this->objectManager
80+
->getObject(
81+
Image::class,
82+
[
83+
'imageFactory' => $this->imageFactory,
84+
'state' => $this->state,
85+
'storeManager' => $this->storeManager,
86+
'design' => $this->design,
87+
'imageRenderInfoFactory' => $this->imageInterfaceFactory,
88+
'imageCodes' => $this->imageCodes,
89+
'designLoader' => $this->designLoader,
90+
]
91+
);
7192
}
7293

7394
public function testGet()
@@ -165,6 +186,7 @@ public function testEmulateImageCreating()
165186
$imageMock->expects($this->once())
166187
->method('setUrl')
167188
->with('url');
189+
$this->designLoader->expects($this->once())->method('load');
168190

169191
$this->assertEquals(
170192
$imageHelperMock,

app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/Collector/Image.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
use Magento\Framework\View\DesignInterface;
1818
use Magento\Store\Model\StoreManager;
1919
use Magento\Store\Model\StoreManagerInterface;
20+
use Magento\Framework\View\DesignLoader;
2021

2122
/**
2223
* Collect enough information about image rendering on front
2324
* If you want to add new image, that should render on front you need
2425
* to configure this class in di.xml
2526
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628
*/
2729
class Image implements ProductRenderCollectorInterface
2830
{
@@ -59,6 +61,11 @@ class Image implements ProductRenderCollectorInterface
5961
*/
6062
private $imageRenderInfoFactory;
6163

64+
/**
65+
* @var DesignLoader
66+
*/
67+
private $designLoader;
68+
6269
/**
6370
* Image constructor.
6471
* @param ImageFactory $imageFactory
@@ -67,21 +74,25 @@ class Image implements ProductRenderCollectorInterface
6774
* @param DesignInterface $design
6875
* @param ImageInterfaceFactory $imageRenderInfoFactory
6976
* @param array $imageCodes
77+
* @param DesignLoader|null $designLoader
7078
*/
7179
public function __construct(
7280
ImageFactory $imageFactory,
7381
State $state,
7482
StoreManagerInterface $storeManager,
7583
DesignInterface $design,
7684
ImageInterfaceFactory $imageRenderInfoFactory,
77-
array $imageCodes = []
85+
array $imageCodes = [],
86+
DesignLoader $designLoader = null
7887
) {
7988
$this->imageFactory = $imageFactory;
8089
$this->imageCodes = $imageCodes;
8190
$this->state = $state;
8291
$this->storeManager = $storeManager;
8392
$this->design = $design;
8493
$this->imageRenderInfoFactory = $imageRenderInfoFactory;
94+
$this->designLoader = $designLoader ?: \Magento\Framework\App\ObjectManager::getInstance()
95+
->get(DesignLoader::class);
8596
}
8697

8798
/**
@@ -124,6 +135,8 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
124135
}
125136

126137
/**
138+
* Callback for emulating image creation.
139+
*
127140
* Callback in which we emulate initialize default design theme, depends on current store, be settings store id
128141
* from render info
129142
*
@@ -136,7 +149,7 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
136149
public function emulateImageCreating(ProductInterface $product, $imageCode, $storeId, ImageInterface $image)
137150
{
138151
$this->storeManager->setCurrentStore($storeId);
139-
$this->design->setDefaultDesignTheme();
152+
$this->designLoader->load();
140153

141154
$imageHelper = $this->imageFactory->create();
142155
$imageHelper->init($product, $imageCode);

0 commit comments

Comments
 (0)