-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdjustmentTest.php
179 lines (154 loc) · 5.1 KB
/
AdjustmentTest.php
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Tax\Test\Unit\Pricing;
use \Magento\Tax\Pricing\Adjustment;
use Magento\Framework\Pricing\SaleableInterface;
class AdjustmentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Adjustment
*/
protected $adjustment;
/**
* @var \Magento\Tax\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
*/
protected $taxHelper;
/**
* @var \Magento\Catalog\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
*/
protected $catalogHelper;
/**
* @var int
*/
protected $sortOrder = 5;
protected function setUp()
{
$this->taxHelper = $this->getMock('Magento\Tax\Helper\Data', [], [], '', false);
$this->catalogHelper = $this->getMock('Magento\Catalog\Helper\Data', [], [], '', false);
$this->adjustment = new Adjustment($this->taxHelper, $this->catalogHelper, $this->sortOrder);
}
public function testGetAdjustmentCode()
{
$this->assertEquals(Adjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
}
/**
* @param bool $expectedResult
* @dataProvider isIncludedInBasePriceDataProvider
*/
public function testIsIncludedInBasePrice($expectedResult)
{
$this->taxHelper->expects($this->once())
->method('priceIncludesTax')
->will($this->returnValue($expectedResult));
$this->assertEquals($expectedResult, $this->adjustment->isIncludedInBasePrice());
}
public function isIncludedInBasePriceDataProvider()
{
return [[true], [false]];
}
/**
* @dataProvider isIncludedInDisplayPriceDataProvider
*/
public function testIsIncludedInDisplayPrice($displayPriceIncludingTax, $displayBothPrices, $expectedResult)
{
$this->taxHelper->expects($this->once())
->method('displayPriceIncludingTax')
->will($this->returnValue($displayPriceIncludingTax));
if (!$displayPriceIncludingTax) {
$this->taxHelper->expects($this->once())
->method('displayBothPrices')
->will($this->returnValue($displayBothPrices));
}
$this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
}
/**
* @return array
*/
public function isIncludedInDisplayPriceDataProvider()
{
return [
[false, false, false],
[false, true, true],
[true, false, true],
[true, true, true],
];
}
/**
* @param float $amount
* @param bool $isPriceIncludesTax
* @param float $price
* @param float $expectedResult
* @dataProvider extractAdjustmentDataProvider
*/
public function testExtractAdjustment($isPriceIncludesTax, $amount, $price, $expectedResult)
{
$object = $this->getMockForAbstractClass('Magento\Framework\Pricing\SaleableInterface');
$this->taxHelper->expects($this->any())
->method('priceIncludesTax')
->will($this->returnValue($isPriceIncludesTax));
$this->catalogHelper->expects($this->any())
->method('getTaxPrice')
->with($object, $amount)
->will($this->returnValue($price));
$this->assertEquals($expectedResult, $this->adjustment->extractAdjustment($amount, $object));
}
public function extractAdjustmentDataProvider()
{
return [
[false, 'not_important', 'not_important', 0.00],
[true, 10.1, 0.2, 9.9],
[true, 10.1, 20.3, -10.2],
[true, 0.0, 0.0, 0],
];
}
/**
* @param bool $isPriceIncludesTax
* @param float $amount
* @param float $price
* @param $expectedResult
* @dataProvider applyAdjustmentDataProvider
*/
public function testApplyAdjustment($amount, $price, $expectedResult)
{
$object = $this->getMockBuilder('Magento\Framework\Pricing\SaleableInterface')->getMock();
$this->catalogHelper->expects($this->any())
->method('getTaxPrice')
->with($object, $amount, true)
->will($this->returnValue($price));
$this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
}
/**
* @return array
*/
public function applyAdjustmentDataProvider()
{
return [
[1.1, 2.2, 2.2],
[0.0, 2.2, 2.2],
[1.1, 0.0, 0.0],
];
}
/**
* @dataProvider isExcludedWithDataProvider
* @param string $adjustmentCode
* @param bool $expectedResult
*/
public function testIsExcludedWith($adjustmentCode, $expectedResult)
{
$this->assertEquals($expectedResult, $this->adjustment->isExcludedWith($adjustmentCode));
}
public function isExcludedWithDataProvider()
{
return [
[Adjustment::ADJUSTMENT_CODE, true],
['not_tax', false]
];
}
public function testGetSortOrder()
{
$this->assertEquals($this->sortOrder, $this->adjustment->getSortOrder());
}
}