Skip to content

Commit 9395e76

Browse files
committed
420 - Test coverage: GetAvailablePaymentMethodsTest for Guest
1. Add Magento/Payment/_files/disable_all_active_payment_methods.php
1 parent 9b2be29 commit 9395e76

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testGetPaymentMethodsFromAnotherCustomerCart()
8686

8787
/**
8888
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
89-
* @magentoApiDataFixture Magento/Payment/_files/disable_all_payment_methods.php
89+
* @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
9090
*/
9191
public function testGetPaymentMethodsIfPaymentsAreNotSet()
9292
{
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\TestFramework\Helper\Bootstrap;
11+
12+
$processConfigData = function (Config $config, array $data) {
13+
foreach ($data as $key => $value) {
14+
$config->setDataByPath($key, $value);
15+
$config->save();
16+
}
17+
};
18+
19+
$objectManager = Bootstrap::getObjectManager();
20+
$paymentMethodList = $objectManager->get(\Magento\Payment\Api\PaymentMethodListInterface::class);
21+
$rollbackConfigKey = 'test/payment/disabled_payment_methods';
22+
$configData = [];
23+
$disabledPaymentMethods = [];
24+
25+
// Get all active Payment Methods
26+
foreach ($paymentMethodList->getActiveList(\Magento\Store\Model\Store::DEFAULT_STORE_ID) as $paymentMethod) {
27+
$configData['payment/' . $paymentMethod->getCode() . '/active'] = 0;
28+
$disabledPaymentMethods[] = $paymentMethod->getCode();
29+
}
30+
// Remember all manually disabled Payment Methods for rollback
31+
$configData[$rollbackConfigKey] = implode(',', $disabledPaymentMethods);
32+
33+
/** @var Config $defConfig */
34+
$defConfig = $objectManager->create(Config::class);
35+
$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
36+
37+
$processConfigData($defConfig, $configData);
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)