3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
namespace Magento \Quote \Model ;
8
7
9
8
use Magento \Customer \Api \AddressRepositoryInterface ;
14
13
use Magento \Customer \Model \Vat ;
15
14
use Magento \Framework \Api \SearchCriteriaBuilder ;
16
15
use Magento \Framework \App \Config \MutableScopeConfigInterface ;
16
+ use Magento \Framework \Exception \NoSuchEntityException ;
17
17
use Magento \Framework \ObjectManagerInterface ;
18
18
use Magento \Quote \Api \CartRepositoryInterface ;
19
+ use Magento \Quote \Api \Data \AddressInterfaceFactory ;
20
+ use Magento \Quote \Api \Data \EstimateAddressInterface ;
21
+ use Magento \Quote \Api \GuestShippingMethodManagementInterface ;
19
22
use Magento \Quote \Api \ShippingMethodManagementInterface ;
20
23
use Magento \Store \Model \ScopeInterface ;
21
24
use Magento \Tax \Api \Data \TaxClassInterface ;
24
27
use Magento \Tax \Model \Config as TaxConfig ;
25
28
use Magento \TestFramework \Helper \Bootstrap ;
26
29
use Magento \TestFramework \Quote \Model \GetQuoteByReservedOrderId ;
30
+ use PHPUnit \Framework \TestCase ;
27
31
28
32
/**
29
33
* Test for shipping methods management
30
34
*
31
35
* @magentoDbIsolation enabled
32
36
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
33
37
*/
34
- class ShippingMethodManagementTest extends \ PHPUnit \ Framework \ TestCase
38
+ class ShippingMethodManagementTest extends TestCase
35
39
{
36
40
/** @var ObjectManagerInterface $objectManager */
37
41
private $ objectManager ;
@@ -56,14 +60,14 @@ protected function setUp()
56
60
* @magentoDataFixture Magento/SalesRule/_files/cart_rule_100_percent_off.php
57
61
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
58
62
* @return void
59
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
63
+ * @throws NoSuchEntityException
60
64
*/
61
65
public function testRateAppliedToShipping (): void
62
66
{
63
- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
67
+ $ objectManager = Bootstrap::getObjectManager ();
64
68
65
- /** @var \Magento\Quote\Api\ CartRepositoryInterface $quoteRepository */
66
- $ quoteRepository = $ objectManager ->create (\ Magento \ Quote \ Api \ CartRepositoryInterface::class);
69
+ /** @var CartRepositoryInterface $quoteRepository */
70
+ $ quoteRepository = $ objectManager ->create (CartRepositoryInterface::class);
67
71
$ customerQuote = $ quoteRepository ->getForCustomer (1 );
68
72
$ this ->assertEquals (0 , $ customerQuote ->getBaseGrandTotal ());
69
73
}
@@ -80,17 +84,17 @@ public function testRateAppliedToShipping(): void
80
84
*/
81
85
public function testTableRateFreeShipping ()
82
86
{
83
- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
84
- /** @var \Magento\Quote\Model\ Quote $quote */
85
- $ quote = $ objectManager ->get (\ Magento \ Quote \ Model \ Quote::class);
87
+ $ objectManager = Bootstrap::getObjectManager ();
88
+ /** @var Quote $quote */
89
+ $ quote = $ objectManager ->get (Quote::class);
86
90
$ quote ->load ('test01 ' , 'reserved_order_id ' );
87
91
$ cartId = $ quote ->getId ();
88
92
if (!$ cartId ) {
89
93
$ this ->fail ('quote fixture failed ' );
90
94
}
91
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
92
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
93
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
95
+ /** @var QuoteIdMask $quoteIdMask */
96
+ $ quoteIdMask = Bootstrap::getObjectManager ()
97
+ ->create (QuoteIdMaskFactory::class)
94
98
->create ();
95
99
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
96
100
//Use masked cart Id
@@ -103,10 +107,10 @@ public function testTableRateFreeShipping()
103
107
'region_id ' => null
104
108
]
105
109
];
106
- /** @var \Magento\Quote\Api\Data\ EstimateAddressInterface $address */
107
- $ address = $ objectManager ->create (\ Magento \ Quote \ Api \ Data \ EstimateAddressInterface::class, $ data );
108
- /** @var \Magento\Quote\Api\ GuestShippingMethodManagementInterface $shippingEstimation */
109
- $ shippingEstimation = $ objectManager ->get (\ Magento \ Quote \ Api \ GuestShippingMethodManagementInterface::class);
110
+ /** @var EstimateAddressInterface $address */
111
+ $ address = $ objectManager ->create (EstimateAddressInterface::class, $ data );
112
+ /** @var GuestShippingMethodManagementInterface $shippingEstimation */
113
+ $ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
110
114
$ result = $ shippingEstimation ->estimateByAddress ($ cartId , $ address );
111
115
$ this ->assertNotEmpty ($ result );
112
116
$ expectedResult = [
@@ -134,25 +138,25 @@ public function testTableRateFreeShipping()
134
138
*/
135
139
public function testTableRateWithCartRuleForFreeShipping ()
136
140
{
137
- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
141
+ $ objectManager = Bootstrap::getObjectManager ();
138
142
$ quote = $ this ->getQuote ('tableRate ' );
139
143
$ cartId = $ quote ->getId ();
140
144
if (!$ cartId ) {
141
145
$ this ->fail ('quote fixture failed ' );
142
146
}
143
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
144
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
145
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
147
+ /** @var QuoteIdMask $quoteIdMask */
148
+ $ quoteIdMask = Bootstrap::getObjectManager ()
149
+ ->create (QuoteIdMaskFactory::class)
146
150
->create ();
147
151
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
148
152
//Use masked cart Id
149
153
$ cartId = $ quoteIdMask ->getMaskedId ();
150
- $ addressFactory = $ this ->objectManager ->get (\ Magento \ Quote \ Api \ Data \ AddressInterfaceFactory::class);
154
+ $ addressFactory = $ this ->objectManager ->get (AddressInterfaceFactory::class);
151
155
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
152
156
$ address = $ addressFactory ->create ();
153
157
$ address ->setCountryId ('US ' );
154
- /** @var \Magento\Quote\Api\ GuestShippingMethodManagementInterface $shippingEstimation */
155
- $ shippingEstimation = $ objectManager ->get (\ Magento \ Quote \ Api \ GuestShippingMethodManagementInterface::class);
158
+ /** @var GuestShippingMethodManagementInterface $shippingEstimation */
159
+ $ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
156
160
$ result = $ shippingEstimation ->estimateByExtendedAddress ($ cartId , $ address );
157
161
$ this ->assertCount (1 , $ result );
158
162
$ rate = reset ($ result );
@@ -234,17 +238,17 @@ public function testEstimateByAddress()
234
238
*/
235
239
private function executeTestFlow ($ flatRateAmount , $ tableRateAmount )
236
240
{
237
- $ objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
238
- /** @var \Magento\Quote\Model\ Quote $quote */
239
- $ quote = $ objectManager ->get (\ Magento \ Quote \ Model \ Quote::class);
241
+ $ objectManager = Bootstrap::getObjectManager ();
242
+ /** @var Quote $quote */
243
+ $ quote = $ objectManager ->get (Quote::class);
240
244
$ quote ->load ('test01 ' , 'reserved_order_id ' );
241
245
$ cartId = $ quote ->getId ();
242
246
if (!$ cartId ) {
243
247
$ this ->fail ('quote fixture failed ' );
244
248
}
245
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
246
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
247
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
249
+ /** @var QuoteIdMask $quoteIdMask */
250
+ $ quoteIdMask = Bootstrap::getObjectManager ()
251
+ ->create (QuoteIdMaskFactory::class)
248
252
->create ();
249
253
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
250
254
//Use masked cart Id
@@ -257,17 +261,17 @@ private function executeTestFlow($flatRateAmount, $tableRateAmount)
257
261
'region_id ' => null
258
262
]
259
263
];
260
- /** @var \Magento\Quote\Api\Data\ EstimateAddressInterface $address */
261
- $ address = $ objectManager ->create (\ Magento \ Quote \ Api \ Data \ EstimateAddressInterface::class, $ data );
262
- /** @var \Magento\Quote\Api\ GuestShippingMethodManagementInterface $shippingEstimation */
263
- $ shippingEstimation = $ objectManager ->get (\ Magento \ Quote \ Api \ GuestShippingMethodManagementInterface::class);
264
+ /** @var EstimateAddressInterface $address */
265
+ $ address = $ objectManager ->create (EstimateAddressInterface::class, $ data );
266
+ /** @var GuestShippingMethodManagementInterface $shippingEstimation */
267
+ $ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
264
268
$ result = $ shippingEstimation ->estimateByAddress ($ cartId , $ address );
265
269
$ this ->assertNotEmpty ($ result );
266
270
$ expectedResult = [
267
271
'tablerate ' => [
268
- 'method_code ' => 'bestway ' ,
269
- 'amount ' => $ tableRateAmount
270
- ],
272
+ 'method_code ' => 'bestway ' ,
273
+ 'amount ' => $ tableRateAmount
274
+ ],
271
275
'flatrate ' => [
272
276
'method_code ' => 'flatrate ' ,
273
277
'amount ' => $ flatRateAmount
@@ -295,8 +299,6 @@ private function executeTestFlow($flatRateAmount, $tableRateAmount)
295
299
*/
296
300
public function testEstimateByAddressWithInclExclTaxAndVATGroup ()
297
301
{
298
- $ this ->markTestSkipped ('MC-33463 ' );
299
-
300
302
/** @var CustomerRepositoryInterface $customerRepository */
301
303
$ customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
302
304
$ customer =
$ customerRepository->
get (
'[email protected] ' );
@@ -395,6 +397,11 @@ private function setConfig(int $customerGroupId, int $productTaxClassId): void
395
397
'value ' => $ customerGroupId ,
396
398
'scope ' => ScopeInterface::SCOPE_STORE ,
397
399
],
400
+ [
401
+ 'path ' => Vat::XML_PATH_CUSTOMER_VIV_ERROR_GROUP ,
402
+ 'value ' => $ customerGroupId ,
403
+ 'scope ' => ScopeInterface::SCOPE_STORE ,
404
+ ],
398
405
[
399
406
'path ' => TaxConfig::CONFIG_XML_PATH_SHIPPING_TAX_CLASS ,
400
407
'value ' => $ productTaxClassId ,
0 commit comments