Skip to content

Commit 93f57b9

Browse files
ENGCOM-4486: 419 test coverage get available payment methods customer #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
2 parents 9d231d1 + 31166c9 commit 93f57b9

File tree

6 files changed

+152
-13
lines changed

6 files changed

+152
-13
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,86 @@ protected function setUp()
5656
*/
5757
public function testGetCartWithPaymentMethods()
5858
{
59-
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_item_with_items');
59+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
60+
$query = $this->getQuery($maskedQuoteId);
61+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
62+
63+
self::assertArrayHasKey('cart', $response);
64+
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']);
65+
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']);
66+
self::assertGreaterThan(
67+
0,
68+
count($response['cart']['available_payment_methods']),
69+
'There are no available payment methods for customer cart!'
70+
);
71+
}
6072

61-
$query = <<<QUERY
73+
/**
74+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
75+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
76+
*/
77+
public function testGetPaymentMethodsFromGuestCart()
78+
{
79+
$guestQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId(
80+
'test_order_with_virtual_product_without_address'
81+
);
82+
$query = $this->getQuery($guestQuoteMaskedId);
83+
84+
$this->expectExceptionMessage(
85+
"The current user cannot perform operations on cart \"$guestQuoteMaskedId\""
86+
);
87+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
88+
}
89+
90+
/**
91+
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
92+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
93+
*/
94+
public function testGetPaymentMethodsFromAnotherCustomerCart()
95+
{
96+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
97+
$query = $this->getQuery($maskedQuoteId);
98+
99+
$this->expectExceptionMessage(
100+
"The current user cannot perform operations on cart \"$maskedQuoteId\""
101+
);
102+
$this->graphQlQuery($query, [], '', $this->getHeaderMap('customer3@search.example.com'));
103+
}
104+
105+
/**
106+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
107+
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
108+
*/
109+
public function testGetPaymentMethodsIfPaymentsAreNotSet()
110+
{
111+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_item_with_items');
112+
$query = $this->getQuery($maskedQuoteId);
113+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
114+
115+
self::assertEquals(0, count($response['cart']['available_payment_methods']));
116+
}
117+
118+
/**
119+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
120+
* @expectedException \Exception
121+
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
122+
*/
123+
public function testGetPaymentMethodsOfNonExistentCart()
124+
{
125+
$maskedQuoteId = 'non_existent_masked_id';
126+
$query = $this->getQuery($maskedQuoteId);
127+
128+
$this->graphQlQuery($query, [], '', $this->getHeaderMap());
129+
}
130+
131+
/**
132+
* @param string $maskedQuoteId
133+
* @return string
134+
*/
135+
private function getQuery(
136+
string $maskedQuoteId
137+
): string {
138+
return <<<QUERY
62139
{
63140
cart(cart_id: "$maskedQuoteId") {
64141
available_payment_methods {
@@ -68,11 +145,6 @@ public function testGetCartWithPaymentMethods()
68145
}
69146
}
70147
QUERY;
71-
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
72-
73-
self::assertArrayHasKey('cart', $response);
74-
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']);
75-
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']);
76148
}
77149

78150
/**
@@ -88,13 +160,13 @@ private function getHeaderMap(string $username = 'customer@example.com', string
88160
}
89161

90162
/**
91-
* @param string $reversedQuoteId
163+
* @param string $reservedOrderId
92164
* @return string
93165
*/
94-
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string
166+
private function getMaskedQuoteIdByReservedOrderId(string $reservedOrderId): string
95167
{
96168
$quote = $this->quoteFactory->create();
97-
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
169+
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
98170

99171
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
100172
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetCartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function testGetCart()
7272
}
7373

7474
/**
75-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
7675
* @magentoApiDataFixture Magento/Customer/_files/customer.php
76+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
7777
*/
7878
public function testGetGuestCart()
7979
{

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testRemoveItemIfItemIsNotBelongToCart()
129129
}
130130

131131
/**
132-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
132+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
133133
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
134134
*/
135135
public function testRemoveItemFromGuestCart()

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/UpdateCartItemsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testUpdateItemIfItemIsNotBelongToCart()
156156
}
157157

158158
/**
159-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
159+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
160160
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
161161
*/
162162
public function testUpdateItemInGuestCart()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Config\Model\Config;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Store\Model\Store;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
$paymentMethodList = $objectManager->get(\Magento\Payment\Api\PaymentMethodListInterface::class);
15+
$rollbackConfigKey = 'test/payment/disabled_payment_methods';
16+
$configData = [];
17+
$disabledPaymentMethods = [];
18+
19+
// Get all active Payment Methods
20+
foreach ($paymentMethodList->getActiveList(Store::DEFAULT_STORE_ID) as $paymentMethod) {
21+
$configData['payment/' . $paymentMethod->getCode() . '/active'] = 0;
22+
$disabledPaymentMethods[] = $paymentMethod->getCode();
23+
}
24+
// Remember all manually disabled Payment Methods for rollback
25+
$configData[$rollbackConfigKey] = implode(',', $disabledPaymentMethods);
26+
27+
/** @var Config $defConfig */
28+
$defConfig = $objectManager->create(Config::class);
29+
$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
30+
31+
foreach ($configData as $key => $value) {
32+
$defConfig->setDataByPath($key, $value);
33+
$defConfig->save();
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\App\Config\Storage\WriterInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
$objectManager = Bootstrap::getObjectManager();
13+
$rollbackConfigKey = 'test/payment/disabled_payment_methods';
14+
15+
$configWriter = $objectManager->create(WriterInterface::class);
16+
$rollbackConfigValue = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
17+
->getStore(\Magento\Store\Model\Store::DEFAULT_STORE_ID)
18+
->getConfig($rollbackConfigKey);
19+
20+
$disabledPaymentMethods = [];
21+
if (!empty($rollbackConfigValue)) {
22+
$disabledPaymentMethods = explode(',', $rollbackConfigValue);
23+
}
24+
25+
if (count($disabledPaymentMethods)) {
26+
foreach ($disabledPaymentMethods as $keyToRemove) {
27+
$configWriter->delete(sprintf('payment/%s/active', $keyToRemove));
28+
}
29+
}
30+
$configWriter->delete($rollbackConfigKey);
31+
32+
$scopeConfig = $objectManager->get(ScopeConfigInterface::class);
33+
$scopeConfig->clean();

0 commit comments

Comments
 (0)