1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Tax \Test \Unit \Model \Sales \Total \Quote ;
9
9
10
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+ use Magento \Customer \Api \AccountManagementInterface ;
11
+ use Magento \Customer \Api \Data \AddressInterface ;
12
+ use Magento \Customer \Api \Data \RegionInterface ;
13
+ use Magento \Customer \Api \Data \RegionInterfaceFactory ;
14
+ use Magento \Customer \Api \Data \AddressInterfaceFactory ;
11
15
use Magento \Quote \Api \Data \ShippingAssignmentInterface ;
12
16
use Magento \Quote \Api \Data \ShippingInterface ;
13
17
use Magento \Quote \Model \Quote ;
14
18
use Magento \Quote \Model \Quote \Address as QuoteAddress ;
15
19
use Magento \Quote \Model \Quote \Address \Total as QuoteAddressTotal ;
16
20
use Magento \Quote \Model \Quote \Item as QuoteItem ;
17
21
use Magento \Store \Model \Store ;
22
+ use Magento \Tax \Api \Data \QuoteDetailsInterfaceFactory ;
23
+ use Magento \Tax \Api \Data \QuoteDetailsItemExtensionInterfaceFactory ;
18
24
use Magento \Tax \Api \Data \QuoteDetailsItemInterface ;
19
25
use Magento \Tax \Api \Data \QuoteDetailsItemInterfaceFactory ;
20
26
use Magento \Tax \Api \Data \TaxClassKeyInterface ;
21
27
use Magento \Tax \Api \Data \TaxClassKeyInterfaceFactory ;
22
28
use Magento \Tax \Api \Data \TaxDetailsItemInterface ;
29
+ use Magento \Tax \Api \TaxCalculationInterface ;
23
30
use Magento \Tax \Helper \Data as TaxHelper ;
24
31
use Magento \Tax \Model \Config ;
25
32
use Magento \Tax \Model \Sales \Quote \ItemDetails ;
26
33
use Magento \Tax \Model \Sales \Total \Quote \CommonTaxCollector ;
27
34
use Magento \Tax \Model \TaxClass \Key as TaxClassKey ;
35
+ use PHPUnit \Framework \MockObject \Exception ;
28
36
use PHPUnit \Framework \MockObject \MockObject ;
29
37
use PHPUnit \Framework \TestCase ;
30
38
@@ -36,60 +44,88 @@ class CommonTaxCollectorTest extends TestCase
36
44
/**
37
45
* @var CommonTaxCollector
38
46
*/
39
- private $ commonTaxCollector ;
47
+ private CommonTaxCollector $ commonTaxCollector ;
40
48
41
49
/**
42
50
* @var MockObject|Config
43
51
*/
44
- private $ taxConfig ;
52
+ private Config $ taxConfig ;
45
53
46
54
/**
47
55
* @var MockObject|QuoteAddress
48
56
*/
49
- private $ address ;
57
+ private QuoteAddress $ address ;
50
58
51
59
/**
52
60
* @var MockObject|Quote
53
61
*/
54
- private $ quote ;
62
+ private Quote $ quote ;
55
63
56
64
/**
57
65
* @var MockObject|Store
58
66
*/
59
- private $ store ;
67
+ private Store $ store ;
60
68
61
69
/**
62
- * @var MockObject
70
+ * @var TaxClassKeyInterfaceFactory| MockObject
63
71
*/
64
- protected $ taxClassKeyDataObjectFactoryMock ;
72
+ private TaxClassKeyInterfaceFactory $ taxClassKeyDataObjectFactoryMock ;
65
73
66
74
/**
67
- * @var MockObject
75
+ * @var QuoteDetailsItemInterfaceFactory| MockObject
68
76
*/
69
- protected $ quoteDetailsItemDataObjectFactoryMock ;
77
+ private QuoteDetailsItemInterfaceFactory $ quoteDetailsItemDataObjectFactoryMock ;
70
78
71
79
/**
72
- * @var QuoteDetailsItemInterface
80
+ * @var QuoteDetailsItemInterface|MockObject
73
81
*/
74
- protected $ quoteDetailsItemDataObject ;
82
+ private QuoteDetailsItemInterface $ quoteDetailsItemDataObject ;
75
83
76
84
/**
77
- * @var TaxClassKeyInterface
85
+ * @var TaxClassKeyInterface|MockObject
78
86
*/
79
- protected $ taxClassKeyDataObject ;
87
+ private TaxClassKeyInterface $ taxClassKeyDataObject ;
80
88
81
89
/**
82
- * @var TaxHelper
90
+ * @var TaxHelper|MockObject
83
91
*/
84
- private $ taxHelper ;
92
+ private TaxHelper $ taxHelper ;
85
93
86
94
/**
87
- * {@inheritdoc}
95
+ * @var TaxCalculationInterface|TaxCalculationInterface&MockObject|MockObject
96
+ */
97
+ private TaxCalculationInterface $ taxCalculation ;
98
+
99
+ /**
100
+ * @var QuoteDetailsInterfaceFactory|QuoteDetailsInterfaceFactory&MockObject|MockObject
101
+ */
102
+ private QuoteDetailsInterfaceFactory $ quoteDetailsFactory ;
103
+
104
+ /**
105
+ * @var AddressInterfaceFactory|AddressInterfaceFactory&MockObject|MockObject
106
+ */
107
+ private AddressInterfaceFactory $ addressFactory ;
108
+
109
+ /**
110
+ * @var RegionInterfaceFactory|RegionInterfaceFactory&MockObject|MockObject
111
+ */
112
+ private RegionInterfaceFactory $ regionFactory ;
113
+
114
+ /**
115
+ * @var QuoteDetailsItemExtensionInterfaceFactory|QuoteDetailsItemExtensionInterfaceFactory&MockObject|MockObject
116
+ */
117
+ private QuoteDetailsItemExtensionInterfaceFactory $ quoteDetailsItemExtensionFactory ;
118
+
119
+ /**
120
+ * @var AccountManagementInterface|AccountManagementInterface&MockObject|MockObject
121
+ */
122
+ private AccountManagementInterface $ accountManagement ;
123
+
124
+ /**
125
+ * @inheritdoc
88
126
*/
89
127
protected function setUp (): void
90
128
{
91
- $ objectManager = new ObjectManager ($ this );
92
-
93
129
$ this ->taxConfig = $ this ->getMockBuilder (Config::class)
94
130
->disableOriginalConstructor ()
95
131
->onlyMethods (['getShippingTaxClass ' , 'shippingPriceIncludesTax ' , 'discountTax ' ])
@@ -117,8 +153,13 @@ protected function setUp(): void
117
153
->method ('getQuote ' )
118
154
->willReturn ($ this ->quote );
119
155
$ methods = ['create ' ];
120
- $ this ->quoteDetailsItemDataObject = $ objectManager ->getObject (ItemDetails::class);
121
- $ this ->taxClassKeyDataObject = $ objectManager ->getObject (TaxClassKey::class);
156
+ $ this ->quoteDetailsItemDataObject = $ this ->createMock (ItemDetails::class);
157
+ $ this ->quoteDetailsItemDataObject ->method ('setType ' )->willReturnSelf ();
158
+ $ this ->quoteDetailsItemDataObject ->method ('setCode ' )->willReturnSelf ();
159
+ $ this ->quoteDetailsItemDataObject ->method ('setQuantity ' )->willReturnSelf ();
160
+ $ this ->taxClassKeyDataObject = $ this ->createMock (TaxClassKey::class);
161
+ $ this ->taxClassKeyDataObject ->method ('setType ' )->willReturnSelf ();
162
+ $ this ->taxClassKeyDataObject ->method ('setValue ' )->willReturnSelf ();
122
163
$ this ->quoteDetailsItemDataObjectFactoryMock
123
164
= $ this ->createPartialMock (QuoteDetailsItemInterfaceFactory::class, $ methods );
124
165
$ this ->quoteDetailsItemDataObjectFactoryMock
@@ -132,15 +173,78 @@ protected function setUp(): void
132
173
$ this ->taxHelper = $ this ->getMockBuilder (TaxHelper::class)
133
174
->disableOriginalConstructor ()
134
175
->getMock ();
135
- $ this ->commonTaxCollector = $ objectManager ->getObject (
136
- CommonTaxCollector::class,
137
- [
138
- 'taxConfig ' => $ this ->taxConfig ,
139
- 'quoteDetailsItemDataObjectFactory ' => $ this ->quoteDetailsItemDataObjectFactoryMock ,
140
- 'taxClassKeyDataObjectFactory ' => $ this ->taxClassKeyDataObjectFactoryMock ,
141
- 'taxHelper ' => $ this ->taxHelper ,
142
- ]
176
+ $ this ->taxCalculation = $ this ->createMock (TaxCalculationInterface::class);
177
+ $ this ->quoteDetailsFactory = $ this ->createMock (QuoteDetailsInterfaceFactory::class);
178
+ $ this ->addressFactory = $ this ->createMock (AddressInterfaceFactory::class);
179
+ $ this ->regionFactory = $ this ->createMock (RegionInterfaceFactory::class);
180
+ $ this ->quoteDetailsItemExtensionFactory = $ this ->createMock (QuoteDetailsItemExtensionInterfaceFactory::class);
181
+ $ this ->accountManagement = $ this ->createMock (AccountManagementInterface::class);
182
+ $ this ->commonTaxCollector = new CommonTaxCollector (
183
+ $ this ->taxConfig ,
184
+ $ this ->taxCalculation ,
185
+ $ this ->quoteDetailsFactory ,
186
+ $ this ->quoteDetailsItemDataObjectFactoryMock ,
187
+ $ this ->taxClassKeyDataObjectFactoryMock ,
188
+ $ this ->addressFactory ,
189
+ $ this ->regionFactory ,
190
+ $ this ->taxHelper ,
191
+ $ this ->quoteDetailsItemExtensionFactory ,
192
+ $ this ->accountManagement
143
193
);
194
+
195
+ parent ::setUp ();
196
+ }
197
+
198
+ /**
199
+ * @return void
200
+ * @throws Exception
201
+ */
202
+ public function testMapAddress (): void
203
+ {
204
+ $ countryId = 1 ;
205
+ $ regionId = 2 ;
206
+ $ regionCode = 'regionCode ' ;
207
+ $ region = 'region ' ;
208
+ $ postCode = 'postCode ' ;
209
+ $ city = 'city ' ;
210
+ $ street = ['street ' ];
211
+
212
+ $ address = $ this ->createMock (QuoteAddress::class);
213
+ $ address ->expects ($ this ->once ())->method ('getCountryId ' )->willReturn ($ countryId );
214
+ $ address ->expects ($ this ->once ())->method ('getRegionId ' )->willReturn ($ regionId );
215
+ $ address ->expects ($ this ->once ())->method ('getRegionCode ' )->willReturn ($ regionCode );
216
+ $ address ->expects ($ this ->once ())->method ('getRegion ' )->willReturn ($ region );
217
+ $ address ->expects ($ this ->once ())->method ('getPostcode ' )->willReturn ($ postCode );
218
+ $ address ->expects ($ this ->once ())->method ('getCity ' )->willReturn ($ city );
219
+ $ address ->expects ($ this ->once ())->method ('getStreet ' )->willReturn ($ street );
220
+
221
+ $ regionData = [
222
+ 'data ' => [
223
+ 'region_id ' => $ regionId ,
224
+ 'region_code ' => $ regionCode ,
225
+ 'region ' => $ region ,
226
+ ]
227
+ ];
228
+ $ regionObject = $ this ->createMock (RegionInterface::class);
229
+ $ this ->regionFactory ->expects ($ this ->once ())->method ('create ' )->with ($ regionData )->willReturn ($ regionObject );
230
+ $ customerAddress = $ this ->createMock (AddressInterface::class);
231
+
232
+ $ this ->addressFactory ->expects ($ this ->once ())
233
+ ->method ('create ' )
234
+ ->with (
235
+ [
236
+ 'data ' => [
237
+ 'country_id ' => $ countryId ,
238
+ 'region ' => $ regionObject ,
239
+ 'postcode ' => $ postCode ,
240
+ 'city ' => $ city ,
241
+ 'street ' => $ street
242
+ ]
243
+ ]
244
+ )
245
+ ->willReturn ($ customerAddress );
246
+
247
+ $ this ->assertSame ($ customerAddress , $ this ->commonTaxCollector ->mapAddress ($ address ));
144
248
}
145
249
146
250
/**
@@ -153,12 +257,13 @@ protected function setUp(): void
153
257
*
154
258
* @return void
155
259
* @dataProvider getShippingDataObjectDataProvider
260
+ * @throws Exception
156
261
*/
157
262
public function testGetShippingDataObject (
158
263
array $ addressData ,
159
- $ useBaseCurrency ,
160
- $ shippingTaxClass ,
161
- $ shippingPriceInclTax
264
+ bool $ useBaseCurrency ,
265
+ string $ shippingTaxClass ,
266
+ bool $ shippingPriceInclTax
162
267
): void {
163
268
$ shippingAssignmentMock = $ this ->getMockForAbstractClass (ShippingAssignmentInterface::class);
164
269
/** @var MockObject|QuoteAddressTotal $totalsMock */
@@ -201,10 +306,8 @@ public function testGetShippingDataObject(
201
306
->expects ($ this ->once ())
202
307
->method ('getBaseShippingDiscountAmount ' )
203
308
->willReturn ($ baseShippingAmount );
204
- $ expectedDiscountAmount = $ baseShippingAmount ;
205
309
} else {
206
310
$ totalsMock ->expects ($ this ->never ())->method ('getBaseShippingDiscountAmount ' );
207
- $ expectedDiscountAmount = $ shippingAmount ;
208
311
}
209
312
}
210
313
foreach ($ addressData as $ key => $ value ) {
@@ -214,10 +317,6 @@ public function testGetShippingDataObject(
214
317
$ this ->quoteDetailsItemDataObject ,
215
318
$ this ->commonTaxCollector ->getShippingDataObject ($ shippingAssignmentMock , $ totalsMock , $ useBaseCurrency )
216
319
);
217
-
218
- if ($ shippingAmount ) {
219
- $ this ->assertEquals ($ expectedDiscountAmount , $ this ->quoteDetailsItemDataObject ->getDiscountAmount ());
220
- }
221
320
}
222
321
223
322
/**
0 commit comments