Skip to content

Commit

Permalink
magento/graphql-ce#540: Replace deprecated fixture
Browse files Browse the repository at this point in the history
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
  • Loading branch information
atwixfirster committed Apr 13, 2019
2 parents 78f02fa + b946dd0 commit b027198
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,47 @@ protected function setUp()
$this->getQuoteShippingAddressIdByReservedQuoteId = $objectManager->get(GetQuoteShippingAddressIdByReservedQuoteId::class);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Ups/_files/enable_ups_shipping_method.php
*
* @param string $methodCode
* @param string $methodLabel
* @dataProvider availableForCartShippingMethods
*/
public function testSetAvailableUpsShippingMethodOnCart(string $methodCode, string $methodLabel)
{
$quoteReservedId = 'test_quote';
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);

$query = $this->getQuery($maskedQuoteId, $shippingAddressId, self::CARRIER_CODE, $methodCode);
$response = $this->graphQlQuery($query);

self::assertArrayHasKey('setShippingMethodsOnCart', $response);
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);

$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);

self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
self::assertEquals(self::CARRIER_CODE, $shippingAddress['selected_shipping_method']['carrier_code']);

self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);

self::assertArrayHasKey('label', $shippingAddress['selected_shipping_method']);
self::assertEquals(
self::CARRIER_LABEL . ' - ' . $methodLabel,
$shippingAddress['selected_shipping_method']['label']
);
}

/**
* Set "Next Day Air Early AM" UPS shipping method
*
Expand Down Expand Up @@ -239,9 +280,55 @@ public function testSetGroundUpsShippingMethod()
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/Ups/_files/enable_ups_shipping_method.php
*
* @param string $carrierMethodCode
* @param string $carrierMethodLabel
* @dataProvider notAvailableForCartShippingMethods
*/
public function testSetNotAvailableForCartUpsShippingMethod(string $carrierMethodCode, string $carrierMethodLabel)
{
$quoteReservedId = 'test_quote';
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($quoteReservedId);
$shippingAddressId = $this->getQuoteShippingAddressIdByReservedQuoteId->execute($quoteReservedId);

$query = $this->getQuery(
$maskedQuoteId,
$shippingAddressId,
self::CARRIER_CODE,
$carrierMethodCode
);

$this->expectExceptionMessage(
"GraphQL response contains errors: Carrier with such method not found: " . self::CARRIER_CODE . ", " . $carrierMethodCode
);

$response = $this->sendRequestWithToken($query);

$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses'];
$expectedResult = [
'carrier_code' => self::CARRIER_CODE,
'method_code' => $carrierMethodCode,
'label' => self::CARRIER_LABEL . ' - ' . $carrierMethodLabel,
];
self::assertEquals($addressesInformation[0]['selected_shipping_method'], $expectedResult);
}

/**
* @return array
*/
public function availableForCartShippingMethods(): array
{
$shippingMethods = ['1DM', '1DA', '2DA', '3DS', 'GND'];

return $this->filterShippingMethodsByCodes($shippingMethods);
}

/**
* @return array
Expand All @@ -253,6 +340,21 @@ public function notAvailableForCartShippingMethods(): array
return $this->filterShippingMethodsByCodes($shippingMethods);
}

/**
* @param array $filter
* @return array
*/
private function filterShippingMethodsByCodes(array $filter):array
{
$result = [];
foreach ($this->getAllUpsShippingMethods() as $shippingMethod) {
if (in_array($shippingMethod[0], $filter)) {
$result[] = $shippingMethod;
}
}
return $result;
}

private function getAllUpsShippingMethods():array
{
return [
Expand Down Expand Up @@ -334,6 +436,6 @@ private function sendRequestWithToken(string $query): array
$customerToken = $this->customerTokenService->createCustomerAccessToken('[email protected]', 'password');
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];

return $this->graphQlMutation($query, [], '', $headerMap);
return $this->graphQlQuery($query, [], '', $headerMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167
declare(strict_types=1);

use Magento\Framework\App\Config\Storage\Writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167
declare(strict_types=1);

use Magento\Framework\App\Config\Storage\Writer;
Expand Down

0 comments on commit b027198

Please sign in to comment.