forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-4486: 419 test coverage get available payment methods customer m…
…agento#451 - Merge Pull Request magento/graphql-ce#451 from magento/graphql-ce:419-test-coverage-getAvailablePaymentMethods-customer - Merged commits: 1. 44e24e3 2. 8786fbf 3. 1356caa 4. b8006ee 5. 31166c9
- Loading branch information
Showing
6 changed files
with
152 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,86 @@ protected function setUp() | |
*/ | ||
public function testGetCartWithPaymentMethods() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items'); | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); | ||
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); | ||
self::assertGreaterThan( | ||
0, | ||
count($response['cart']['available_payment_methods']), | ||
'There are no available payment methods for customer cart!' | ||
); | ||
} | ||
|
||
$query = <<<QUERY | ||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php | ||
*/ | ||
public function testGetPaymentMethodsFromGuestCart() | ||
{ | ||
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId( | ||
'test_order_with_virtual_product_without_address' | ||
); | ||
$query = $this->getQuery($guestQuoteMaskedId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$guestQuoteMaskedId\"" | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php | ||
*/ | ||
public function testGetPaymentMethodsFromAnotherCustomerCart() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->expectExceptionMessage( | ||
"The current user cannot perform operations on cart \"$maskedQuoteId\"" | ||
); | ||
$this->graphQlQuery($query, [], '', $this->getHeaderMap('[email protected]')); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php | ||
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php | ||
*/ | ||
public function testGetPaymentMethodsIfPaymentsAreNotSet() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items'); | ||
$query = $this->getQuery($maskedQuoteId); | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertEquals(0, count($response['cart']['available_payment_methods'])); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @expectedException \Exception | ||
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id" | ||
*/ | ||
public function testGetPaymentMethodsOfNonExistentCart() | ||
{ | ||
$maskedQuoteId = 'non_existent_masked_id'; | ||
$query = $this->getQuery($maskedQuoteId); | ||
|
||
$this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @return string | ||
*/ | ||
private function getQuery( | ||
string $maskedQuoteId | ||
): string { | ||
return <<<QUERY | ||
{ | ||
cart(cart_id: "$maskedQuoteId") { | ||
available_payment_methods { | ||
|
@@ -68,11 +145,6 @@ public function testGetCartWithPaymentMethods() | |
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('cart', $response); | ||
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']); | ||
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']); | ||
} | ||
|
||
/** | ||
|
@@ -88,13 +160,13 @@ private function getHeaderMap(string $username = '[email protected]', string | |
} | ||
|
||
/** | ||
* @param string $reversedQuoteId | ||
* @param string $reservedOrderId | ||
* @return string | ||
*/ | ||
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string | ||
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string | ||
{ | ||
$quote = $this->quoteFactory->create(); | ||
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id'); | ||
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id'); | ||
|
||
return $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Config\Model\Config; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\Store; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
$paymentMethodList = $objectManager->get(\Magento\Payment\Api\PaymentMethodListInterface::class); | ||
$rollbackConfigKey = 'test/payment/disabled_payment_methods'; | ||
$configData = []; | ||
$disabledPaymentMethods = []; | ||
|
||
// Get all active Payment Methods | ||
foreach ($paymentMethodList->getActiveList(Store::DEFAULT_STORE_ID) as $paymentMethod) { | ||
$configData['payment/' . $paymentMethod->getCode() . '/active'] = 0; | ||
$disabledPaymentMethods[] = $paymentMethod->getCode(); | ||
} | ||
// Remember all manually disabled Payment Methods for rollback | ||
$configData[$rollbackConfigKey] = implode(',', $disabledPaymentMethods); | ||
|
||
/** @var Config $defConfig */ | ||
$defConfig = $objectManager->create(Config::class); | ||
$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT); | ||
|
||
foreach ($configData as $key => $value) { | ||
$defConfig->setDataByPath($key, $value); | ||
$defConfig->save(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...egration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Config\Storage\WriterInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
$rollbackConfigKey = 'test/payment/disabled_payment_methods'; | ||
|
||
$configWriter = $objectManager->create(WriterInterface::class); | ||
$rollbackConfigValue = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class) | ||
->getStore(\Magento\Store\Model\Store::DEFAULT_STORE_ID) | ||
->getConfig($rollbackConfigKey); | ||
|
||
$disabledPaymentMethods = []; | ||
if (!empty($rollbackConfigValue)) { | ||
$disabledPaymentMethods = explode(',', $rollbackConfigValue); | ||
} | ||
|
||
if (count($disabledPaymentMethods)) { | ||
foreach ($disabledPaymentMethods as $keyToRemove) { | ||
$configWriter->delete(sprintf('payment/%s/active', $keyToRemove)); | ||
} | ||
} | ||
$configWriter->delete($rollbackConfigKey); | ||
|
||
$scopeConfig = $objectManager->get(ScopeConfigInterface::class); | ||
$scopeConfig->clean(); |