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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Pricing\Test\Unit\Price;
use \Magento\Framework\Pricing\Price\AbstractPrice;
/**
* Class RegularPriceTest
*/
class AbstractPriceTest extends \PHPUnit\Framework\TestCase
{
/**
* @var AbstractPrice
*/
protected $price;
/**
* @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceInfoMock;
/**
* @var \Magento\Framework\Pricing\SaleableInterface |\PHPUnit_Framework_MockObject_MockObject
*/
protected $saleableItemMock;
/**
* @var \Magento\Framework\Pricing\Adjustment\Calculator |\PHPUnit_Framework_MockObject_MockObject
*/
protected $calculatorMock;
/**
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrencyMock;
/**
* Test setUp
*/
protected function setUp()
{
$qty = 1;
$this->saleableItemMock = $this->createMock(\Magento\Catalog\Model\Product::class);
$this->priceInfoMock = $this->createMock(\Magento\Framework\Pricing\PriceInfo\Base::class);
$this->calculatorMock = $this->createMock(\Magento\Framework\Pricing\Adjustment\Calculator::class);
$this->saleableItemMock->expects($this->once())
->method('getPriceInfo')
->will($this->returnValue($this->priceInfoMock));
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
$this->price = $objectManager->getObject(
\Magento\Framework\Pricing\Test\Unit\Price\Stub::class,
[
'saleableItem' => $this->saleableItemMock,
'quantity' => $qty,
'calculator' => $this->calculatorMock,
'priceCurrency' => $this->priceCurrencyMock,
]
);
}
/**
* Test method testGetDisplayValue
*/
public function testGetAmount()
{
$priceValue = $this->price->getValue();
$amountValue = 88;
$this->calculatorMock->expects($this->once())
->method('getAmount')
->with($this->equalTo($priceValue))
->will($this->returnValue($amountValue));
$this->assertEquals($amountValue, $this->price->getAmount());
}
/**
* Test method getPriceType
*/
public function testGetPriceCode()
{
$this->assertEquals(AbstractPrice::PRICE_CODE, $this->price->getPriceCode());
}
public function testGetCustomAmount()
{
$exclude = false;
$amount = 21.0;
$convertedValue = 30.25;
$customAmount = 42.0;
$this->priceCurrencyMock->expects($this->any())
->method('convertAndRound')
->with($amount)
->will($this->returnValue($convertedValue));
$this->calculatorMock->expects($this->once())
->method('getAmount')
->with($convertedValue, $this->saleableItemMock, $exclude)
->will($this->returnValue($customAmount));
$this->assertEquals($customAmount, $this->price->getCustomAmount($amount, $exclude));
}
public function testGetCustomAmountDefault()
{
$customAmount = 42.0;
$this->calculatorMock->expects($this->once())
->method('getAmount')
->with($this->price->getValue(), $this->saleableItemMock, null)
->will($this->returnValue($customAmount));
$this->assertEquals($customAmount, $this->price->getCustomAmount());
}
public function testGetQuantity()
{
$this->assertEquals(1, $this->price->getQuantity());
}
}