Skip to content

Commit 63fb1d0

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'chaika/MC-30461' into Chaika-PR23-2020-01-22
2 parents 7f37bdc + b362c22 commit 63fb1d0

File tree

4 files changed

+12
-86
lines changed

4 files changed

+12
-86
lines changed

app/code/Magento/ProductAlert/Block/Product/ImageProvider.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
*/
66
namespace Magento\ProductAlert\Block\Product;
77

8-
use Magento\Store\Model\App\Emulation;
98
use Magento\Catalog\Block\Product\ImageBuilder;
109
use Magento\Catalog\Model\Product;
11-
use Magento\Store\Model\StoreManagerInterface;
12-
use Magento\Framework\App\Area;
1310
use Magento\Catalog\Block\Product\Image;
1411

1512
/**
@@ -22,32 +19,18 @@ class ImageProvider
2219
*/
2320
private $imageBuilder;
2421

25-
/**
26-
* @var StoreManagerInterface
27-
*/
28-
private $storeManager;
29-
30-
/**
31-
* @var Emulation
32-
*/
33-
private $appEmulation;
34-
3522
/**
3623
* @param ImageBuilder $imageBuilder
37-
* @param StoreManagerInterface $storeManager
38-
* @param Emulation $appEmulation
3924
*/
4025
public function __construct(
41-
ImageBuilder $imageBuilder,
42-
StoreManagerInterface $storeManager,
43-
Emulation $appEmulation
26+
ImageBuilder $imageBuilder
4427
) {
4528
$this->imageBuilder = $imageBuilder;
46-
$this->storeManager = $storeManager;
47-
$this->appEmulation = $appEmulation;
4829
}
4930

5031
/**
32+
* Gets Product Image Block
33+
*
5134
* @param Product $product
5235
* @param string $imageId
5336
* @param array $attributes
@@ -56,17 +39,6 @@ public function __construct(
5639
*/
5740
public function getImage(Product $product, $imageId, $attributes = [])
5841
{
59-
$storeId = $this->storeManager->getStore()->getId();
60-
$this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
61-
62-
try {
63-
$image = $this->imageBuilder->create($product, $imageId, $attributes);
64-
} catch (\Exception $exception) {
65-
$this->appEmulation->stopEnvironmentEmulation();
66-
throw $exception;
67-
}
68-
69-
$this->appEmulation->stopEnvironmentEmulation();
70-
return $image;
42+
return $this->imageBuilder->create($product, $imageId, $attributes);
7143
}
7244
}

app/code/Magento/ProductAlert/Model/Observer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ protected function _processPrice(\Magento\ProductAlert\Model\Email $email)
242242
);
243243

244244
$product->setCustomerGroupId($customer->getGroupId());
245+
$this->_storeManager->getStore()->setWebsiteId($website->getId());
245246
if ($alert->getPrice() > $product->getFinalPrice()) {
246247
$productPrice = $product->getFinalPrice();
247248
$product->setFinalPrice($this->_catalogData->getTaxPrice($product, $productPrice));

app/code/Magento/ProductAlert/Test/Unit/Block/Product/ImageProviderTest.php

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ class ImageProviderTest extends \PHPUnit\Framework\TestCase
1212
*/
1313
private $imageBuilderMock;
1414

15-
/**
16-
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
17-
*/
18-
private $storeManagerMock;
19-
20-
/**
21-
* @var \Magento\Store\Model\App\Emulation|\PHPUnit_Framework_MockObject_MockObject
22-
*/
23-
private $emulationMock;
24-
2515
/**
2616
* @var \Magento\ProductAlert\Block\Product\ImageProvider
2717
*/
@@ -32,17 +22,9 @@ protected function setUp()
3222
$this->imageBuilderMock = $this->getMockBuilder(\Magento\Catalog\Block\Product\ImageBuilder::class)
3323
->disableOriginalConstructor()
3424
->getMock();
35-
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
36-
->disableOriginalConstructor()
37-
->getMock();
38-
$this->emulationMock = $this->getMockBuilder(\Magento\Store\Model\App\Emulation::class)
39-
->disableOriginalConstructor()
40-
->getMock();
4125

4226
$this->model = new \Magento\ProductAlert\Block\Product\ImageProvider(
43-
$this->imageBuilderMock,
44-
$this->storeManagerMock,
45-
$this->emulationMock
27+
$this->imageBuilderMock
4628
);
4729
}
4830

@@ -56,44 +38,11 @@ public function testGetImage()
5638

5739
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
5840
$imageMock = $this->createMock(\Magento\Catalog\Block\Product\Image::class);
59-
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
60-
61-
$this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')->willReturn($storeMock);
62-
$this->emulationMock->expects($this->once())->method('startEnvironmentEmulation');
6341
$this->imageBuilderMock->expects($this->once())
6442
->method('create')
6543
->with($productMock, $imageId, $attributes)
6644
->willReturn($imageMock);
67-
$this->emulationMock->expects($this->once())->method('stopEnvironmentEmulation');
6845

6946
$this->assertEquals($imageMock, $this->model->getImage($productMock, $imageId, $attributes));
7047
}
71-
72-
/**
73-
* Test that app emulation stops when exception occurs.
74-
*
75-
* @expectedException \Exception
76-
* @expectedExceptionMessage Image Builder Exception
77-
*/
78-
public function testGetImageThrowsAnException()
79-
{
80-
$imageId = 1;
81-
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
82-
->disableOriginalConstructor()
83-
->getMock();
84-
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
85-
->disableOriginalConstructor()
86-
->getMock();
87-
88-
$this->emulationMock->expects($this->once())->method('startEnvironmentEmulation');
89-
$this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')->willReturn($storeMock);
90-
91-
$this->imageBuilderMock->expects($this->once())
92-
->method('create')
93-
->with($productMock, $imageId)
94-
->willThrowException(new \Exception("Image Builder Exception"));
95-
96-
$this->emulationMock->expects($this->once())->method('stopEnvironmentEmulation');
97-
$this->model->getImage($productMock, $imageId);
98-
}
9948
}

app/code/Magento/ProductAlert/Test/Unit/Model/ObserverTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
/**
1313
* Class ObserverTest
14+
*
15+
* Is used to test Product Alert Observer
16+
*
1417
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1518
* @SuppressWarnings(PHPMD.TooManyFields)
1619
*/
@@ -168,7 +171,7 @@ protected function setUp()
168171
);
169172
$this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
170173
->disableOriginalConstructor()
171-
->setMethods(['getDefaultStore', 'getId'])
174+
->setMethods(['getDefaultStore', 'getId', 'setWebsiteId'])
172175
->getMock();
173176
$this->customerRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\CustomerRepositoryInterface::class)
174177
->getMock();
@@ -285,12 +288,13 @@ public function testProcessPriceEmailThrowsException()
285288
$this->storeMock->expects($this->any())->method('getDefaultStore')->willReturnSelf();
286289
$this->websiteMock->expects($this->once())->method('getDefaultStore')->willReturn($this->storeMock);
287290
$this->storeMock->expects($this->any())->method('getId')->willReturn(2);
291+
$this->storeMock->expects($this->any())->method('setWebsiteId')->willReturnSelf();
288292

289293
$this->scopeConfigMock->expects($this->once())->method('getValue')->willReturn(true);
290294

291295
$this->priceColFactoryMock->expects($this->once())->method('create')->willReturnSelf();
292296
$this->priceColFactoryMock->expects($this->once())->method('addWebsiteFilter')->willReturnSelf();
293-
297+
$this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
294298
$items = [
295299
new \Magento\Framework\DataObject([
296300
'customer_id' => $id

0 commit comments

Comments
 (0)