1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Msrp\Test\Unit\Helper;
use Magento\Msrp\Pricing\MsrpPriceCalculatorInterface;
/**
* Class DataTest
*/
class DataTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Msrp\Helper\Data
*/
protected $helper;
/**
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrencyMock;
/**
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
*/
protected $productMock;
/**
* @var MsrpPriceCalculatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $msrpPriceCalculator;
/**
* @inheritdoc
*/
protected function setUp()
{
$this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
$this->productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->setMethods(['getMsrp', 'getPriceInfo', '__wakeup'])
->getMock();
$this->msrpPriceCalculator = $this->getMockBuilder(MsrpPriceCalculatorInterface::class)
->getMockForAbstractClass();
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->helper = $objectManager->getObject(
\Magento\Msrp\Helper\Data::class,
[
'priceCurrency' => $this->priceCurrencyMock,
'msrpPriceCalculator' => $this->msrpPriceCalculator,
]
);
}
/**
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function testIsMinimalPriceLessMsrp()
{
$msrp = 120;
$convertedFinalPrice = 200;
$this->priceCurrencyMock->expects($this->any())
->method('convertAndRound')
->will(
$this->returnCallback(
function ($arg) {
return round(2 * $arg, 2);
}
)
);
$finalPriceMock = $this->getMockBuilder(\Magento\Catalog\Pricing\Price\FinalPrice::class)
->disableOriginalConstructor()
->getMock();
$finalPriceMock->expects($this->any())
->method('getValue')
->will($this->returnValue($convertedFinalPrice));
$priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class)
->disableOriginalConstructor()
->getMock();
$priceInfoMock->expects($this->once())
->method('getPrice')
->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
->will($this->returnValue($finalPriceMock));
$this->msrpPriceCalculator
->expects($this->any())
->method('getMsrpPriceValue')
->willReturn($msrp);
$this->productMock->expects($this->any())
->method('getPriceInfo')
->willReturn($priceInfoMock);
$result = $this->helper->isMinimalPriceLessMsrp($this->productMock);
$this->assertTrue($result, "isMinimalPriceLessMsrp returned incorrect value");
}
}