Skip to content

Commit 34eea6d

Browse files
authored
ENGCOM-4764: magento/graphql-ce#540: Replace deprecated fixture #541
2 parents 0d2b026 + 8786b19 commit 34eea6d

File tree

5 files changed

+194
-41
lines changed

5 files changed

+194
-41
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php

Lines changed: 148 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,86 +7,194 @@
77

88
namespace Magento\GraphQl\Ups;
99

10+
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
11+
use Magento\GraphQl\Quote\GetQuoteShippingAddressIdByReservedQuoteId;
1012
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\Quote\Model\QuoteFactory;
12-
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
13-
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1413
use Magento\TestFramework\Helper\Bootstrap;
1514
use Magento\TestFramework\TestCase\GraphQlAbstract;
1615

1716
/**
18-
* Test for setting "UPS" shipping method on cart
17+
* Test for setting "UPS" shipping method on cart. Current class covers the next UPS shipping methods:
18+
*
19+
* | Code | Label
20+
* --------------------------------------
21+
* | 1DM | Next Day Air Early AM
22+
* | 1DA | Next Day Air
23+
* | 2DA | 2nd Day Air
24+
* | 3DS | 3 Day Select
25+
* | GND | Ground
26+
* | STD | Canada Standard
27+
* | XPR | Worldwide Express
28+
* | WXS | Worldwide Express Saver
29+
* | XDM | Worldwide Express Plus
30+
* | XPD | Worldwide Expedited
31+
*
32+
* Current class does not cover these UPS shipping methods (depends on address and sandbox settings)
33+
*
34+
* | Code | Label
35+
* --------------------------------------
36+
* | 1DML | Next Day Air Early AM Letter
37+
* | 1DAL | Next Day Air Letter
38+
* | 1DAPI | Next Day Air Intra (Puerto Rico)
39+
* | 1DP | Next Day Air Saver
40+
* | 1DPL | Next Day Air Saver Letter
41+
* | 2DM | 2nd Day Air AM
42+
* | 2DML | 2nd Day Air AM Letter
43+
* | 2DAL | 2nd Day Air Letter
44+
* | GNDCOM | Ground Commercial
45+
* | GNDRES | Ground Residential
46+
* | XPRL | Worldwide Express Letter
47+
* | XDML | Worldwide Express Plus Letter
1948
*/
2049
class SetUpsShippingMethodsOnCartTest extends GraphQlAbstract
2150
{
2251
/**
23-
* Defines carrier code for "UPS" shipping method
24-
*/
25-
const CARRIER_CODE = 'ups';
26-
27-
/**
28-
* Defines method code for the "Ground" UPS shipping
52+
* Defines carrier label for "UPS" shipping method
2953
*/
30-
const CARRIER_METHOD_CODE_GROUND = 'GND';
54+
const CARRIER_LABEL = 'United Parcel Service';
3155

3256
/**
33-
* @var QuoteFactory
57+
* Defines carrier code for "UPS" shipping method
3458
*/
35-
private $quoteFactory;
59+
const CARRIER_CODE = 'ups';
3660

3761
/**
3862
* @var CustomerTokenServiceInterface
3963
*/
4064
private $customerTokenService;
4165

4266
/**
43-
* @var QuoteResource
67+
* @var GetMaskedQuoteIdByReservedOrderId
4468
*/
45-
private $quoteResource;
69+
private $getMaskedQuoteIdByReservedOrderId;
4670

4771
/**
48-
* @var QuoteIdToMaskedQuoteIdInterface
72+
* @var GetQuoteShippingAddressIdByReservedQuoteId
4973
*/
50-
private $quoteIdToMaskedId;
74+
private $getQuoteShippingAddressIdByReservedQuoteId;
5175

5276
/**
5377
* @inheritdoc
5478
*/
5579
protected function setUp()
5680
{
5781
$objectManager = Bootstrap::getObjectManager();
58-
$this->quoteResource = $objectManager->get(QuoteResource::class);
59-
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
60-
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
6182
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
83+
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
84+
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(
85+
GetQuoteShippingAddressIdByReservedQuoteId::class
86+
);
6287
}
6388

6489
/**
65-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
66-
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
90+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
91+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
92+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
93+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
94+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
95+
* @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
96+
*
97+
* @dataProvider dataProviderShippingMethods
98+
* @param string $methodCode
99+
* @param string $methodLabel
67100
*/
68-
public function testSetUpsShippingMethod()
101+
public function testSetUpsShippingMethod(string $methodCode, string $methodLabel)
69102
{
70-
$quote = $this->quoteFactory->create();
71-
$this->quoteResource->load($quote, 'test_order_1', 'reserved_order_id');
72-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
73-
$shippingAddressId = (int)$quote->getShippingAddress()->getId();
74-
75-
$query = $this->getAddUpsShippingMethodQuery(
76-
$maskedQuoteId,
77-
$shippingAddressId,
78-
self::CARRIER_CODE,
79-
self::CARRIER_METHOD_CODE_GROUND
103+
$quoteReservedId = 'test_quote';
104+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
105+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
106+
107+
$query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode);
108+
$response = $this->sendRequestWithToken($query);
109+
110+
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
111+
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
112+
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
113+
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
114+
115+
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
116+
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
117+
118+
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
119+
self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']);
120+
121+
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
122+
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);
123+
124+
self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']);
125+
self::assertEquals(
126+
self::CARRIER_LABEL . ' - ' . $methodLabel,
127+
$shippingAddress['selected_shipping_method']['label']
80128
);
129+
}
81130

