-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
428 - Test coverage: GetAvailableShippingMethodsTest
Merge remote-tracking branch 'origin/2.3-develop' into 428-getAvailableShippingMethodsTest
- Loading branch information
Showing
24 changed files
with
1,022 additions
and
192 deletions.
There are no files selected for viewing
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
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
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
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
38 changes: 38 additions & 0 deletions
38
app/code/Magento/Sales/Test/Mftf/Test/AdminChangeCustomerGroupInNewOrder.xml
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="AdminChangeCustomerGroupInNewOrder"> | ||
<annotations> | ||
<title value="Customer account group cannot be selected while creating a new customer in order"/> | ||
<stories value="MC-15290: Customer account group cannot be selected while creating a new customer in order"/> | ||
<description value="Customer account group cannot be selected while creating a new customer in order"/> | ||
<severity value="MAJOR"/> | ||
<testCaseId value="MC-15290"/> | ||
<useCaseId value="MC-15289"/> | ||
<group value="sales"/> | ||
</annotations> | ||
|
||
<before> | ||
<actionGroup ref="LoginAsAdmin" stepKey="login"/> | ||
</before> | ||
<after> | ||
<actionGroup ref="logout" stepKey="logout"/> | ||
</after> | ||
|
||
<actionGroup ref="navigateToNewOrderPageNewCustomerSingleStore" stepKey="openNewOrder"/> | ||
<selectOption selector="{{AdminOrderFormAccountSection.group}}" userInput="Retailer" stepKey="selectCustomerGroup"/> | ||
<waitForPageLoad stepKey="waitForPageLoad"/> | ||
<grabValueFrom selector="{{AdminOrderFormAccountSection.group}}" stepKey="grabGroupValue"/> | ||
<assertEquals stepKey="assertValueIsStillSelected"> | ||
<actualResult type="variable">$grabGroupValue</actualResult> | ||
<expectedResult type="string">3</expectedResult> | ||
</assertEquals> | ||
</test> | ||
</tests> |
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
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
210 changes: 210 additions & 0 deletions
210
...ctional/testsuite/Magento/GraphQl/OfflineShipping/SetOfflineShippingMethodsOnCartTest.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,210 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\OfflineShipping; | ||
|
||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\Quote\Model\QuoteFactory; | ||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; | ||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\TestCase\GraphQlAbstract; | ||
|
||
/** | ||
* Test for setting offline shipping methods on cart | ||
*/ | ||
class SetOfflineShippingMethodsOnCartTest extends GraphQlAbstract | ||
{ | ||
/** | ||
* @var QuoteFactory | ||
*/ | ||
private $quoteFactory; | ||
|
||
/** | ||
* @var CustomerTokenServiceInterface | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @var QuoteResource | ||
*/ | ||
private $quoteResource; | ||
|
||
/** | ||
* @var QuoteIdToMaskedQuoteIdInterface | ||
*/ | ||
private $quoteIdToMaskedId; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->quoteResource = $objectManager->get(QuoteResource::class); | ||
$this->quoteFactory = $objectManager->get(QuoteFactory::class); | ||
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class); | ||
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php | ||
* @magentoApiDataFixture Magento/OfflineShipping/_files/enable_offline_shipping_methods.php | ||
* @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php | ||
* | ||
* @param string $carrierCode | ||
* @param string $methodCode | ||
* @param float $amount | ||
* @param string $label | ||
* @dataProvider offlineShippingMethodDataProvider | ||
*/ | ||
public function testSetOfflineShippingMethod(string $carrierCode, string $methodCode, float $amount, string $label) | ||
{ | ||
$quote = $this->quoteFactory->create(); | ||
$this->quoteResource->load( | ||
$quote, | ||
'test_order_1', | ||
'reserved_order_id' | ||
); | ||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
$shippingAddressId = (int)$quote->getShippingAddress()->getId(); | ||
|
||
$query = $this->getQuery( | ||
$maskedQuoteId, | ||
$shippingAddressId, | ||
$carrierCode, | ||
$methodCode | ||
); | ||
|
||
$response = $this->sendRequestWithToken($query); | ||
|
||
$addressesInformation = $response['setShippingMethodsOnCart']['cart']['shipping_addresses']; | ||
self::assertEquals($addressesInformation[0]['selected_shipping_method']['carrier_code'], $carrierCode); | ||
self::assertEquals($addressesInformation[0]['selected_shipping_method']['method_code'], $methodCode); | ||
self::assertEquals($addressesInformation[0]['selected_shipping_method']['amount'], $amount); | ||
self::assertEquals($addressesInformation[0]['selected_shipping_method']['label'], $label); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function offlineShippingMethodDataProvider() | ||
{ | ||
return [ | ||
'flatrate_flatrate' => ['flatrate', 'flatrate', 10, 'Flat Rate - Fixed'], | ||
'tablerate_bestway' => ['tablerate', 'bestway', 10, 'Best Way - Table Rate'], | ||
'freeshipping_freeshipping' => ['freeshipping', 'freeshipping', 0, 'Free Shipping - Free'], | ||
]; | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php | ||
* @magentoApiDataFixture Magento/OfflineShipping/_files/enable_offline_shipping_methods.php | ||
*/ | ||
public function testSetShippingMethodTwiceInOneRequest() | ||
{ | ||
$quote = $this->quoteFactory->create(); | ||
$this->quoteResource->load( | ||
$quote, | ||
'test_order_1', | ||
'reserved_order_id' | ||
); | ||
$shippingAddress = $quote->getShippingAddress(); | ||
$shippingAddressId = $shippingAddress->getId(); | ||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
|
||
$query = <<<QUERY | ||
mutation { | ||
setShippingMethodsOnCart(input: { | ||
cart_id: "$maskedQuoteId" | ||
shipping_methods: [ | ||
{ | ||
cart_address_id: $shippingAddressId | ||
carrier_code: "flatrate" | ||
method_code: "flatrate" | ||
} | ||
{ | ||
cart_address_id: $shippingAddressId | ||
carrier_code: "freeshipping" | ||
method_code: "freeshipping" | ||
} | ||
] | ||
}) { | ||
cart { | ||
shipping_addresses { | ||
selected_shipping_method { | ||
carrier_code | ||
method_code | ||
label | ||
amount | ||
} | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
self::expectExceptionMessage('You cannot specify multiple shipping methods.'); | ||
$this->sendRequestWithToken($query); | ||
} | ||
|
||
/** | ||
* Generates query for setting the specified shipping method on cart | ||
* | ||
* @param int $shippingAddressId | ||
* @param string $maskedQuoteId | ||
* @param string $carrierCode | ||
* @param string $methodCode | ||
* @return string | ||
*/ | ||
private function getQuery( | ||
string $maskedQuoteId, | ||
int $shippingAddressId, | ||
string $carrierCode, | ||
string $methodCode | ||
): string { | ||
return <<<QUERY | ||
mutation { | ||
setShippingMethodsOnCart(input: { | ||
cart_id: "$maskedQuoteId" | ||
shipping_methods: [ | ||
{ | ||
cart_address_id: $shippingAddressId | ||
carrier_code: "$carrierCode" | ||
method_code: "$methodCode" | ||
} | ||
] | ||
}) { | ||
cart { | ||
shipping_addresses { | ||
selected_shipping_method { | ||
carrier_code | ||
method_code | ||
label | ||
amount | ||
} | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
|
||
/** | ||
* Sends a GraphQL request with using a bearer token | ||
* | ||
* @param string $query | ||
* @return array | ||
* @throws \Magento\Framework\Exception\AuthenticationException | ||
*/ | ||
private function sendRequestWithToken(string $query): array | ||
{ | ||
$customerToken = $this->customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); | ||
$headerMap = ['Authorization' => 'Bearer ' . $customerToken]; | ||
|
||
return $this->graphQlQuery($query, [], '', $headerMap); | ||
} | ||
} |
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
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
Oops, something went wrong.