From 8786fbfa171adb26931d90e8f3d3790a5ddcb63c Mon Sep 17 00:00:00 2001 From: Alex Taranovsky Date: Thu, 7 Mar 2019 15:55:27 +0200 Subject: [PATCH] 419 - Test coverage: GetAvailablePaymentMethodsTest for Customer 1. Add testGetPaymentMethodsIfPaymentsAreNotSet and appropriate fixtures --- .../GetAvailablePaymentMethodsTest.php | 12 ++++++ .../disable_all_active_payment_methods.php | 37 +++++++++++++++++++ ...le_all_active_payment_methods_rollback.php | 33 +++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php create mode 100644 dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php index 4cc72a8089b94..e5027119cbc6c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/GetAvailablePaymentMethodsTest.php @@ -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 diff --git a/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php b/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php new file mode 100644 index 0000000000000..762ea672614a8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods.php @@ -0,0 +1,37 @@ + $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); diff --git a/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php b/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php new file mode 100644 index 0000000000000..ee81af139f4b4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Payment/_files/disable_all_active_payment_methods_rollback.php @@ -0,0 +1,33 @@ +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();