131+
/**
132+
* @return array
133+
*/
134+
public function dataProviderShippingMethods(): array
135+
{
136+
return [
137+
'Next Day Air Early AM' => ['1DM', 'Next Day Air Early AM'],
138+
'Next Day Air' => ['1DA', 'Next Day Air'],
139+
'2nd Day Air' => ['2DA', '2nd Day Air'],
140+
'3 Day Select' => ['3DS', '3 Day Select'],
141+
'Ground' => ['GND', 'Ground'],
142+
];
143+
}
144+
145+
/**
146+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
147+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
148+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
149+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
150+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_canada_address.php
151+
* @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
152+
*
153+
* @dataProvider dataProviderShippingMethodsBasedOnCanadaAddress
154+
* @param string $methodCode
155+
* @param string $methodLabel
156+
*/
157+
public function testSetUpsShippingMethodBasedOnCanadaAddress(string $methodCode, string $methodLabel)
158+
{
159+
$quoteReservedId = 'test_quote';
160+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
161+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
162+
163+
$query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode);
82164
$response = $this->sendRequestWithToken($query);
83-
$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
84-
$expectedResult = [
85-
'carrier_code' => self::CARRIER_CODE,
86-
'method_code' => self::CARRIER_METHOD_CODE_GROUND,
87-
'label' => 'United Parcel Service - Ground',
165+
166+
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
167+
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
168+
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
169+
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
170+
171+
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
172+
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
173+
174+
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
175+
self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']);
176+
177+
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
178+
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);
179+
180+
self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']);
181+
self::assertEquals(
182+
self::CARRIER_LABEL . ' - ' . $methodLabel,
183+
$shippingAddress['selected_shipping_method']['label']
184+
);
185+
}
186+
187+
/**
188+
* @return array
189+
*/
190+
public function dataProviderShippingMethodsBasedOnCanadaAddress(): array
191+
{
192+
return [
193+
'Canada Standard' => ['STD', 'Canada Standard'],
194+
'Worldwide Express' => ['XPR', 'Worldwide Express'],
195+
'Worldwide Express Saver' => ['WXS', 'Worldwide Express Saver'],
196+
'Worldwide Express Plus' => ['XDM', 'Worldwide Express Plus'],
88197
];
89-
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
90198
}
91199

92200
/**
@@ -98,7 +206,7 @@ public function testSetUpsShippingMethod()
98206
* @param string $methodCode
99207
* @return string
100208
*/
101-
private function getAddUpsShippingMethodQuery(
209+
private function getQuery(
102210
string $maskedQuoteId,
103211
int $shippingAddressId,
104212
string $carrierCode,

dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/set_new_shipping_address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
$quoteAddressData = [
2828
AddressInterface::KEY_TELEPHONE => 3468676,
29-
AddressInterface::KEY_POSTCODE => 75477,
29+
AddressInterface::KEY_POSTCODE => '75477',
3030
AddressInterface::KEY_COUNTRY_ID => 'US',
3131
AddressInterface::KEY_CITY => 'CityM',
3232
AddressInterface::KEY_COMPANY => 'CompanyName',
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Api\DataObjectHelper;
9+
use Magento\Quote\Api\Data\AddressInterface;
10+
use Magento\Quote\Api\Data\AddressInterfaceFactory;
11+
use Magento\Quote\Model\QuoteFactory;
12+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
13+
use Magento\Quote\Model\ShippingAddressManagementInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
16+
/** @var QuoteFactory $quoteFactory */
17+
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
18+
/** @var QuoteResource $quoteResource */
19+
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
20+
/** @var AddressInterfaceFactory $quoteAddressFactory */
21+
$quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressInterfaceFactory::class);
22+
/** @var DataObjectHelper $dataObjectHelper */
23+
$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
24+
/** @var ShippingAddressManagementInterface $shippingAddressManagement */
25+
$shippingAddressManagement = Bootstrap::getObjectManager()->get(ShippingAddressManagementInterface::class);
26+
27+
$quoteAddressData = [
28+
AddressInterface::KEY_TELEPHONE => 3468676,
29+
AddressInterface::KEY_POSTCODE => 'M4L 1V3',
30+
AddressInterface::KEY_COUNTRY_ID => 'CA',
31+
AddressInterface::KEY_CITY => 'Toronto',
32+
AddressInterface::KEY_COMPANY => 'CompanyName',
33+
AddressInterface::KEY_STREET => '500 Kingston Rd',
34+
AddressInterface::KEY_LASTNAME => 'Smith',
35+
AddressInterface::KEY_FIRSTNAME => 'John',
36+
AddressInterface::KEY_REGION_CODE => 'ON',
37+
];
38+
$quoteAddress = $quoteAddressFactory->create();
39+
$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class);
40+
41+
$quote = $quoteFactory->create();
42+
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
43+
$shippingAddressManagement->assign($quote->getId(), $quoteAddress);

dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method.php renamed to dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167
67
declare(strict_types=1);
78

89
use Magento\Framework\App\Config\Storage\Writer;

dev/tests/integration/testsuite/Magento/Ups/_files/enable_ups_shipping_method_rollback.php renamed to dev/tests/integration/testsuite/Magento/GraphQl/Ups/_files/enable_ups_shipping_method_rollback.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167
67
declare(strict_types=1);
78

89
use Magento\Framework\App\Config\Storage\Writer;

0 commit comments

Comments
 (0)