3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Tax \Test \Unit \Model \Sales \Total \Quote ;
8
9
9
- /**
10
- * Test class for \Magento\Tax\Model\Sales\Total\Quote\Tax
11
- */
12
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
11
+ use Magento \Tax \Helper \Data as TaxHelper ;
12
+ use Magento \Tax \Api \Data \TaxDetailsItemInterface ;
13
+ use Magento \Quote \Model \Quote \Item as QuoteItem ;
14
+ use Magento \Store \Model \Store ;
15
+ use Magento \Tax \Model \Sales \Total \Quote \CommonTaxCollector ;
16
+ use Magento \Tax \Model \Config ;
17
+ use Magento \Quote \Model \Quote \Address as QuoteAddress ;
18
+ use Magento \Quote \Model \Quote ;
19
+ use Magento \Tax \Api \Data \QuoteDetailsItemInterface ;
20
+ use Magento \Tax \Api \Data \TaxClassKeyInterface ;
21
+ use Magento \Tax \Model \Sales \Quote \ItemDetails ;
22
+ use Magento \Tax \Model \TaxClass \Key as TaxClassKey ;
23
+ use Magento \Tax \Api \Data \QuoteDetailsItemInterfaceFactory ;
24
+ use Magento \Tax \Api \Data \TaxClassKeyInterfaceFactory ;
25
+ use Magento \Quote \Api \Data \ShippingAssignmentInterface ;
26
+ use Magento \Quote \Api \Data \ShippingInterface ;
27
+ use Magento \Quote \Model \Quote \Address \Total as QuoteAddressTotal ;
28
+ use PHPUnit \Framework \MockObject \MockObject ;
29
+ use PHPUnit \Framework \TestCase ;
13
30
14
31
/**
32
+ * Common tax collector test
33
+ *
15
34
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16
35
*/
17
- class CommonTaxCollectorTest extends \ PHPUnit \ Framework \ TestCase
36
+ class CommonTaxCollectorTest extends TestCase
18
37
{
19
38
/**
20
- * @var \Magento\Tax\Model\Sales\Total\Quote\ CommonTaxCollector
39
+ * @var CommonTaxCollector
21
40
*/
22
41
private $ commonTaxCollector ;
23
42
24
43
/**
25
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Tax\Model\ Config
44
+ * @var MockObject| Config
26
45
*/
27
46
private $ taxConfig ;
28
47
29
48
/**
30
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote\Address
49
+ * @var MockObject|QuoteAddress
31
50
*/
32
51
private $ address ;
33
52
34
53
/**
35
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\ Quote
54
+ * @var MockObject| Quote
36
55
*/
37
56
private $ quote ;
38
57
39
58
/**
40
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\ Store
59
+ * @var MockObject| Store
41
60
*/
42
61
private $ store ;
43
62
44
63
/**
45
- * @var \PHPUnit_Framework_MockObject_MockObject|
64
+ * @var MockObject
46
65
*/
47
66
protected $ taxClassKeyDataObjectFactoryMock ;
48
67
49
68
/**
50
- * @var \PHPUnit_Framework_MockObject_MockObject|
69
+ * @var MockObject
51
70
*/
52
71
protected $ quoteDetailsItemDataObjectFactoryMock ;
53
72
54
73
/**
55
- * @var \Magento\Tax\Api\Data\ QuoteDetailsItemInterface
74
+ * @var QuoteDetailsItemInterface
56
75
*/
57
76
protected $ quoteDetailsItemDataObject ;
58
77
59
78
/**
60
- * @var \Magento\Tax\Api\Data\ TaxClassKeyInterface
79
+ * @var TaxClassKeyInterface
61
80
*/
62
81
protected $ taxClassKeyDataObject ;
63
82
83
+ /**
84
+ * @var TaxHelper
85
+ */
86
+ protected $ taxHelper ;
87
+
88
+ /**
89
+ * {@inheritdoc}
90
+ */
64
91
protected function setUp ()
65
92
{
66
93
$ objectManager = new ObjectManager ($ this );
67
94
68
- $ this ->taxConfig = $ this ->getMockBuilder (\ Magento \ Tax \ Model \ Config::class)
95
+ $ this ->taxConfig = $ this ->getMockBuilder (Config::class)
69
96
->disableOriginalConstructor ()
70
- ->setMethods (['getShippingTaxClass ' , 'shippingPriceIncludesTax ' ])
97
+ ->setMethods (['getShippingTaxClass ' , 'shippingPriceIncludesTax ' , ' discountTax ' ])
71
98
->getMock ();
72
99
73
- $ this ->store = $ this ->getMockBuilder (\ Magento \ Store \ Model \ Store::class)
100
+ $ this ->store = $ this ->getMockBuilder (Store::class)
74
101
->disableOriginalConstructor ()
75
102
->setMethods (['__wakeup ' ])
76
103
->getMock ();
77
104
78
- $ this ->quote = $ this ->getMockBuilder (\ Magento \ Quote \ Model \ Quote::class)
105
+ $ this ->quote = $ this ->getMockBuilder (Quote::class)
79
106
->disableOriginalConstructor ()
80
107
->setMethods (['__wakeup ' , 'getStore ' ])
81
108
->getMock ();
@@ -84,39 +111,43 @@ protected function setUp()
84
111
->method ('getStore ' )
85
112
->will ($ this ->returnValue ($ this ->store ));
86
113
87
- $ this ->address = $ this ->getMockBuilder (\ Magento \ Quote \ Model \ Quote \Address ::class)
114
+ $ this ->address = $ this ->getMockBuilder (QuoteAddress ::class)
88
115
->disableOriginalConstructor ()
89
116
->getMock ();
90
117
91
118
$ this ->address ->expects ($ this ->any ())
92
119
->method ('getQuote ' )
93
120
->will ($ this ->returnValue ($ this ->quote ));
94
121
$ methods = ['create ' ];
95
- $ this ->quoteDetailsItemDataObject = $ objectManager ->getObject (
96
- \Magento \Tax \Model \Sales \Quote \ItemDetails::class
97
- );
98
- $ this ->taxClassKeyDataObject = $ objectManager ->getObject (\Magento \Tax \Model \TaxClass \Key::class);
122
+ $ this ->quoteDetailsItemDataObject = $ objectManager ->getObject (ItemDetails::class);
123
+ $ this ->taxClassKeyDataObject = $ objectManager ->getObject (TaxClassKey::class);
99
124
$ this ->quoteDetailsItemDataObjectFactoryMock
100
- = $ this ->createPartialMock (\ Magento \ Tax \ Api \ Data \ QuoteDetailsItemInterfaceFactory::class, $ methods );
125
+ = $ this ->createPartialMock (QuoteDetailsItemInterfaceFactory::class, $ methods );
101
126
$ this ->quoteDetailsItemDataObjectFactoryMock ->expects ($ this ->any ())
102
127
->method ('create ' )
103
128
->willReturn ($ this ->quoteDetailsItemDataObject );
104
129
$ this ->taxClassKeyDataObjectFactoryMock =
105
- $ this ->createPartialMock (\ Magento \ Tax \ Api \ Data \ TaxClassKeyInterfaceFactory::class, $ methods );
130
+ $ this ->createPartialMock (TaxClassKeyInterfaceFactory::class, $ methods );
106
131
$ this ->taxClassKeyDataObjectFactoryMock ->expects ($ this ->any ())
107
132
->method ('create ' )
108
133
->willReturn ($ this ->taxClassKeyDataObject );
134
+ $ this ->taxHelper = $ this ->getMockBuilder (TaxHelper::class)
135
+ ->disableOriginalConstructor ()
136
+ ->getMock ();
109
137
$ this ->commonTaxCollector = $ objectManager ->getObject (
110
- \ Magento \ Tax \ Model \ Sales \ Total \ Quote \ CommonTaxCollector::class,
138
+ CommonTaxCollector::class,
111
139
[
112
140
'taxConfig ' => $ this ->taxConfig ,
113
141
'quoteDetailsItemDataObjectFactory ' => $ this ->quoteDetailsItemDataObjectFactoryMock ,
114
- 'taxClassKeyDataObjectFactory ' => $ this ->taxClassKeyDataObjectFactoryMock
142
+ 'taxClassKeyDataObjectFactory ' => $ this ->taxClassKeyDataObjectFactoryMock ,
143
+ 'taxHelper ' => $ this ->taxHelper ,
115
144
]
116
145
);
117
146
}
118
147
119
148
/**
149
+ * Test for GetShippingDataObject
150
+ *
120
151
* @param array $addressData
121
152
* @param bool $useBaseCurrency
122
153
* @param string $shippingTaxClass
@@ -128,8 +159,8 @@ public function testGetShippingDataObject(
128
159
$ useBaseCurrency ,
129
160
$ shippingTaxClass ,
130
161
$ shippingPriceInclTax
131
- ) {
132
- $ shippingAssignmentMock = $ this ->createMock (\ Magento \ Quote \ Api \ Data \ ShippingAssignmentInterface::class);
162
+ ): void {
163
+ $ shippingAssignmentMock = $ this ->createMock (ShippingAssignmentInterface::class);
133
164
$ methods = [
134
165
'getShippingDiscountAmount ' ,
135
166
'getShippingTaxCalculationAmount ' ,
@@ -139,8 +170,10 @@ public function testGetShippingDataObject(
139
170
'getBaseShippingAmount ' ,
140
171
'getBaseShippingDiscountAmount '
141
172
];
142
- $ totalsMock = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Address \Total::class, $ methods );
143
- $ shippingMock = $ this ->createMock (\Magento \Quote \Api \Data \ShippingInterface::class);
173
+ /** @var MockObject|QuoteAddressTotal $totalsMock */
174
+ $ totalsMock = $ this ->createPartialMock (QuoteAddressTotal::class, $ methods );
175
+ $ shippingMock = $ this ->createMock (ShippingInterface::class);
176
+ /** @var MockObject|ShippingAssignmentInterface $shippingAssignmentMock */
144
177
$ shippingAssignmentMock ->expects ($ this ->once ())->method ('getShipping ' )->willReturn ($ shippingMock );
145
178
$ shippingMock ->expects ($ this ->once ())->method ('getAddress ' )->willReturn ($ this ->address );
146
179
$ baseShippingAmount = $ addressData ['base_shipping_amount ' ];
@@ -184,9 +217,44 @@ public function testGetShippingDataObject(
184
217
}
185
218
186
219
/**
220
+ * Update item tax info
221
+ *
222
+ * @return void
223
+ */
224
+ public function testUpdateItemTaxInfo (): void
225
+ {
226
+ /** @var MockObject|QuoteItem $quoteItem */
227
+ $ quoteItem = $ this ->getMockBuilder (QuoteItem::class)
228
+ ->disableOriginalConstructor ()
229
+ ->setMethods (['getPrice ' , 'setPrice ' , 'getCustomPrice ' , 'setCustomPrice ' ])
230
+ ->getMock ();
231
+ $ this ->taxHelper ->method ('applyTaxOnCustomPrice ' )->willReturn (true );
232
+ $ quoteItem ->method ('getCustomPrice ' )->willReturn (true );
233
+ /** @var MockObject|TaxDetailsItemInterface $itemTaxDetails */
234
+ $ itemTaxDetails = $ this ->getMockBuilder (TaxDetailsItemInterface::class)
235
+ ->disableOriginalConstructor ()
236
+ ->getMock ();
237
+ /** @var MockObject|TaxDetailsItemInterface $baseItemTaxDetails */
238
+ $ baseItemTaxDetails = $ this ->getMockBuilder (TaxDetailsItemInterface::class)
239
+ ->disableOriginalConstructor ()
240
+ ->getMock ();
241
+
242
+ $ quoteItem ->expects ($ this ->once ())->method ('setCustomPrice ' );
243
+
244
+ $ this ->commonTaxCollector ->updateItemTaxInfo (
245
+ $ quoteItem ,
246
+ $ itemTaxDetails ,
247
+ $ baseItemTaxDetails ,
248
+ $ this ->store
249
+ );
250
+ }
251
+
252
+ /**
253
+ * Data for testGetShippingDataObject
254
+ *
187
255
* @return array
188
256
*/
189
- public function getShippingDataObjectDataProvider ()
257
+ public function getShippingDataObjectDataProvider (): array
190
258
{
191
259
$ data = [
192
260
'free_shipping ' => [
0 commit comments