Skip to content

Commit b027198

Browse files
committed
magento/graphql-ce#540: Replace deprecated fixture
Merge branch '540-new-fixture-for-SetUpsShippingMethodsOnCartTest' of https://github.com/magento/graphql-ce into 540-new-fixture-for-SetUpsShippingMethodsOnCartTest # Conflicts: # dev/tests/api-functional/testsuite/Magento/GraphQl/Ups/SetUpsShippingMethodsOnCartTest.php
2 parents 78f02fa + b946dd0 commit b027198

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

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

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,47 @@ protected function setUp()
5454
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(GetQuoteShippingAddressIdByReservedQuoteId::class);
5555
}
5656

57+
/**
58+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
59+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
60+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
61+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
62+
* @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
63+
*
64+
* @param string $methodCode
65+
* @param string $methodLabel
66+
* @dataProvider availableForCartShippingMethods
67+
*/
68+
public function testSetAvailableUpsShippingMethodOnCart(string $methodCode, string $methodLabel)
69+
{
70+
$quoteReservedId = 'test_quote';
71+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
72+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
73+
74+
$query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode);
75+
$response = $this->graphQlQuery($query);
76+
77+
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
78+
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
79+
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
80+
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
81+
82+
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
83+
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
84+
85+
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
86+
self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']);
87+
88+
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
89+
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);
90+
91+
self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']);
92+
self::assertEquals(
93+
self::CARRIER_LABEL . ' - ' . $methodLabel,
94+
$shippingAddress['selected_shipping_method']['label']
95+
);
96+
}
97+
5798
/**
5899
* Set "Next Day Air Early AM" UPS shipping method
59100
*
@@ -239,9 +280,55 @@ public function testSetGroundUpsShippingMethod()
239280
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
240281
}
241282

283+
/**
284+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
285+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
286+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
287+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
288+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
289+
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
290+
*
291+
* @param string $carrierMethodCode
292+
* @param string $carrierMethodLabel
293+
* @dataProvider notAvailableForCartShippingMethods
294+
*/
295+
public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel)
296+
{
297+
$quoteReservedId = 'test_quote';
298+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
299+
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);
300+
301+
$query = $this->getQuery(
302+
$maskedQuoteId,
303+
$shippingAddressId,
304+
self::CARRIER_CODE,
305+
$carrierMethodCode
306+
);
307+
308+
$this->expectExceptionMessage(
309+
"GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode
310+
);
311+
312+
$response = $this->sendRequestWithToken($query);
242313

314+
$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
315+
$expectedResult = [
316+
'carrier_code' => self::CARRIER_CODE,
317+
'method_code' => $carrierMethodCode,
318+
'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel,
319+
];
320+
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
321+
}
243322

323+
/**
324+
* @return array
325+
*/
326+
public function availableForCartShippingMethods(): array
327+
{
328+
$shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND'];
244329

330+
return $this->filterShippingMethodsByCodes($shippingMethods);
331+
}
245332

246333
/**
247334
* @return array
@@ -253,6 +340,21 @@ public function notAvailableForCartShippingMethods(): array
253340
return $this->filterShippingMethodsByCodes($shippingMethods);
254341
}
255342

343+
/**
344+
* @param array $filter
345+
* @return array
346+
*/
347+
private function filterShippingMethodsByCodes(array $filter):array
348+
{
349+
$result = [];
350+
foreach ($this->getAllUpsShippingMethods() as $shippingMethod) {
351+
if (in_array($shippingMethod[0], $filter)) {
352+
$result[] = $shippingMethod;
353+
}
354+
}
355+
return $result;
356+
}
357+
256358
private function getAllUpsShippingMethods():array
257359
{
258360
return [
@@ -334,6 +436,6 @@ private function sendRequestWithToken(string $query): array
334436
$customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password');
335437
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
336438

337-
return $this->graphQlMutation($query, [], '', $headerMap);
439+
return $this->graphQlQuery($query, [], '', $headerMap);
338440
}
339441
}

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)