This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #601
- Loading branch information
Showing
2 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
...unctional/testsuite/Magento/GraphQl/Quote/Customer/SetOfflinePaymentMethodsOnCartTest.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,168 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Quote\Customer; | ||
|
||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\OfflinePayments\Model\Banktransfer; | ||
use Magento\OfflinePayments\Model\Cashondelivery; | ||
use Magento\OfflinePayments\Model\Checkmo; | ||
use Magento\OfflinePayments\Model\Purchaseorder; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test for setting offline payment methods on cart | ||
*/ | ||
class SetOfflinePaymentMethodsOnCartTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var GetMaskedQuoteIdByReservedOrderId | ||
*/ | ||
private $getMaskedQuoteIdByReservedOrderId; | ||
|
||
/** | ||
* @var CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); | ||
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php | ||
* | ||
* @param string $methodCode | ||
* @dataProvider offlinePaymentMethodDataProvider | ||
*/ | ||
public function testSetOfflinePaymentMethod(string $methodCode) | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
|
||
$query = $this->getQuery( | ||
$maskedQuoteId, | ||
$methodCode | ||
); | ||
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('setPaymentMethodOnCart', $response); | ||
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); | ||
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); | ||
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); | ||
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php | ||
* | ||
* @param string $methodCode | ||
*/ | ||
public function testSetPurchaseOrderPaymentMethod() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE; | ||
$poNumber = 'abc123'; | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
setPaymentMethodOnCart(input: { | ||
cart_id: "{$maskedQuoteId}", | ||
payment_method: { | ||
code: "{$methodCode}" | ||
purchase_order_number: "{$poNumber}" | ||
} | ||
}) { | ||
cart { | ||
selected_payment_method { | ||
code | ||
purchase_order_number | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
|
||
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); | ||
|
||
self::assertArrayHasKey('setPaymentMethodOnCart', $response); | ||
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); | ||
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); | ||
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); | ||
self::assertArrayHasKey('purchase_order_number', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); | ||
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); | ||
self::assertEquals($poNumber, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['purchase_order_number']); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function offlinePaymentMethodDataProvider(): array | ||
{ | ||
return [ | ||
'check_mo' => [Checkmo::PAYMENT_METHOD_CHECKMO_CODE], | ||
'bank_transfer' => [Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE], | ||
'cash_on_delivery' => [Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @param string $methodCode | ||
* @return string | ||
*/ | ||
private function getQuery( | ||
string $maskedQuoteId, | ||
string $methodCode | ||
) : string { | ||
return <<<QUERY | ||
mutation { | ||
setPaymentMethodOnCart(input: { | ||
cart_id: "{$maskedQuoteId}", | ||
payment_method: { | ||
code: "{$methodCode}" | ||
} | ||
}) { | ||
cart { | ||
selected_payment_method { | ||
code | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
|
||
/** | ||
* @param string $username | ||
* @param string $password | ||
* @return array | ||
*/ | ||
private function getHeaderMap(string $username = 'customer@example.com', string $password = 'password'): array | ||
{ | ||
$customerToken = $this->customerTokenService->createCustomerAccessToken($username, $password); | ||
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
return $headerMap; | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
...i-functional/testsuite/Magento/GraphQl/Quote/Guest/SetOfflinePaymentMethodsOnCartTest.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,147 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Quote\Guest; | ||
|
||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId; | ||
use Magento\OfflinePayments\Model\Banktransfer; | ||
use Magento\OfflinePayments\Model\Cashondelivery; | ||
use Magento\OfflinePayments\Model\Checkmo; | ||
use Magento\OfflinePayments\Model\Purchaseorder; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test for setting offline payment methods on cart | ||
*/ | ||
class SetOfflinePaymentMethodsOnCartTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var GetMaskedQuoteIdByReservedOrderId | ||
*/ | ||
private $getMaskedQuoteIdByReservedOrderId; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php | ||
* | ||
* @param string $methodCode | ||
* @dataProvider offlinePaymentMethodDataProvider | ||
*/ | ||
public function testSetOfflinePaymentMethod(string $methodCode) | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
|
||
$query = $this->getQuery( | ||
$maskedQuoteId, | ||
$methodCode | ||
); | ||
$response = $this->graphQlMutation($query); | ||
|
||
self::assertArrayHasKey('setPaymentMethodOnCart', $response); | ||
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); | ||
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); | ||
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); | ||
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php | ||
* | ||
* @param string $methodCode | ||
*/ | ||
public function testSetPurchaseOrderPaymentMethod() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE; | ||
$poNumber = 'abc123'; | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
setPaymentMethodOnCart(input: { | ||
cart_id: "{$maskedQuoteId}", | ||
payment_method: { | ||
code: "{$methodCode}" | ||
purchase_order_number: "{$poNumber}" | ||
} | ||
}) { | ||
cart { | ||
selected_payment_method { | ||
code | ||
purchase_order_number | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
|
||
$response = $this->graphQlMutation($query); | ||
|
||
self::assertArrayHasKey('setPaymentMethodOnCart', $response); | ||
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']); | ||
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']); | ||
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); | ||
self::assertArrayHasKey('purchase_order_number', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']); | ||
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']); | ||
self::assertEquals($poNumber, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['purchase_order_number']); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function offlinePaymentMethodDataProvider(): array | ||
{ | ||
return [ | ||
'check_mo' => [Checkmo::PAYMENT_METHOD_CHECKMO_CODE], | ||
'bank_transfer' => [Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE], | ||
'cash_on_delivery' => [Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @param string $methodCode | ||
* @return string | ||
*/ | ||
private function getQuery( | ||
string $maskedQuoteId, | ||
string $methodCode | ||
) : string { | ||
return <<<QUERY | ||
mutation { | ||
setPaymentMethodOnCart(input: { | ||
cart_id: "{$maskedQuoteId}", | ||
payment_method: { | ||
code: "{$methodCode}" | ||
} | ||
}) { | ||
cart { | ||
selected_payment_method { | ||
code | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
} |