Skip to content

Commit f09dd10

Browse files
author
Oleksandr Dubovyk
committed
MC-30091: In Stock Alert Email Shows Incorrect Item Pricing
- minor changes - modified unit test
1 parent 58faf8b commit f09dd10

File tree

2 files changed

+3
-69
lines changed

2 files changed

+3
-69
lines changed

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

Lines changed: 2 additions & 27 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,29 +19,13 @@ 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
/**
@@ -54,15 +35,9 @@ public function __construct(
5435
* @param string $imageId
5536
* @param array $attributes
5637
* @return Image
57-
* @throws \Exception
5838
*/
5939
public function getImage(Product $product, $imageId, $attributes = [])
6040
{
61-
try {
62-
$image = $this->imageBuilder->create($product, $imageId, $attributes);
63-
} catch (\Exception $exception) {
64-
throw $exception;
65-
}
66-
return $image;
41+
return $this->imageBuilder->create($product, $imageId, $attributes);
6742
}
6843
}

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

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,9 @@ protected function setUp()
3232
$this->imageBuilderMock = $this->getMockBuilder(\Magento\Catalog\Block\Product\ImageBuilder::class)
3333
->disableOriginalConstructor()
3434
->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();
4135

4236
$this->model = new \Magento\ProductAlert\Block\Product\ImageProvider(
43-
$this->imageBuilderMock,
44-
$this->storeManagerMock,
45-
$this->emulationMock
37+
$this->imageBuilderMock
4638
);
4739
}
4840

@@ -56,44 +48,11 @@ public function testGetImage()
5648

5749
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
5850
$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');
6351
$this->imageBuilderMock->expects($this->once())
6452
->method('create')
6553
->with($productMock, $imageId, $attributes)
6654
->willReturn($imageMock);
67-
$this->emulationMock->expects($this->once())->method('stopEnvironmentEmulation');
6855

6956
$this->assertEquals($imageMock, $this->model->getImage($productMock, $imageId, $attributes));
7057
}
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-
}
9958
}

0 commit comments

Comments
 (0)