Skip to content

Commit

Permalink
419 - Test coverage: GetAvailablePaymentMethodsTest for Customer
Browse files Browse the repository at this point in the history
1. Add testGetPaymentMethodsIfPaymentsAreNotSet and appropriate fixtures
  • Loading branch information
atwixfirster committed Mar 7, 2019
1 parent 44e24e3 commit 8786fbf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public function testGetPaymentMethodsFromAnotherCustomerCart()
$this->graphQlQuery($query, [], '', $this->getHeaderMap('customer3@search.example.com'));
}

/**
* @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->getCartAvailablePaymentMethodsQuery($maskedQuoteId);
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());

self::assertEquals(0, count($response['cart']['available_payment_methods']));
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\TestFramework\Helper\Bootstrap;

$processConfigData = function (Config $config, array $data) {
foreach ($data as $key => $value) {
$config->setDataByPath($key, $value);
$config->save();
}
};

$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(\Magento\Store\Model\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);

$processConfigData($defConfig, $configData);
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();

0 comments on commit 8786fbf

Please sign in to comment.