ltsecurityinc安防产品在线商城代码
This commit is contained in:
+489
@@ -0,0 +1,489 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Add simple product to cart testcases
|
||||
*/
|
||||
class AddSimpleProductToCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testAddSimpleProductToCart()
|
||||
{
|
||||
$sku = 'simple_product';
|
||||
$quantity = 2;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$response = $this->graphQlMutation($query);
|
||||
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
|
||||
|
||||
self::assertArrayHasKey('shipping_addresses', $response['addSimpleProductsToCart']['cart']);
|
||||
self::assertEmpty($response['addSimpleProductsToCart']['cart']['shipping_addresses']);
|
||||
self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
|
||||
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
|
||||
self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]);
|
||||
self::assertArrayHasKey('id', $response['addSimpleProductsToCart']['cart']);
|
||||
self::assertEquals($maskedQuoteId, $response['addSimpleProductsToCart']['cart']['id']);
|
||||
|
||||
self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
|
||||
$price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price'];
|
||||
self::assertArrayHasKey('value', $price);
|
||||
self::assertEquals(10, $price['value']);
|
||||
self::assertArrayHasKey('currency', $price);
|
||||
self::assertEquals('USD', $price['currency']);
|
||||
|
||||
self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
|
||||
$rowTotal = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total'];
|
||||
self::assertArrayHasKey('value', $rowTotal);
|
||||
self::assertEquals(20, $rowTotal['value']);
|
||||
self::assertArrayHasKey('currency', $rowTotal);
|
||||
self::assertEquals('USD', $rowTotal['currency']);
|
||||
|
||||
self::assertArrayHasKey(
|
||||
'row_total_including_tax',
|
||||
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']
|
||||
);
|
||||
$rowTotalIncludingTax =
|
||||
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax'];
|
||||
self::assertArrayHasKey('value', $rowTotalIncludingTax);
|
||||
self::assertEquals(20, $rowTotalIncludingTax['value']);
|
||||
self::assertArrayHasKey('currency', $rowTotalIncludingTax);
|
||||
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/Store/_files/second_store.php
|
||||
*/
|
||||
public function testAddSimpleProductWithDifferentStoreHeader()
|
||||
{
|
||||
$sku = 'simple_product';
|
||||
$quantity = 2;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$headerMap = ['Store' => 'fixture_second_store'];
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$response = $this->graphQlMutation($query, [], '', $headerMap);
|
||||
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
|
||||
|
||||
self::assertArrayHasKey('shipping_addresses', $response['addSimpleProductsToCart']['cart']);
|
||||
self::assertEmpty($response['addSimpleProductsToCart']['cart']['shipping_addresses']);
|
||||
self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
|
||||
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
|
||||
self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]);
|
||||
self::assertArrayHasKey('id', $response['addSimpleProductsToCart']['cart']);
|
||||
self::assertEquals($maskedQuoteId, $response['addSimpleProductsToCart']['cart']['id']);
|
||||
|
||||
self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
|
||||
$price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price'];
|
||||
self::assertArrayHasKey('value', $price);
|
||||
self::assertEquals(10, $price['value']);
|
||||
self::assertArrayHasKey('currency', $price);
|
||||
self::assertEquals('USD', $price['currency']);
|
||||
|
||||
self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
|
||||
$rowTotal = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total'];
|
||||
self::assertArrayHasKey('value', $rowTotal);
|
||||
self::assertEquals(20, $rowTotal['value']);
|
||||
self::assertArrayHasKey('currency', $rowTotal);
|
||||
self::assertEquals('USD', $rowTotal['currency']);
|
||||
|
||||
self::assertArrayHasKey(
|
||||
'row_total_including_tax',
|
||||
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']
|
||||
);
|
||||
$rowTotalIncludingTax =
|
||||
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax'];
|
||||
self::assertArrayHasKey('value', $rowTotalIncludingTax);
|
||||
self::assertEquals(20, $rowTotalIncludingTax['value']);
|
||||
self::assertArrayHasKey('currency', $rowTotalIncludingTax);
|
||||
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image_no_options.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*/
|
||||
public function testAddProductToCartWithImage()
|
||||
{
|
||||
$sku = 'simple-2';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(input: {
|
||||
cart_id: "$maskedQuoteId",
|
||||
cart_items: [{data: {sku: "$sku", quantity: 1}}]
|
||||
}) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
prices{
|
||||
price {
|
||||
value
|
||||
}
|
||||
}
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
name
|
||||
image {
|
||||
label
|
||||
url
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlMutation($query);
|
||||
$this->assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
|
||||
$this->assertCount(1, $response['addSimpleProductsToCart']['cart']['items']);
|
||||
$cartItem = $response['addSimpleProductsToCart']['cart']['items'][0];
|
||||
$this->assertEquals('11', $cartItem['prices']['price']['value']);
|
||||
$this->assertEquals($sku, $cartItem['product']['sku']);
|
||||
$expectedImageRegex = '/^https?:\/\/.+magento_image(_[0-9]+)?.jpg$/';
|
||||
$this->assertMatchesRegularExpression($expectedImageRegex, $cartItem['product']['image']['url']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add disabled product to cart
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @return void
|
||||
*/
|
||||
public function testAddDisabledProductToCart(): void
|
||||
{
|
||||
$sku = 'simple3';
|
||||
$quantity = 2;
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
|
||||
$this->expectException(ResponseContainsErrorsException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'GraphQL response contains errors: Could not find a product with SKU "' . $sku . '"'
|
||||
);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add out of stock product to cart
|
||||
*
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
* @return void
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testAddOutOfStockProductToCart(): void
|
||||
{
|
||||
$sku = 'simple1';
|
||||
$skuOutOfStock = 'simple_product';
|
||||
$quantity = 1;
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$this->graphQlMutation($query);
|
||||
|
||||
$this->expectException(ResponseContainsErrorsException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Product that you are trying to add is not available'
|
||||
);
|
||||
$query = $this->getQuery($maskedQuoteId, $skuOutOfStock, $quantity);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add out of stock product to cart with disabled quote item check
|
||||
*
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
* @return void
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testAddOutOfStockProductToCartWithDisabledInventoryCheck(): void
|
||||
{
|
||||
$sku = 'simple1';
|
||||
$quantity = 1;
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
|
||||
$this->assertCount(2, $response['addSimpleProductsToCart']['cart']['items']);
|
||||
$cartItems = $response['addSimpleProductsToCart']['cart']['items'];
|
||||
$this->assertEquals(2, $cartItems[0]['quantity']);
|
||||
$this->assertEquals(1, $cartItems[1]['quantity']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add out of stock simple product to cart with disabled quote item check
|
||||
*
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
* @return void
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testAddOutOfStockSimpleProductToCart(): void
|
||||
{
|
||||
$sku = 'simple_product';
|
||||
$quantity = 1;
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
|
||||
$this->expectException(ResponseContainsErrorsException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Could not add the product with SKU ' . $sku . ' to the shopping cart: ' .
|
||||
'Product that you are trying to add is not available.'
|
||||
);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add out of stock simple product to cart with disabled quote item check
|
||||
*
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
* @return void
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testAddOutOfStockSimpleProductToCartWithDisabledInventoryCheck(): void
|
||||
{
|
||||
$sku = 'simple_product';
|
||||
$quantity = 1;
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
|
||||
$this->expectException(ResponseContainsErrorsException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Could not add the product with SKU ' . $sku . ' to the shopping cart: ' .
|
||||
'Product that you are trying to add is not available.'
|
||||
);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testAddSimpleProductToCartIfCartIdIsEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_id" is missing');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(
|
||||
input: {
|
||||
cart_id: "",
|
||||
cart_items: []
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testAddSimpleProductToCartIfCartItemsAreEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_items" is missing');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(
|
||||
input: {
|
||||
cart_id: "cart_id",
|
||||
cart_items: []
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
*
|
||||
*/
|
||||
public function testAddProductToNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$sku = 'simple_product';
|
||||
$quantity = 1;
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*
|
||||
*/
|
||||
public function testNonExistentProductToCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a product with SKU "simple_product"');
|
||||
|
||||
$sku = 'simple_product';
|
||||
$quantity = 1;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testAddSimpleProductToCustomerCart()
|
||||
{
|
||||
$sku = 'simple_product';
|
||||
$quantity = 2;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $sku
|
||||
* @param float $quantity
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(
|
||||
input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
cart_items: [
|
||||
{
|
||||
data: {
|
||||
quantity: $quantity
|
||||
sku: "$sku"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
id
|
||||
items {
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
}
|
||||
prices {
|
||||
price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
row_total {
|
||||
value
|
||||
currency
|
||||
}
|
||||
row_total_including_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
shipping_addresses {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Add virtual product to cart testcases
|
||||
*/
|
||||
class AddVirtualProductToCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/virtual_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*/
|
||||
public function testAddVirtualProductToCart()
|
||||
{
|
||||
$sku = 'virtual_product';
|
||||
$quantity = 2;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response['addVirtualProductsToCart']);
|
||||
self::assertArrayHasKey('id', $response['addVirtualProductsToCart']['cart']);
|
||||
self::assertEquals($maskedQuoteId, $response['addVirtualProductsToCart']['cart']['id']);
|
||||
self::assertEquals($quantity, $response['addVirtualProductsToCart']['cart']['items'][0]['quantity']);
|
||||
self::assertEquals($sku, $response['addVirtualProductsToCart']['cart']['items'][0]['product']['sku']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testAddVirtualProductToCartIfCartIdIsEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_id" is missing');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(
|
||||
input: {
|
||||
cart_id: "",
|
||||
cart_items: []
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testAddVirtualProductToCartIfCartItemsAreEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_items" is missing');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(
|
||||
input: {
|
||||
cart_id: "cart_id",
|
||||
cart_items: []
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/virtual_product.php
|
||||
*
|
||||
*/
|
||||
public function testAddVirtualToNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$sku = 'virtual_product';
|
||||
$quantity = 1;
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*
|
||||
*/
|
||||
public function testNonExistentProductToCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a product with SKU "virtual_product"');
|
||||
|
||||
$sku = 'virtual_product';
|
||||
$quantity = 1;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/virtual_product.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testAddVirtualProductToCustomerCart()
|
||||
{
|
||||
$sku = 'virtual_product';
|
||||
$quantity = 2;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $sku
|
||||
* @param float $quantity
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, string $sku, float $quantity): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
addVirtualProductsToCart(
|
||||
input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
cart_items: [
|
||||
{
|
||||
data: {
|
||||
quantity: {$quantity}
|
||||
sku: "{$sku}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
id
|
||||
items {
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\OfflinePayments\Model\Checkmo;
|
||||
use Magento\Quote\Api\GuestCartRepositoryInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for guest checkout.
|
||||
*/
|
||||
class AllowGuestCheckoutOptionTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $orderCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var GuestCartRepositoryInterface
|
||||
*/
|
||||
private $guestCartRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->orderCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
$this->guestCartRepository = $objectManager->get(GuestCartRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*/
|
||||
public function testCreateEmptyCartIfGuestCheckoutIsDisabled()
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createEmptyCart
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('createEmptyCart', $response);
|
||||
self::assertNotEmpty($response['createEmptyCart']);
|
||||
|
||||
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
|
||||
|
||||
self::assertNotNull($guestCart->getId());
|
||||
self::assertNull($guestCart->getCustomer()->getId());
|
||||
self::assertEquals('default', $guestCart->getStore()->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*
|
||||
*/
|
||||
public function testSetBillingAddressToGuestCustomerCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AZ"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*
|
||||
*/
|
||||
public function testSetGuestEmailOnCartWithGuestCheckoutDisabled()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$email = 'some@user.com';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setGuestEmailOnCart(input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
email: "$email"
|
||||
}) {
|
||||
cart {
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*
|
||||
*/
|
||||
public function testSetPaymentOnCartWithGuestCheckoutDisabled()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.');
|
||||
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "{$maskedQuoteId}",
|
||||
payment_method: {
|
||||
code: "{$methodCode}"
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('setPaymentMethodOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']);
|
||||
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']);
|
||||
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
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*
|
||||
*/
|
||||
public function testSetNewShippingAddressOnCartWithGuestCheckoutDisabled()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AZ"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
firstname
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*
|
||||
*/
|
||||
public function testSetShippingMethodOnCartWithGuestCheckoutDisabled()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$carrierCode = 'flatrate';
|
||||
$methodCode = 'flatrate';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingMethodsOnCart(input:
|
||||
{
|
||||
cart_id: "$maskedQuoteId",
|
||||
shipping_methods: [{
|
||||
carrier_code: "$carrierCode"
|
||||
method_code: "$methodCode"
|
||||
}]
|
||||
}) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
selected_shipping_method {
|
||||
carrier_code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
* @magentoConfigFixture default_store checkout/options/guest_checkout 0
|
||||
*
|
||||
*/
|
||||
public function testPlaceOrderWithGuestCheckoutDisabled()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest checkout is not allowed. Register a customer account or login with existing one.');
|
||||
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
placeOrder(input: {cart_id: "{$maskedQuoteId}"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', true);
|
||||
|
||||
$orderCollection = $this->orderCollectionFactory->create();
|
||||
foreach ($orderCollection as $order) {
|
||||
$this->orderRepository->delete($order);
|
||||
}
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', false);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test Apply Coupon to Cart functionality for guest
|
||||
*/
|
||||
class ApplyCouponToCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponToCart()
|
||||
{
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('applyCouponToCart', $response);
|
||||
self::assertArrayHasKey('id', $response['applyCouponToCart']['cart']);
|
||||
self::assertEquals($maskedQuoteId, $response['applyCouponToCart']['cart']['id']);
|
||||
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['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/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponTwice()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('A coupon is already applied to the cart. Please remove it to apply another');
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey("applyCouponToCart", $response);
|
||||
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupon']['code']);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponToCartWithoutItems()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Cart does not contain products.');
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testApplyCouponToCustomerCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
self::expectExceptionMessage('The current user cannot perform operations on cart "' . $maskedQuoteId . '"');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testApplyNonExistentCouponToCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The coupon code isn\'t valid. Verify the code and try again.');
|
||||
|
||||
$couponCode = 'non_existent_coupon_code';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponToNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
self::expectExceptionMessage('Could not find a cart with ID "' . $maskedQuoteId . '"');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Products in cart don't fit to the coupon
|
||||
*
|
||||
* @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/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/restrict_coupon_usage_for_simple_product.php
|
||||
*/
|
||||
public function testApplyCouponWhichIsNotApplicable()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The coupon code isn\'t valid. Verify the code and try again.');
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $couponCode
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, string $couponCode): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
applyCouponToCart(input: {cart_id: "$maskedQuoteId", coupon_code: "$couponCode"}) {
|
||||
cart {
|
||||
id
|
||||
applied_coupon {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test Apply Coupons to Cart functionality for guest
|
||||
*/
|
||||
class ApplyCouponsToCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponsToCart()
|
||||
{
|
||||
$couponCode = '2?ds5!2d';
|
||||
$expectedGrandTotal = 15.00;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('applyCouponToCart', $response);
|
||||
self::assertEquals($couponCode, $response['applyCouponToCart']['cart']['applied_coupons'][0]['code']);
|
||||
self::assertEquals(
|
||||
$expectedGrandTotal,
|
||||
$response['applyCouponToCart']['cart']['prices']['grand_total']['value']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponsToCartWithoutItems()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Cart does not contain products.');
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testApplyCouponsToCustomerCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
self::expectExceptionMessage('The current user cannot perform operations on cart "' . $maskedQuoteId . '"');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testApplyNonExistentCouponToCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The coupon code isn\'t valid. Verify the code and try again.');
|
||||
|
||||
$couponCode = 'non_existent_coupon_code';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
*/
|
||||
public function testApplyCouponsToNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
self::expectExceptionMessage('Could not find a cart with ID "' . $maskedQuoteId . '"');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Products in cart don't fit to the coupon
|
||||
*
|
||||
* @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/SalesRule/_files/coupon_code_with_wildcard.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/restrict_coupon_usage_for_simple_product.php
|
||||
*/
|
||||
public function testApplyCouponsWhichIsNotApplicable()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The coupon code isn\'t valid. Verify the code and try again.');
|
||||
|
||||
$couponCode = '2?ds5!2d';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $couponCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $couponCode
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, string $couponCode): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
applyCouponToCart(input: {cart_id: "$maskedQuoteId", coupon_code: "$couponCode"}) {
|
||||
cart {
|
||||
applied_coupons {
|
||||
code
|
||||
}
|
||||
prices {
|
||||
grand_total {
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for assigning guest to the guest cart
|
||||
*/
|
||||
class AssignCustomerToGuestCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteIdInterface
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
/**
|
||||
* @var GetQuoteByReservedOrderId
|
||||
*/
|
||||
private $getQuoteByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
|
||||
$this->getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for assigning guest to the guest cart
|
||||
*
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
*/
|
||||
public function testAssignCustomerToGuestCartForGuest(): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The current customer isn\'t authorized.');
|
||||
|
||||
$guestQuote = $this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address');
|
||||
$guestQuoteMaskedId = $this->quoteIdToMaskedId->execute((int)$guestQuote->getId());
|
||||
|
||||
$query = $this->getAssignCustomerToGuestCartMutation($guestQuoteMaskedId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the assignCustomerToGuestCart mutation
|
||||
*
|
||||
* @param string $guestQuoteMaskedId
|
||||
* @return string
|
||||
*/
|
||||
private function getAssignCustomerToGuestCartMutation(string $guestQuoteMaskedId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
assignCustomerToGuestCart(
|
||||
cart_id: "{$guestQuoteMaskedId}"
|
||||
){
|
||||
items {
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test is getting cart discount for guest customer.
|
||||
*/
|
||||
class CartDiscountTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/cart_rule_discount_no_coupon.php
|
||||
* @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
|
||||
*/
|
||||
public function testGetDiscountInformation()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
$discountResponse = $response['cart']['prices']['discount'];
|
||||
self::assertEquals(-10, $discountResponse['amount']['value']);
|
||||
self::assertEquals(['50% Off for all orders'], $discountResponse['label']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/cart_rule_discount_no_coupon.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.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/apply_coupon.php
|
||||
*/
|
||||
public function testGetDiscountInformationWithTwoRulesApplied()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
$discountResponse = $response['cart']['prices']['discount'];
|
||||
self::assertEquals(-15, $discountResponse['amount']['value']);
|
||||
self::assertEquals(['50% Off for all orders', '5$ fixed discount on whole cart'], $discountResponse['label']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testGetDiscountInformationWithNoRulesApplied()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
self::assertNull($response['cart']['prices']['discount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates GraphQl query for retrieving cart discount.
|
||||
*
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "$maskedQuoteId") {
|
||||
prices {
|
||||
discount {
|
||||
label
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
||||
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
|
||||
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture;
|
||||
use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixture;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorage;
|
||||
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test getting cart totals for guest
|
||||
*/
|
||||
class CartTotalsTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteIdInterface
|
||||
*/
|
||||
private $quoteIdToMaskedQuoteIdInterface;
|
||||
|
||||
/**
|
||||
* @var DataFixtureStorage
|
||||
*/
|
||||
private $fixtures;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->quoteIdToMaskedQuoteIdInterface = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
|
||||
$this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_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/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetCartTotalsWithTaxApplied()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(10, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(10.75, $cartItem['prices']['price_including_tax']['value']);
|
||||
self::assertEquals(20, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(21.5, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
|
||||
self::assertArrayHasKey('prices', $response['cart']);
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(21.5, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(21.5, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
|
||||
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
|
||||
|
||||
self::assertEquals('US-TEST-*-Rate-1', $appliedTaxesResponse[0]['label']);
|
||||
self::assertEquals(1.5, $appliedTaxesResponse[0]['amount']['value']);
|
||||
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_with_translated_titles.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_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/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetCartTotalsWithTranslatedTaxTitles()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(10, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(20, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(21.5, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
|
||||
self::assertArrayHasKey('prices', $response['cart']);
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(21.5, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(21.5, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
|
||||
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
|
||||
|
||||
self::assertEquals('Rate Title on storeview 1', $appliedTaxesResponse[0]['label']);
|
||||
self::assertEquals(1.5, $appliedTaxesResponse[0]['amount']['value']);
|
||||
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.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/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetCartTotalsWithCatalogRuleApplied()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(9, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(9, $cartItem['prices']['price_including_tax']['value']);
|
||||
self::assertEquals(18, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(18, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
|
||||
self::assertArrayHasKey('prices', $response['cart']);
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(18, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.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/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetCartTotalsWithCatalogRuleAndTaxApplied()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(9, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(9.68, $cartItem['prices']['price_including_tax']['value']);
|
||||
self::assertEquals(18, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(19.35, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
|
||||
self::assertArrayHasKey('prices', $response['cart']);
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(19.35, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(19.35, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/cart_rule_discount_no_coupon.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/catalog_rule_10_off_not_logged.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/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetCartTotalsWithCatalogRuleAndCartRuleApplied()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(9, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(9, $cartItem['prices']['price_including_tax']['value']);
|
||||
self::assertEquals(18, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(18, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
self::assertEquals(9, $cartItem['prices']['total_item_discount']['value']);
|
||||
|
||||
$discount = $cartItem['prices']['discounts'][0];
|
||||
self::assertEquals("50% Off for all orders", $discount['label']);
|
||||
self::assertEquals(9, $discount['amount']['value']);
|
||||
|
||||
self::assertArrayHasKey('prices', $response['cart']);
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(9, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(18, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(9, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetCartTotalsWithEmptyCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('prices', $response['cart']);
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(0, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(0, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(0, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(0, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
|
||||
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
|
||||
|
||||
self::assertCount(0, $appliedTaxesResponse);
|
||||
}
|
||||
|
||||
#[
|
||||
DataFixture(ProductFixture::class, as: 'p'),
|
||||
DataFixture(GuestCartFixture::class, as: 'cart'),
|
||||
DataFixture(AddProductToCartFixture::class, ['cart_id' => '$cart.id$', 'product_id' => '$p.id$', 'qty' => 2]),
|
||||
DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$']),
|
||||
DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$']),
|
||||
]
|
||||
public function testGetTotalsWithNoTaxApplied()
|
||||
{
|
||||
$cart = $this->fixtures->get('cart');
|
||||
$maskedQuoteId = $this->quoteIdToMaskedQuoteIdInterface->execute((int) $cart->getId());
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(10, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(10, $cartItem['prices']['price_including_tax']['value']);
|
||||
self::assertEquals(20, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(20, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(20, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
self::assertEmpty($pricesResponse['applied_taxes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* The totals calculation is based on quote address.
|
||||
* But the totals should be calculated even if no address is set
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testGetCartTotalsWithNoAddressSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$cartItem = $response['cart']['items'][0];
|
||||
self::assertEquals(10, $cartItem['prices']['price']['value']);
|
||||
self::assertEquals(10, $cartItem['prices']['price_including_tax']['value']);
|
||||
self::assertEquals(20, $cartItem['prices']['row_total']['value']);
|
||||
self::assertEquals(20, $cartItem['prices']['row_total_including_tax']['value']);
|
||||
|
||||
$pricesResponse = $response['cart']['prices'];
|
||||
self::assertEquals(20, $pricesResponse['grand_total']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']);
|
||||
self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
|
||||
self::assertEmpty($pricesResponse['applied_taxes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/apply_tax_for_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/set_new_billing_address.php
|
||||
*/
|
||||
public function testGetSelectedShippingMethodFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates GraphQl query for retrieving cart totals
|
||||
*
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "$maskedQuoteId") {
|
||||
items {
|
||||
prices {
|
||||
price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
price_including_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
row_total {
|
||||
value
|
||||
currency
|
||||
}
|
||||
row_total_including_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
total_item_discount {
|
||||
value
|
||||
}
|
||||
discounts {
|
||||
label
|
||||
amount {
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prices {
|
||||
grand_total {
|
||||
value
|
||||
currency
|
||||
}
|
||||
subtotal_including_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
subtotal_excluding_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
subtotal_with_discount_excluding_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
applied_taxes {
|
||||
label
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+436
@@ -0,0 +1,436 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* End to checkout tests for guest
|
||||
*/
|
||||
class CheckoutEndToEndTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var QuoteCollectionFactory
|
||||
*/
|
||||
private $quoteCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var QuoteResource
|
||||
*/
|
||||
private $quoteResource;
|
||||
|
||||
/**
|
||||
* @var QuoteIdMaskFactory
|
||||
*/
|
||||
private $quoteIdMaskFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $orderCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->registry = $objectManager->get(Registry::class);
|
||||
$this->quoteCollectionFactory = $objectManager->get(QuoteCollectionFactory::class);
|
||||
$this->quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$this->quoteIdMaskFactory = $objectManager->get(QuoteIdMaskFactory::class);
|
||||
$this->orderCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
|
||||
*/
|
||||
public function testCheckoutWorkflow()
|
||||
{
|
||||
$quantity = 2;
|
||||
|
||||
$sku = $this->findProduct();
|
||||
$cartId = $this->createEmptyCart();
|
||||
$this->setGuestEmailOnCart($cartId);
|
||||
$this->addProductToCart($cartId, $quantity, $sku);
|
||||
|
||||
$this->setBillingAddress($cartId);
|
||||
$shippingMethod = $this->setShippingAddress($cartId);
|
||||
|
||||
$paymentMethod = $this->setShippingMethod($cartId, $shippingMethod);
|
||||
$this->setPaymentMethod($cartId, $paymentMethod);
|
||||
|
||||
$this->placeOrder($cartId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function findProduct(): string
|
||||
{
|
||||
$query = <<<QUERY
|
||||
{
|
||||
products (
|
||||
filter: {
|
||||
sku: {
|
||||
eq:"simple1"
|
||||
}
|
||||
}
|
||||
pageSize: 1
|
||||
currentPage: 1
|
||||
) {
|
||||
items {
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlQuery($query);
|
||||
self::assertArrayHasKey('products', $response);
|
||||
self::assertArrayHasKey('items', $response['products']);
|
||||
self::assertCount(1, $response['products']['items']);
|
||||
|
||||
$product = current($response['products']['items']);
|
||||
self::assertArrayHasKey('sku', $product);
|
||||
self::assertNotEmpty($product['sku']);
|
||||
|
||||
return $product['sku'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function createEmptyCart(): string
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createEmptyCart
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
self::assertArrayHasKey('createEmptyCart', $response);
|
||||
self::assertNotEmpty($response['createEmptyCart']);
|
||||
|
||||
return $response['createEmptyCart'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @return void
|
||||
*/
|
||||
private function setGuestEmailOnCart(string $cartId): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setGuestEmailOnCart(
|
||||
input: {
|
||||
cart_id: "{$cartId}"
|
||||
email: "customer@example.com"
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @param float $quantity
|
||||
* @param string $sku
|
||||
* @return void
|
||||
*/
|
||||
private function addProductToCart(string $cartId, float $quantity, string $sku): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
addSimpleProductsToCart(
|
||||
input: {
|
||||
cart_id: "{$cartId}"
|
||||
cart_items: [
|
||||
{
|
||||
data: {
|
||||
quantity: {$quantity}
|
||||
sku: "{$sku}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @param array $auth
|
||||
* @return array
|
||||
*/
|
||||
private function setBillingAddress(string $cartId): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "{$cartId}"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
postcode: "887766"
|
||||
telephone: "88776655"
|
||||
region: "TX"
|
||||
country_code: "US"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @return array
|
||||
*/
|
||||
private function setShippingAddress(string $cartId): array
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$cartId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "TX"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
available_shipping_methods {
|
||||
carrier_code
|
||||
method_code
|
||||
amount {
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
self::assertArrayHasKey('setShippingAddressesOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setShippingAddressesOnCart']);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['setShippingAddressesOnCart']['cart']);
|
||||
self::assertCount(1, $response['setShippingAddressesOnCart']['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['setShippingAddressesOnCart']['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('available_shipping_methods', $shippingAddress);
|
||||
self::assertCount(1, $shippingAddress['available_shipping_methods']);
|
||||
|
||||
$availableShippingMethod = current($shippingAddress['available_shipping_methods']);
|
||||
self::assertArrayHasKey('carrier_code', $availableShippingMethod);
|
||||
self::assertNotEmpty($availableShippingMethod['carrier_code']);
|
||||
|
||||
self::assertArrayHasKey('method_code', $availableShippingMethod);
|
||||
self::assertNotEmpty($availableShippingMethod['method_code']);
|
||||
|
||||
self::assertArrayHasKey('amount', $availableShippingMethod);
|
||||
self::assertArrayHasKey('value', $availableShippingMethod['amount']);
|
||||
self::assertNotEmpty($availableShippingMethod['amount']['value']);
|
||||
|
||||
return $availableShippingMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @param array $method
|
||||
* @return array
|
||||
*/
|
||||
private function setShippingMethod(string $cartId, array $method): array
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingMethodsOnCart(input: {
|
||||
cart_id: "{$cartId}",
|
||||
shipping_methods: [
|
||||
{
|
||||
carrier_code: "{$method['carrier_code']}"
|
||||
method_code: "{$method['method_code']}"
|
||||
}
|
||||
]
|
||||
}) {
|
||||
cart {
|
||||
available_payment_methods {
|
||||
code
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
|
||||
self::assertArrayHasKey('available_payment_methods', $response['setShippingMethodsOnCart']['cart']);
|
||||
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['available_payment_methods']);
|
||||
|
||||
$availablePaymentMethod = current($response['setShippingMethodsOnCart']['cart']['available_payment_methods']);
|
||||
self::assertArrayHasKey('code', $availablePaymentMethod);
|
||||
self::assertNotEmpty($availablePaymentMethod['code']);
|
||||
self::assertArrayHasKey('title', $availablePaymentMethod);
|
||||
self::assertNotEmpty($availablePaymentMethod['title']);
|
||||
|
||||
return $availablePaymentMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @param array $method
|
||||
* @return void
|
||||
*/
|
||||
private function setPaymentMethod(string $cartId, array $method): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(
|
||||
input: {
|
||||
cart_id: "{$cartId}"
|
||||
payment_method: {
|
||||
code: "{$method['code']}"
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cartId
|
||||
* @return void
|
||||
*/
|
||||
private function placeOrder(string $cartId): void
|
||||
{
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
placeOrder(
|
||||
input: {
|
||||
cart_id: "{$cartId}"
|
||||
}
|
||||
) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
self::assertArrayHasKey('placeOrder', $response);
|
||||
self::assertArrayHasKey('order', $response['placeOrder']);
|
||||
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
|
||||
self::assertNotEmpty($response['placeOrder']['order']['order_number']);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->deleteQuote();
|
||||
$this->deleteOrder();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function deleteQuote(): void
|
||||
{
|
||||
$quoteCollection = $this->quoteCollectionFactory->create();
|
||||
foreach ($quoteCollection as $quote) {
|
||||
$this->quoteResource->delete($quote);
|
||||
|
||||
$quoteIdMask = $this->quoteIdMaskFactory->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId())
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function deleteOrder()
|
||||
{
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', true);
|
||||
|
||||
$orderCollection = $this->orderCollectionFactory->create();
|
||||
foreach ($orderCollection as $order) {
|
||||
$this->orderRepository->delete($order);
|
||||
}
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', false);
|
||||
}
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
use Magento\Quote\Api\GuestCartRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Test for empty cart creation mutation
|
||||
*/
|
||||
class CreateEmptyCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GuestCartRepositoryInterface
|
||||
*/
|
||||
private $guestCartRepository;
|
||||
|
||||
/**
|
||||
* @var QuoteCollectionFactory
|
||||
*/
|
||||
private $quoteCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var QuoteResource
|
||||
*/
|
||||
private $quoteResource;
|
||||
|
||||
/**
|
||||
* @var QuoteIdMaskFactory
|
||||
*/
|
||||
private $quoteIdMaskFactory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $maskedQuoteId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->guestCartRepository = $objectManager->get(GuestCartRepositoryInterface::class);
|
||||
$this->quoteCollectionFactory = $objectManager->get(QuoteCollectionFactory::class);
|
||||
$this->quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$this->quoteIdMaskFactory = $objectManager->get(QuoteIdMaskFactory::class);
|
||||
}
|
||||
|
||||
public function testCreateEmptyCart()
|
||||
{
|
||||
$query = $this->getQuery();
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('createEmptyCart', $response);
|
||||
self::assertNotEmpty($response['createEmptyCart']);
|
||||
|
||||
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
|
||||
|
||||
self::assertNotNull($guestCart->getId());
|
||||
self::assertNull($guestCart->getCustomer()->getId());
|
||||
self::assertEquals('default', $guestCart->getStore()->getCode());
|
||||
self::assertEquals('1', $guestCart->getCustomerIsGuest());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Store/_files/second_store.php
|
||||
*/
|
||||
public function testCreateEmptyCartWithNotDefaultStore()
|
||||
{
|
||||
$query = $this->getQuery();
|
||||
$headerMap = ['Store' => 'fixture_second_store'];
|
||||
$response = $this->graphQlMutation($query, [], '', $headerMap);
|
||||
|
||||
self::assertArrayHasKey('createEmptyCart', $response);
|
||||
self::assertNotEmpty($response['createEmptyCart']);
|
||||
|
||||
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
|
||||
$this->maskedQuoteId = $response['createEmptyCart'];
|
||||
|
||||
self::assertNotNull($guestCart->getId());
|
||||
self::assertNull($guestCart->getCustomer()->getId());
|
||||
self::assertSame('fixture_second_store', $guestCart->getStore()->getCode());
|
||||
self::assertEquals('1', $guestCart->getCustomerIsGuest());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testCreateEmptyCartWithPredefinedCartId()
|
||||
{
|
||||
$predefinedCartId = '572cda51902b5b517c0e1a2b2fd004b4';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('createEmptyCart', $response);
|
||||
self::assertEquals($predefinedCartId, $response['createEmptyCart']);
|
||||
|
||||
$guestCart = $this->guestCartRepository->get($response['createEmptyCart']);
|
||||
self::assertNotNull($guestCart->getId());
|
||||
self::assertNull($guestCart->getCustomer()->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
*/
|
||||
public function testCreateEmptyCartIfPredefinedCartIdAlreadyExists()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Cart with ID "572cda51902b5b517c0e1a2b2fd004b4" already exists.');
|
||||
|
||||
$predefinedCartId = '572cda51902b5b517c0e1a2b2fd004b4';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
*/
|
||||
public function testCreateEmptyCartWithWrongPredefinedCartId()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Cart ID length should to be 32 symbols.');
|
||||
|
||||
$predefinedCartId = '572';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createEmptyCart (input: {cart_id: "{$predefinedCartId}"})
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
createEmptyCart
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$quoteCollection = $this->quoteCollectionFactory->create();
|
||||
foreach ($quoteCollection as $quote) {
|
||||
$this->quoteResource->delete($quote);
|
||||
|
||||
$quoteIdMask = $this->quoteIdMaskFactory->create();
|
||||
$quoteIdMask->setQuoteId($quote->getId())
|
||||
->delete();
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for getting cart information
|
||||
*/
|
||||
class GetAvailablePaymentMethodsTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testGetAvailablePaymentMethods()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('available_payment_methods', $response['cart']);
|
||||
|
||||
self::assertEquals('checkmo', $response['cart']['available_payment_methods'][0]['code']);
|
||||
self::assertEquals('Check / Money order', $response['cart']['available_payment_methods'][0]['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product_with_zero_price.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_shipping_methods.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product_with_zero_price.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_freeshipping_shipping_method.php
|
||||
*/
|
||||
public function testGetAvailablePaymentMethodsForZeroSubTotalCheckout():void
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('available_payment_methods', $response['cart']);
|
||||
self::assertEquals('free', current($response['cart']['available_payment_methods'])['code']);
|
||||
self::assertEquals(
|
||||
'No Payment Information Required',
|
||||
current($response['cart']['available_payment_methods'])['title']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*/
|
||||
public function testGetAvailablePaymentMethodsFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @magentoConfigFixture default_store payment/paypal_billing_agreement/active 0
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 0
|
||||
* @magentoConfigFixture default_store payment/free/active 0
|
||||
*/
|
||||
public function testGetAvailablePaymentMethodsIfPaymentsAreNotPresent()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('available_payment_methods', $response['cart']);
|
||||
self::assertEmpty($response['cart']['available_payment_methods']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetAvailablePaymentMethodsOfNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "$maskedQuoteId") {
|
||||
available_payment_methods {
|
||||
code
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+249
@@ -0,0 +1,249 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for get available shipping methods
|
||||
*/
|
||||
class GetAvailableShippingMethodsTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case: get available shipping methods from current customer quote
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testGetAvailableShippingMethods()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('available_shipping_methods', $response['cart']['shipping_addresses'][0]);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']);
|
||||
|
||||
$expectedAddressData = [
|
||||
'amount' => [
|
||||
'value' => 10,
|
||||
'currency' => 'USD',
|
||||
],
|
||||
'carrier_code' => 'flatrate',
|
||||
'carrier_title' => 'Flat Rate',
|
||||
'error_message' => '',
|
||||
'method_code' => 'flatrate',
|
||||
'method_title' => 'Fixed',
|
||||
'price_incl_tax' => [
|
||||
'value' => 10,
|
||||
'currency' => 'USD',
|
||||
],
|
||||
'price_excl_tax' => [
|
||||
'value' => 10,
|
||||
'currency' => 'USD',
|
||||
],
|
||||
'base_amount' => null,
|
||||
];
|
||||
self::assertEquals(
|
||||
$expectedAddressData,
|
||||
$response['cart']['shipping_addresses'][0]['available_shipping_methods'][0]
|
||||
);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses'][0]['cart_items']);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses'][0]['cart_items_v2']);
|
||||
self::assertEquals(
|
||||
'simple_product',
|
||||
$response['cart']['shipping_addresses'][0]['cart_items_v2'][0]['product']['sku']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case: get available shipping methods from current customer quote with configurable product
|
||||
*
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/CatalogRule/_files/configurable_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_configurable_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
*/
|
||||
public function testGetAvailableShippingMethodsWithConfigurableProduct()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('available_shipping_methods', $response['cart']['shipping_addresses'][0]);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']);
|
||||
|
||||
$expectedAddressData = [
|
||||
'amount' => [
|
||||
'value' => 5,
|
||||
'currency' => 'USD',
|
||||
],
|
||||
'carrier_code' => 'flatrate',
|
||||
'carrier_title' => 'Flat Rate',
|
||||
'error_message' => '',
|
||||
'method_code' => 'flatrate',
|
||||
'method_title' => 'Fixed',
|
||||
'price_incl_tax' => [
|
||||
'value' => 5,
|
||||
'currency' => 'USD',
|
||||
],
|
||||
'price_excl_tax' => [
|
||||
'value' => 5,
|
||||
'currency' => 'USD',
|
||||
],
|
||||
'base_amount' => null,
|
||||
];
|
||||
self::assertEquals(
|
||||
$expectedAddressData,
|
||||
$response['cart']['shipping_addresses'][0]['available_shipping_methods'][0]
|
||||
);
|
||||
self::assertCount(2, $response['cart']['shipping_addresses'][0]['cart_items']);
|
||||
self::assertCount(2, $response['cart']['shipping_addresses'][0]['cart_items_v2']);
|
||||
self::assertEquals(
|
||||
'configurable',
|
||||
$response['cart']['shipping_addresses'][0]['cart_items_v2'][0]['product']['sku']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*/
|
||||
public function testGetAvailableShippingMethodsFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlQuery($this->getQuery($maskedQuoteId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case: get available shipping methods when all shipping methods are disabled
|
||||
*
|
||||
* @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
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 0
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 0
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 0
|
||||
*/
|
||||
public function testGetAvailableShippingMethodsIfShippingMethodsAreNotPresent()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));
|
||||
|
||||
self::assertEmpty($response['cart']['shipping_addresses'][0]['available_shipping_methods']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case: get available shipping methods from non-existent cart
|
||||
*
|
||||
*/
|
||||
public function testGetAvailableShippingMethodsOfNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
query {
|
||||
cart (cart_id: "{$maskedQuoteId}") {
|
||||
shipping_addresses {
|
||||
cart_items {
|
||||
cart_item_id
|
||||
quantity
|
||||
}
|
||||
cart_items_v2 {
|
||||
id
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
}
|
||||
}
|
||||
available_shipping_methods {
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
carrier_code
|
||||
carrier_title
|
||||
error_message
|
||||
method_code
|
||||
method_title
|
||||
price_excl_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
price_incl_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
base_amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
carrier_code
|
||||
carrier_title
|
||||
error_message
|
||||
method_code
|
||||
method_title
|
||||
price_excl_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
price_incl_tax {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for getting email from cart
|
||||
*/
|
||||
class GetCartEmailTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
*/
|
||||
public function testGetCartEmail()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
$this->assertArrayHasKey('email', $response['cart']);
|
||||
$this->assertEquals('guest@example.com', $response['cart']['email']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetCartEmailFromNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testGetCartEmailFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"{$maskedQuoteId}\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id:"$maskedQuoteId") {
|
||||
email
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for getting is_virtual from cart
|
||||
*/
|
||||
class GetCartIsVirtualTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testGetCartIsNotVirtual()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
$this->assertArrayHasKey('is_virtual', $response['cart']);
|
||||
$this->assertFalse($response['cart']['is_virtual']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.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/add_virtual_product.php
|
||||
*/
|
||||
public function testGetMixedCartIsNotVirtual()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
$this->assertArrayHasKey('is_virtual', $response['cart']);
|
||||
$this->assertFalse($response['cart']['is_virtual']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
|
||||
*/
|
||||
public function testGetCartIsVirtual()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
$this->assertArrayHasKey('is_virtual', $response['cart']);
|
||||
$this->assertTrue($response['cart']['is_virtual']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id:"$maskedQuoteId") {
|
||||
is_virtual
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\Config\App\Config\Type\System;
|
||||
use Magento\Config\Model\ResourceModel\Config;
|
||||
use Magento\Directory\Model\Currency;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Model\Store;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for getting cart information
|
||||
*/
|
||||
class GetCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.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/add_virtual_product.php
|
||||
*/
|
||||
public function testGetCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('items', $response['cart']);
|
||||
self::assertArrayHasKey('id', $response['cart']);
|
||||
self::assertEquals($maskedQuoteId, $response['cart']['id']);
|
||||
self::assertCount(2, $response['cart']['items']);
|
||||
|
||||
self::assertNotEmpty($response['cart']['items'][0]['id']);
|
||||
self::assertEquals(2, $response['cart']['items'][0]['quantity']);
|
||||
self::assertEquals('simple_product', $response['cart']['items'][0]['product']['sku']);
|
||||
|
||||
self::assertNotEmpty($response['cart']['items'][1]['id']);
|
||||
self::assertEquals(2, $response['cart']['items'][1]['quantity']);
|
||||
self::assertEquals('virtual-product', $response['cart']['items'][1]['product']['sku']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.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/add_virtual_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
*/
|
||||
public function testCartErrorWithOutOfStockItem()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('items', $response['cart']);
|
||||
self::assertArrayHasKey('errors', $response['cart']['items'][0]);
|
||||
self::assertEquals(
|
||||
'There are no source items with the in stock status',
|
||||
$response['cart']['items'][0]['errors'][0]['message']
|
||||
);
|
||||
self::assertArrayHasKey('id', $response['cart']);
|
||||
self::assertEquals($maskedQuoteId, $response['cart']['id']);
|
||||
self::assertCount(2, $response['cart']['items']);
|
||||
|
||||
self::assertNotEmpty($response['cart']['items'][0]['id']);
|
||||
self::assertEquals(2, $response['cart']['items'][0]['quantity']);
|
||||
self::assertEquals('simple_product', $response['cart']['items'][0]['product']['sku']);
|
||||
self::assertEquals('OUT_OF_STOCK', $response['cart']['items'][0]['product']['stock_status']);
|
||||
|
||||
self::assertNotEmpty($response['cart']['items'][1]['id']);
|
||||
self::assertEquals(2, $response['cart']['items'][1]['quantity']);
|
||||
self::assertEquals('virtual-product', $response['cart']['items'][1]['product']['sku']);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testGetCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"{$maskedQuoteId}\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetCartIfCartIdIsEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_id" is missing');
|
||||
|
||||
$maskedQuoteId = '';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetCartIfCartIdIsMissed()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage(
|
||||
'Field "cart" argument "cart_id" of type "String!" is required but not provided.'
|
||||
);
|
||||
|
||||
$query = <<<QUERY
|
||||
{
|
||||
cart {
|
||||
email
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php
|
||||
*
|
||||
*/
|
||||
public function testGetInactiveCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The cart isn\'t active.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/active_quote_guest_not_default_store.php
|
||||
*/
|
||||
public function testGetCartWithNotDefaultStore()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_not_default_store_guest');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$headerMap = ['Store' => 'fixture_second_store'];
|
||||
$response = $this->graphQlQuery($query, [], '', $headerMap);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('items', $response['cart']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
|
||||
* @magentoApiDataFixture Magento/Store/_files/second_store.php
|
||||
*/
|
||||
public function testGetCartWithWrongStore()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$headerMap = ['Store' => 'fixture_second_store'];
|
||||
$response = $this->graphQlQuery($query, [], '', $headerMap);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('items', $response['cart']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoApiDataFixture Magento/Store/_files/second_store_with_second_currency.php
|
||||
*/
|
||||
public function testGetCartWithDifferentStoreDifferentCurrency()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute(
|
||||
'test_order_with_simple_product_without_address'
|
||||
);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$headerMap = ['Store' => 'fixture_second_store'];
|
||||
$response = $this->graphQlQuery($query, [], '', $headerMap);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('items', $response['cart']);
|
||||
self::assertArrayHasKey('prices', $response['cart']['items'][0]);
|
||||
$price = $response['cart']['items'][0]['prices']['price'];
|
||||
self::assertEquals(20, $price['value']);
|
||||
self::assertEquals('EUR', $price['currency']);
|
||||
|
||||
// test alternate currency in header
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$store = $objectManager->create(Store::class);
|
||||
$store->load('fixture_second_store', 'code');
|
||||
if ($storeId = $store->load('fixture_second_store', 'code')->getId()) {
|
||||
/** @var \Magento\Config\Model\ResourceModel\Config $configResource */
|
||||
$configResource = $objectManager->get(Config::class);
|
||||
$configResource->saveConfig(
|
||||
Currency::XML_PATH_CURRENCY_ALLOW,
|
||||
'USD',
|
||||
ScopeInterface::SCOPE_STORES,
|
||||
$storeId
|
||||
);
|
||||
/**
|
||||
* Configuration cache clean is required to reload currency setting
|
||||
*/
|
||||
/** @var System $config */
|
||||
$config = $objectManager->get(System::class);
|
||||
$config->clean();
|
||||
}
|
||||
$headerMap['Content-Currency'] = 'USD';
|
||||
$response = $this->graphQlQuery($query, [], '', $headerMap);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('items', $response['cart']);
|
||||
self::assertArrayHasKey('prices', $response['cart']['items'][0]);
|
||||
$price = $response['cart']['items'][0]['prices']['price'];
|
||||
self::assertEquals(10, $price['value']);
|
||||
self::assertEquals('USD', $price['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
|
||||
* @magentoApiDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
|
||||
*/
|
||||
public function testGetCartWithDifferentStoreDifferentWebsite()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Can\'t assign cart to store in different website.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$headerMap = ['Store' => 'fixture_second_store'];
|
||||
$this->graphQlQuery($query, [], '', $headerMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/active_quote_guest_not_default_store.php
|
||||
*
|
||||
*/
|
||||
public function testGetCartWithNotExistingStore()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Requested store is not found');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1_not_default_store_guest');
|
||||
|
||||
$headerMap['Store'] = 'not_existing_store';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlQuery($query, [], '', $headerMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "{$maskedQuoteId}") {
|
||||
id
|
||||
items {
|
||||
id
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
stock_status
|
||||
}
|
||||
prices {
|
||||
price {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
errors {
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for getting selected payment method from cart
|
||||
*/
|
||||
class GetSelectedPaymentMethodTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*
|
||||
*/
|
||||
public function testGetSelectedPaymentMethod()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
$this->assertArrayHasKey('selected_payment_method', $response['cart']);
|
||||
$this->assertArrayHasKey('code', $response['cart']['selected_payment_method']);
|
||||
$this->assertEquals('checkmo', $response['cart']['selected_payment_method']['code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
*/
|
||||
public function testGetSelectedPaymentMethodBeforeSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
$this->assertArrayHasKey('selected_payment_method', $response['cart']);
|
||||
$this->assertArrayHasKey('code', $response['cart']['selected_payment_method']);
|
||||
$this->assertEquals('', $response['cart']['selected_payment_method']['code']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetSelectedPaymentMethodFromNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
'Could not find a cart with ID "non_existent_masked_id"'
|
||||
);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @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/set_checkmo_payment_method.php
|
||||
*/
|
||||
public function testGetSelectedPaymentMethodFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"{$maskedQuoteId}\""
|
||||
);
|
||||
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id:"$maskedQuoteId") {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for get selected shipping method
|
||||
*/
|
||||
class GetSelectedShippingMethodTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testGetSelectedShippingMethod()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
|
||||
|
||||
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('flatrate', $shippingAddress['selected_shipping_method']['carrier_code']);
|
||||
|
||||
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('flatrate', $shippingAddress['selected_shipping_method']['method_code']);
|
||||
|
||||
self::assertArrayHasKey('carrier_title', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('Flat Rate', $shippingAddress['selected_shipping_method']['carrier_title']);
|
||||
|
||||
self::assertArrayHasKey('method_title', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('Fixed', $shippingAddress['selected_shipping_method']['method_title']);
|
||||
|
||||
self::assertArrayHasKey('amount', $shippingAddress['selected_shipping_method']);
|
||||
$amount = $shippingAddress['selected_shipping_method']['amount'];
|
||||
|
||||
self::assertArrayHasKey('value', $amount);
|
||||
self::assertEquals(10, $amount['value']);
|
||||
self::assertArrayHasKey('currency', $amount);
|
||||
self::assertEquals('USD', $amount['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testGetSelectedShippingMethodBeforeSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
|
||||
self::assertNull($shippingAddress['selected_shipping_method']);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testGetSelectedShippingMethodFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testGetGetSelectedShippingMethodIfShippingMethodIsNotSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
self::assertCount(1, $response['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
|
||||
self::assertNull($shippingAddress['selected_shipping_method']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetSelectedShippingMethodOfNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "$maskedQuoteId") {
|
||||
shipping_addresses {
|
||||
available_shipping_methods {
|
||||
carrier_code
|
||||
method_code
|
||||
}
|
||||
selected_shipping_method {
|
||||
carrier_code
|
||||
method_code
|
||||
carrier_title
|
||||
method_title
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for get specified billing address
|
||||
*/
|
||||
class GetSpecifiedBillingAddressTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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_billing_address.php
|
||||
*/
|
||||
public function testGetSpecifiedBillingAddress()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('billing_address', $response['cart']);
|
||||
|
||||
$expectedBillingAddressData = [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Smith',
|
||||
'company' => 'CompanyName',
|
||||
'street' => [
|
||||
'Green str, 67'
|
||||
],
|
||||
'city' => 'CityM',
|
||||
'region' => [
|
||||
'code' => 'AL',
|
||||
'label' => 'Alabama',
|
||||
],
|
||||
'postcode' => '75477',
|
||||
'country' => [
|
||||
'code' => 'US',
|
||||
'label' => 'US',
|
||||
],
|
||||
'telephone' => '3468676',
|
||||
'__typename' => 'BillingCartAddress',
|
||||
];
|
||||
self::assertEquals($expectedBillingAddressData, $response['cart']['billing_address']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testGetSpecifiedBillingAddressIfBillingAddressIsNotSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('billing_address', $response['cart']);
|
||||
self::assertNull($response['cart']['billing_address']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetBillingAddressOfNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_billing_address.php
|
||||
*/
|
||||
public function testGetBillingAddressFromAnotherCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "$maskedQuoteId") {
|
||||
billing_address {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
region
|
||||
{
|
||||
code
|
||||
label
|
||||
}
|
||||
postcode
|
||||
country
|
||||
{
|
||||
code
|
||||
label
|
||||
}
|
||||
telephone
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for get specified shipping address
|
||||
*/
|
||||
class GetSpecifiedShippingAddressTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testGetSpecifiedShippingAddress()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
|
||||
$expectedShippingAddressData = [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Smith',
|
||||
'company' => 'CompanyName',
|
||||
'street' => [
|
||||
'Green str, 67'
|
||||
],
|
||||
'city' => 'CityM',
|
||||
'region' => [
|
||||
'code' => 'AL',
|
||||
'label' => 'Alabama',
|
||||
],
|
||||
'postcode' => '75477',
|
||||
'country' => [
|
||||
'code' => 'US',
|
||||
'label' => 'US',
|
||||
],
|
||||
'telephone' => '3468676',
|
||||
'__typename' => 'ShippingCartAddress',
|
||||
];
|
||||
self::assertEquals($expectedShippingAddressData, current($response['cart']['shipping_addresses']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testGetSpecifiedShippingAddressIfShippingAddressIsNotSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$response = $this->graphQlQuery($query);
|
||||
self::assertArrayHasKey('cart', $response);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['cart']);
|
||||
|
||||
self::assertEquals([], $response['cart']['shipping_addresses']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetShippingAddressOfNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*/
|
||||
public function testGetShippingAddressFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
{
|
||||
cart(cart_id: "$maskedQuoteId") {
|
||||
shipping_addresses {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
region
|
||||
{
|
||||
code
|
||||
label
|
||||
}
|
||||
postcode
|
||||
country
|
||||
{
|
||||
code
|
||||
label
|
||||
}
|
||||
telephone
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
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 merging guest carts
|
||||
*/
|
||||
class MergeCartsTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var QuoteResource
|
||||
*/
|
||||
private $quoteResource;
|
||||
|
||||
/**
|
||||
* @var QuoteFactory
|
||||
*/
|
||||
private $quoteFactory;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteIdInterface
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
|
||||
*/
|
||||
public function testMergeGuestCarts()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The current customer isn\'t authorized.');
|
||||
|
||||
$firstQuote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($firstQuote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
|
||||
|
||||
$secondQuote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load(
|
||||
$secondQuote,
|
||||
'test_order_with_virtual_product_without_address',
|
||||
'reserved_order_id'
|
||||
);
|
||||
|
||||
$firstMaskedId = $this->quoteIdToMaskedId->execute((int)$firstQuote->getId());
|
||||
$secondMaskedId = $this->quoteIdToMaskedId->execute((int)$secondQuote->getId());
|
||||
|
||||
$query = $this->getCartMergeMutation($firstMaskedId, $secondMaskedId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the mergeCart mutation
|
||||
*
|
||||
* @param string $guestQuoteMaskedId
|
||||
* @param string $customerQuoteMaskedId
|
||||
* @return string
|
||||
*/
|
||||
private function getCartMergeMutation(string $guestQuoteMaskedId, string $customerQuoteMaskedId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
mergeCarts(
|
||||
source_cart_id: "{$guestQuoteMaskedId}"
|
||||
destination_cart_id: "{$customerQuoteMaskedId}"
|
||||
){
|
||||
items {
|
||||
quantity
|
||||
product {
|
||||
sku
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\OrderFactory;
|
||||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for placing an order for guest
|
||||
*/
|
||||
class PlaceOrderTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $orderCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @var OrderFactory
|
||||
*/
|
||||
private $orderFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->orderCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
$this->orderFactory = $objectManager->get(OrderFactory::class);
|
||||
$this->registry = $objectManager->get(Registry::class);
|
||||
/** @var ScopeConfigInterface $scopeConfig */
|
||||
$scopeConfig = $objectManager->get(ScopeConfigInterface::class);
|
||||
$scopeConfig->clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*/
|
||||
public function testPlaceOrder()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('placeOrder', $response);
|
||||
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
|
||||
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
|
||||
$orderIncrementId = $response['placeOrder']['order']['order_number'];
|
||||
$order = $this->orderFactory->create();
|
||||
$order->loadByIncrementId($orderIncrementId);
|
||||
$this->assertNotEmpty($order->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*/
|
||||
public function testPlaceOrderWithAutoGroup()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('placeOrder', $response);
|
||||
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
|
||||
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
|
||||
$orderIncrementId = $response['placeOrder']['order']['order_number'];
|
||||
$order = $this->orderFactory->create();
|
||||
$order->loadByIncrementId($orderIncrementId);
|
||||
$this->assertNotEmpty($order->getEmailSent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
|
||||
*/
|
||||
public function testPlaceOrderIfCartIdIsEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_id" is missing');
|
||||
|
||||
$maskedQuoteId = '';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
|
||||
* @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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*
|
||||
*/
|
||||
public function testPlaceOrderWithNoEmail()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest email for cart is missing.');
|
||||
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
*/
|
||||
public function testPlaceOrderWithNoItemsInCart()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage(
|
||||
'Unable to place order: A server error stopped your order from being placed. ' .
|
||||
'Please try to place your order again'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
*/
|
||||
public function testPlaceOrderWithNoShippingAddress()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage(
|
||||
'Unable to place order: Some addresses can\'t be used due to the configurations for specific countries'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
*/
|
||||
public function testPlaceOrderWithNoShippingMethod()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage(
|
||||
'Unable to place order: The shipping method is missing. Select the shipping method and try again'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testPlaceOrderWithNoBillingAddress()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessageMatches(
|
||||
'/Unable to place order: Please check the billing address information*/'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testPlaceOrderWithNoPaymentMethod()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage('Unable to place order: Enter a valid payment method and try again');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
*/
|
||||
public function testPlaceOrderWithOutOfStockProduct()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage('Unable to place order: Some of the products are out of stock');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture cataloginventory/options/enable_inventory_check 0
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/set_simple_product_out_of_stock.php
|
||||
*/
|
||||
public function testPlaceOrderWithOutOfStockProductWithDisabledInventoryCheck()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage('Unable to place order: Enter a valid payment method and try again.');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 0
|
||||
* @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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*/
|
||||
public function testPlaceOrderOfCustomerCart()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessageMatches('/The current user cannot perform operations on cart*/');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test place order with gift message options
|
||||
*
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @magentoConfigFixture sales/gift_options/allow_order 1
|
||||
* @magentoConfigFixture default_store customer/create_account/auto_group_assign 1
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_gift_options.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*/
|
||||
public function testPlaceOrderWithGiftMessage()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('placeOrder', $response);
|
||||
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
|
||||
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
|
||||
$orderIncrementId = $response['placeOrder']['order']['order_number'];
|
||||
$order = $this->orderFactory->create();
|
||||
$order->loadByIncrementId($orderIncrementId);
|
||||
$this->assertNotEmpty($order->getGiftMessageId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
placeOrder(input: {cart_id: "{$maskedQuoteId}"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', true);
|
||||
|
||||
$orderCollection = $this->orderCollectionFactory->create();
|
||||
foreach ($orderCollection as $order) {
|
||||
$this->orderRepository->delete($order);
|
||||
}
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', false);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Check removing of the coupon from guest cart
|
||||
*/
|
||||
class RemoveCouponFromCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.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/apply_coupon.php
|
||||
*/
|
||||
public function testRemoveCouponFromCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('removeCouponFromCart', $response);
|
||||
self::assertNull($response['removeCouponFromCart']['cart']['applied_coupon']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testRemoveCouponFromCartIfCartIdIsEmpty()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_id" is missing');
|
||||
|
||||
$maskedQuoteId = '';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testRemoveCouponFromNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*/
|
||||
public function testRemoveCouponFromEmptyCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Cart does not contain products');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testRemoveCouponFromCartIfCouponWasNotSet()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('removeCouponFromCart', $response);
|
||||
self::assertNull($response['removeCouponFromCart']['cart']['applied_coupon']);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/discount_10percent_generalusers.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/apply_coupon.php
|
||||
*/
|
||||
public function testRemoveCouponFromCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId);
|
||||
|
||||
self::expectExceptionMessage('The current user cannot perform operations on cart "' . $maskedQuoteId . '"');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
removeCouponFromCart(input: {cart_id: "{$maskedQuoteId}"}) {
|
||||
cart {
|
||||
applied_coupon {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
<?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\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for removeItemFromCartTest mutation
|
||||
*/
|
||||
class RemoveItemFromCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var GetQuoteItemIdByReservedQuoteIdAndSku
|
||||
*/
|
||||
private $getQuoteItemIdByReservedQuoteIdAndSku;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->getQuoteItemIdByReservedQuoteIdAndSku = $objectManager->get(
|
||||
GetQuoteItemIdByReservedQuoteIdAndSku::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
|
||||
*/
|
||||
public function testRemoveItemFromCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$itemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $itemId);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
$this->assertArrayHasKey('removeItemFromCart', $response);
|
||||
$this->assertArrayHasKey('cart', $response['removeItemFromCart']);
|
||||
$this->assertCount(0, $response['removeItemFromCart']['cart']['items']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testRemoveItemFromNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$query = $this->getQuery('non_existent_masked_id', 1);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testRemoveNonExistentItem()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$notExistentItemId = 999;
|
||||
|
||||
$this->expectExceptionMessage("The cart doesn't contain the item");
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $notExistentItemId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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/Checkout/_files/quote_with_virtual_product_saved.php
|
||||
*/
|
||||
public function testRemoveItemIfItemIsNotBelongToCart()
|
||||
{
|
||||
$firstQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$secondQuoteItemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute(
|
||||
'test_order_with_virtual_product_without_address',
|
||||
'virtual-product'
|
||||
);
|
||||
|
||||
$this->expectExceptionMessage("The cart doesn't contain the item");
|
||||
|
||||
$query = $this->getQuery($firstQuoteMaskedId, $secondQuoteItemId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*/
|
||||
public function testRemoveItemFromCustomerCart()
|
||||
{
|
||||
$customerQuoteMaskedId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$customerQuoteItemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');
|
||||
|
||||
$this->expectExceptionMessage("The current user cannot perform operations on cart \"$customerQuoteMaskedId\"");
|
||||
|
||||
$query = $this->getQuery($customerQuoteMaskedId, $customerQuoteItemId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testRemoveItemWithEmptyCartId()
|
||||
{
|
||||
$cartId = "";
|
||||
$cartItemId = $this->getQuoteItemIdByReservedQuoteIdAndSku->execute('test_quote', 'simple_product');
|
||||
|
||||
$this->expectExceptionMessage("Required parameter \"cart_id\" is missing.");
|
||||
|
||||
$query = $this->getQuery($cartId, $cartItemId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testRemoveItemWithZeroCartItemId()
|
||||
{
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$cartItemId = 0;
|
||||
|
||||
$this->expectExceptionMessage("Required parameter \"cart_item_id\" is missing.");
|
||||
|
||||
$query = $this->getQuery($cartId, $cartItemId);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param int $itemId
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, int $itemId): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
removeItemFromCart(
|
||||
input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
cart_item_id: {$itemId}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+637
@@ -0,0 +1,637 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for set billing address on cart mutation
|
||||
*/
|
||||
class SetBillingAddressOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting the billing address on the cart by providing address input information.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testSetNewBillingAddress()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
|
||||
$cartResponse = $response['setBillingAddressOnCart']['cart'];
|
||||
self::assertArrayHasKey('billing_address', $cartResponse);
|
||||
$billingAddressResponse = $cartResponse['billing_address'];
|
||||
$this->assertNewAddressFields($billingAddressResponse);
|
||||
$this->assertNewAddressFields($billingAddressResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the "use_for_shipping" option sets the provided billing address for shipping as well.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testSetNewBillingAddressWithUseForShipping()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
use_for_shipping: true
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
shipping_addresses {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
|
||||
$cartResponse = $response['setBillingAddressOnCart']['cart'];
|
||||
self::assertArrayHasKey('billing_address', $cartResponse);
|
||||
$billingAddressResponse = $cartResponse['billing_address'];
|
||||
self::assertArrayHasKey('shipping_addresses', $cartResponse);
|
||||
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
|
||||
$this->assertNewAddressFields($billingAddressResponse);
|
||||
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a guest cannot set the billing address on a logged-in customer's cart.
|
||||
*
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testSetBillingAddressToCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a guest cannot use a logged-in customer's saved address as the billing address on their own cart.
|
||||
*
|
||||
* _security
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
public function testSetBillingAddressFromAddressBook()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The current customer isn\'t authorized.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
customer_address_id: 1
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a guest cannot set the billing address on a cart that does not exist.
|
||||
*/
|
||||
public function testSetBillingAddressOnNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an error is thrown when the street information exceeds the maximum number of allowed lines.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testSetBillingAddressRedundantStreetLine()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2", "test street 3"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
firstname
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
self::expectExceptionMessage('"Street Address" cannot contain more than 2 lines.');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that setting a new billing address succeeds with a lower case "country_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
|
||||
*/
|
||||
public function testSetBillingAddressWithLowerCaseCountry()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "us"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
|
||||
$cartResponse = $response['setBillingAddressOnCart']['cart'];
|
||||
self::assertArrayHasKey('billing_address', $cartResponse);
|
||||
$billingAddressResponse = $cartResponse['billing_address'];
|
||||
$this->assertNewAddressFields($billingAddressResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an error is thrown when a billing address is not provided.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testSetBillingAddressWithoutProvidingAddress()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
use_for_shipping: true
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
self::expectExceptionMessage(
|
||||
'The billing address must contain either "customer_address_id", "address", or "same_as_shipping".'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the "same_as_shipping" option uses the cart's existing shipping address for the billing address.
|
||||
*
|
||||
* Ignores any address input as well as the "use_for_shipping" option when "same_as_shipping" is true.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testSetBillingAddressWithSameAsShipping()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
same_as_shipping: true
|
||||
use_for_shipping: true
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
shipping_addresses {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
|
||||
$cartResponse = $response['setBillingAddressOnCart']['cart'];
|
||||
|
||||
// Assert billing address has been set according to the cart's shipping address
|
||||
self::assertArrayHasKey('billing_address', $cartResponse);
|
||||
$billingAddressResponse = $cartResponse['billing_address'];
|
||||
$this->assertNewAddressFieldsFromShippingAddress($billingAddressResponse);
|
||||
|
||||
// Assert the shipping address is unchanged
|
||||
self::assertArrayHasKey('shipping_addresses', $cartResponse);
|
||||
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
|
||||
$this->assertNewAddressFieldsFromShippingAddress($shippingAddressResponse, 'ShippingCartAddress');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the "same_as_shipping" option cannot be used when a shipping address has not been set on the cart.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function testSetBillingAddressWithSameAsShippingWithoutShippingAddressOnCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
same_as_shipping: true
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
self::expectExceptionMessage(
|
||||
'Could not use the "same_as_shipping" option, because the shipping address has not been set.'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the "same_as_shipping" option cannot be used when multi-shipping is applied.
|
||||
*
|
||||
* @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_multishipping_with_two_shipping_addresses.php
|
||||
*/
|
||||
public function testSetBillingAddressWithSameAsShippingAndMultishipping()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setBillingAddressOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
billing_address: {
|
||||
same_as_shipping: true
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
billing_address {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
self::expectExceptionMessage(
|
||||
'Could not use the "same_as_shipping" option, because multiple shipping addresses have been set.'
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify all the whitelisted fields for a New Address Object
|
||||
*
|
||||
* @param array $addressResponse
|
||||
* @param string $addressType
|
||||
*/
|
||||
private function assertNewAddressFields(
|
||||
array $addressResponse,
|
||||
string $addressType = 'BillingCartAddress'
|
||||
): void {
|
||||
$assertionMap = [
|
||||
['response_field' => 'firstname', 'expected_value' => 'test firstname'],
|
||||
['response_field' => 'lastname', 'expected_value' => 'test lastname'],
|
||||
['response_field' => 'company', 'expected_value' => 'test company'],
|
||||
['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']],
|
||||
['response_field' => 'city', 'expected_value' => 'test city'],
|
||||
['response_field' => 'postcode', 'expected_value' => '887766'],
|
||||
['response_field' => 'telephone', 'expected_value' => '88776655'],
|
||||
['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']],
|
||||
['response_field' => '__typename', 'expected_value' => $addressType]
|
||||
];
|
||||
|
||||
$this->assertResponseFields($addressResponse, $assertionMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the fields for the specified quote address match the shipping address from the fixture.
|
||||
*
|
||||
* Useful for verifying scenarios with the "same_as_shipping" option.
|
||||
*
|
||||
* @param array $addressResponse
|
||||
* @param string $addressType
|
||||
*/
|
||||
private function assertNewAddressFieldsFromShippingAddress(
|
||||
array $addressResponse,
|
||||
string $addressType = 'BillingCartAddress'
|
||||
): void {
|
||||
$assertionMap = [
|
||||
['response_field' => 'firstname', 'expected_value' => 'John'],
|
||||
['response_field' => 'lastname', 'expected_value' => 'Smith'],
|
||||
['response_field' => 'company', 'expected_value' => 'CompanyName'],
|
||||
['response_field' => 'street', 'expected_value' => [0 => 'Green str, 67']],
|
||||
['response_field' => 'city', 'expected_value' => 'CityM'],
|
||||
['response_field' => 'postcode', 'expected_value' => '75477'],
|
||||
['response_field' => 'telephone', 'expected_value' => 3468676],
|
||||
['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']],
|
||||
['response_field' => '__typename', 'expected_value' => $addressType]
|
||||
];
|
||||
|
||||
$this->assertResponseFields($addressResponse, $assertionMap);
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
<?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\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for setGuestEmailOnCart mutation
|
||||
*/
|
||||
class SetGuestEmailOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var QuoteFactory
|
||||
*/
|
||||
private $quoteFactory;
|
||||
|
||||
/**
|
||||
* @var QuoteResource
|
||||
*/
|
||||
private $quoteResource;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
$this->quoteResource = $objectManager->get(QuoteResource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*/
|
||||
public function testSetGuestEmailOnCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$email = 'some@user.com';
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $email);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
$this->assertArrayHasKey('setGuestEmailOnCart', $response);
|
||||
$this->assertArrayHasKey('cart', $response['setGuestEmailOnCart']);
|
||||
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['email']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*/
|
||||
public function testSetGuestEmailOnCartWithDifferentEmailAddress()
|
||||
{
|
||||
$reservedOrderId = 'test_quote';
|
||||
$secondEmail = 'attempt2@example.com';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedOrderId);
|
||||
|
||||
$email = 'attempt1@example.com';
|
||||
$query = $this->getQuery($maskedQuoteId, $email);
|
||||
$this->graphQlMutation($query);
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $secondEmail);
|
||||
$this->graphQlMutation($query);
|
||||
|
||||
$quote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($quote, $reservedOrderId, 'reserved_order_id');
|
||||
$addresses = $quote->getAddressesCollection();
|
||||
$this->assertEquals(2, $addresses->count());
|
||||
foreach ($addresses as $address) {
|
||||
if ($address->getAddressType() === Address::ADDRESS_TYPE_SHIPPING) {
|
||||
$this->assertEquals($secondEmail, $address->getEmail());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @magentoApiDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
*/
|
||||
public function testSetGuestEmailOnCustomerCart()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$email = 'some@user.com';
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $email);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*
|
||||
* @dataProvider incorrectEmailDataProvider
|
||||
* @param string $email
|
||||
* @param string $exceptionMessage
|
||||
*/
|
||||
public function testSetGuestEmailOnCartWithIncorrectEmail(
|
||||
string $email,
|
||||
string $exceptionMessage
|
||||
) {
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $email);
|
||||
$this->expectExceptionMessage($exceptionMessage);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function incorrectEmailDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'wrong_email' => ['some', 'Invalid email format'],
|
||||
'no_email' => ['', 'Required parameter "email" is missing'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testSetGuestEmailOnNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$email = 'some@user.com';
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $email);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testSetGuestEmailWithEmptyCartId()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Required parameter "cart_id" is missing');
|
||||
|
||||
$maskedQuoteId = '';
|
||||
$email = 'some@user.com';
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $email);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns GraphQl mutation query for setting email address for a guest
|
||||
*
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $email
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, string $email): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
setGuestEmailOnCart(input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
email: "$email"
|
||||
}) {
|
||||
cart {
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
<?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(): void
|
||||
{
|
||||
$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
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
*
|
||||
* @param string $methodCode
|
||||
* @param string $methodTitle
|
||||
* @dataProvider offlinePaymentMethodDataProvider
|
||||
*/
|
||||
public function testSetOfflinePaymentMethod(string $methodCode, string $methodTitle)
|
||||
{
|
||||
$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']);
|
||||
|
||||
$selectedPaymentMethod = $response['setPaymentMethodOnCart']['cart']['selected_payment_method'];
|
||||
self::assertArrayHasKey('code', $selectedPaymentMethod);
|
||||
self::assertEquals($methodCode, $selectedPaymentMethod['code']);
|
||||
|
||||
self::assertArrayHasKey('title', $selectedPaymentMethod);
|
||||
self::assertEquals($methodTitle, $selectedPaymentMethod['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function offlinePaymentMethodDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'check_mo' => [Checkmo::PAYMENT_METHOD_CHECKMO_CODE, 'Check / Money order'],
|
||||
'bank_transfer' => [Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE, 'Bank Transfer Payment'],
|
||||
'cash_on_delivery' => [Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE, 'Cash On Delivery'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
*/
|
||||
public function testSetPurchaseOrderPaymentMethod()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE;
|
||||
$methodTitle = 'Purchase Order';
|
||||
$poNumber = 'abc123';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "{$maskedQuoteId}",
|
||||
payment_method: {
|
||||
code: "{$methodCode}"
|
||||
purchase_order_number: "{$poNumber}"
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
title
|
||||
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']);
|
||||
|
||||
$selectedPaymentMethod = $response['setPaymentMethodOnCart']['cart']['selected_payment_method'];
|
||||
self::assertArrayHasKey('code', $selectedPaymentMethod);
|
||||
self::assertEquals($methodCode, $selectedPaymentMethod['code']);
|
||||
|
||||
self::assertArrayHasKey('title', $selectedPaymentMethod);
|
||||
self::assertEquals($methodTitle, $selectedPaymentMethod['title']);
|
||||
|
||||
self::assertArrayHasKey('purchase_order_number', $selectedPaymentMethod);
|
||||
self::assertEquals($poNumber, $selectedPaymentMethod['purchase_order_number']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for setting offline shipping methods on cart
|
||||
*/
|
||||
class SetOfflineShippingMethodsOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php
|
||||
*
|
||||
* @param string $carrierCode
|
||||
* @param string $methodCode
|
||||
* @param string $carrierTitle
|
||||
* @param string $methodTitle
|
||||
* @param array $amount
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
* @dataProvider offlineShippingMethodDataProvider
|
||||
*/
|
||||
public function testSetOfflineShippingMethod(
|
||||
string $carrierCode,
|
||||
string $methodCode,
|
||||
string $carrierTitle,
|
||||
string $methodTitle,
|
||||
array $amount
|
||||
) {
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery(
|
||||
$maskedQuoteId,
|
||||
$methodCode,
|
||||
$carrierCode
|
||||
);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
|
||||
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
|
||||
|
||||
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($carrierCode, $shippingAddress['selected_shipping_method']['carrier_code']);
|
||||
|
||||
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['method_code']);
|
||||
|
||||
self::assertArrayHasKey('carrier_title', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($carrierTitle, $shippingAddress['selected_shipping_method']['carrier_title']);
|
||||
|
||||
self::assertArrayHasKey('method_title', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($methodTitle, $shippingAddress['selected_shipping_method']['method_title']);
|
||||
|
||||
self::assertArrayHasKey('amount', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($amount, $shippingAddress['selected_shipping_method']['amount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function offlineShippingMethodDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'flatrate_flatrate' => [
|
||||
'flatrate',
|
||||
'flatrate',
|
||||
'Flat Rate',
|
||||
'Fixed',
|
||||
['value' => 10, 'currency' => 'USD'],
|
||||
],
|
||||
'tablerate_bestway' => [
|
||||
'tablerate',
|
||||
'bestway',
|
||||
'Best Way',
|
||||
'Table Rate',
|
||||
['value' => 10, 'currency' => 'USD'],
|
||||
],
|
||||
'freeshipping_freeshipping' => [
|
||||
'freeshipping',
|
||||
'freeshipping',
|
||||
'Free Shipping',
|
||||
'Free',
|
||||
['value' => 0, 'currency' => 'USD'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $shippingMethodCode
|
||||
* @param string $shippingCarrierCode
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(
|
||||
string $maskedQuoteId,
|
||||
string $shippingMethodCode,
|
||||
string $shippingCarrierCode
|
||||
): string {
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
setShippingMethodsOnCart(input:
|
||||
{
|
||||
cart_id: "$maskedQuoteId",
|
||||
shipping_methods: [{
|
||||
carrier_code: "$shippingCarrierCode"
|
||||
method_code: "$shippingMethodCode"
|
||||
}]
|
||||
}) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
selected_shipping_method {
|
||||
carrier_code
|
||||
method_code
|
||||
carrier_title
|
||||
method_title
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+307
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\OfflinePayments\Model\Checkmo;
|
||||
use Magento\OfflinePayments\Model\Purchaseorder;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for setting payment method and placing an order by guest
|
||||
*/
|
||||
class SetPaymentMethodAndPlaceOrderTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $orderCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var Registry
|
||||
*/
|
||||
private $registry;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->orderCollectionFactory = $objectManager->get(CollectionFactory::class);
|
||||
$this->orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testSetPaymentOnCartWithSimpleProduct()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('setPaymentMethodAndPlaceOrder', $response);
|
||||
self::assertArrayHasKey('order', $response['setPaymentMethodAndPlaceOrder']);
|
||||
self::assertArrayHasKey('order_number', $response['setPaymentMethodAndPlaceOrder']['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
*
|
||||
*/
|
||||
public function testSetPaymentOnCartWithSimpleProductAndWithoutAddress()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The shipping address is missing. Set the address and try again.');
|
||||
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
*/
|
||||
public function testSetPaymentOnCartWithVirtualProduct()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('setPaymentMethodAndPlaceOrder', $response);
|
||||
self::assertArrayHasKey('order', $response['setPaymentMethodAndPlaceOrder']);
|
||||
self::assertArrayHasKey('order_number', $response['setPaymentMethodAndPlaceOrder']['order']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
*
|
||||
*/
|
||||
public function testSetNonExistentPaymentMethod()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The requested Payment Method is not available.');
|
||||
|
||||
$methodCode = 'noway';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testSetPaymentOnNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_checkmo_payment_method.php
|
||||
*
|
||||
*/
|
||||
public function testPlaceOrderWithNoEmail()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Guest email for cart is missing.');
|
||||
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*/
|
||||
public function testSetPaymentMethodToCustomerCart()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
*/
|
||||
public function testSetDisabledPaymentOnCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The requested Payment Method is not available.');
|
||||
|
||||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testPlaceOrderWitMissingCartId()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = "";
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"Required parameter \"cart_id\" is missing"
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.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/set_new_billing_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testPlaceOrderWithMissingPaymentMethod()
|
||||
{
|
||||
$methodCode = "";
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"Required parameter \"code\" for \"payment_method\" is missing."
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $methodCode
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(
|
||||
string $maskedQuoteId,
|
||||
string $methodCode
|
||||
) : string {
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodAndPlaceOrder(input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
payment_method: {
|
||||
code: "$methodCode"
|
||||
}
|
||||
}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', true);
|
||||
|
||||
$orderCollection = $this->orderCollectionFactory->create();
|
||||
foreach ($orderCollection as $order) {
|
||||
$this->orderRepository->delete($order);
|
||||
}
|
||||
$this->registry->unregister('isSecureArea');
|
||||
$this->registry->register('isSecureArea', false);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
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 payment methods on cart by guest
|
||||
*/
|
||||
class SetPaymentMethodOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testSetPaymentOnCartWithSimpleProduct()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$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::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
|
||||
*
|
||||
*/
|
||||
public function testSetPaymentOnCartWithSimpleProductAndWithoutAddress()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The shipping address is missing. Set the address and try again.');
|
||||
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
|
||||
*/
|
||||
public function testSetPaymentOnCartWithVirtualProduct()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$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::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
|
||||
*
|
||||
*/
|
||||
public function testSetNonExistentPaymentMethod()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The requested Payment Method is not available.');
|
||||
|
||||
$methodCode = 'noway';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testSetPaymentOnNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*/
|
||||
public function testSetPaymentMethodToCustomerCart()
|
||||
{
|
||||
$methodCode = Checkmo::PAYMENT_METHOD_CHECKMO_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $message
|
||||
* @dataProvider dataProviderSetPaymentMethodWithoutRequiredParameters
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSetPaymentMethodWithoutRequiredParameters(string $input, string $message)
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(
|
||||
input: {
|
||||
{$input}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->expectExceptionMessage($message);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderSetPaymentMethodWithoutRequiredParameters(): array
|
||||
{
|
||||
return [
|
||||
'missed_cart_id' => [
|
||||
'cart_id: "", payment_method: {code: "' . Checkmo::PAYMENT_METHOD_CHECKMO_CODE . '"}',
|
||||
'Required parameter "cart_id" is missing.'
|
||||
],
|
||||
'missed_payment_method_code' => [
|
||||
'cart_id: "cart_id_value", payment_method: {code: ""}',
|
||||
'Required parameter "code" for "payment_method" is missing.'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
* @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/set_checkmo_payment_method.php
|
||||
*/
|
||||
public function testReSetPayment()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$methodCode = Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE;
|
||||
$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
|
||||
*/
|
||||
public function testSetDisabledPaymentOnCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The requested Payment Method is not available.');
|
||||
|
||||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $methodCode);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
<?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\Purchaseorder;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for setting Purchase Order payment method on cart by guest
|
||||
*/
|
||||
class SetPurchaseOrderPaymentMethodOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
*/
|
||||
public function testSetPurchaseOrderPaymentMethodOnCartWithSimpleProduct()
|
||||
{
|
||||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$purchaseOrderNumber = '123456';
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
payment_method: {
|
||||
code: "$methodCode"
|
||||
purchase_order_number: "$purchaseOrderNumber"
|
||||
}
|
||||
}) {
|
||||
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::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']);
|
||||
self::assertEquals(
|
||||
$purchaseOrderNumber,
|
||||
$response['setPaymentMethodOnCart']['cart']['selected_payment_method']['purchase_order_number']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @magentoConfigFixture default_store payment/banktransfer/active 1
|
||||
* @magentoConfigFixture default_store payment/cashondelivery/active 1
|
||||
* @magentoConfigFixture default_store payment/checkmo/active 1
|
||||
* @magentoConfigFixture default_store payment/purchaseorder/active 1
|
||||
*
|
||||
*/
|
||||
public function testSetPurchaseOrderPaymentMethodOnCartWithoutPurchaseOrderNumber()
|
||||
{
|
||||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE;
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
payment_method: {
|
||||
code: "$methodCode"
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
self::assertArrayHasKey('setPaymentMethodOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']);
|
||||
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']);
|
||||
self::assertEquals(
|
||||
$methodCode,
|
||||
$response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
self::assertArrayNotHasKey(
|
||||
'purchase_order_number',
|
||||
$response['setPaymentMethodOnCart']['cart']['selected_payment_method']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
public function testSetDisabledPurchaseOrderPaymentMethodOnCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The requested Payment Method is not available.');
|
||||
|
||||
$methodCode = Purchaseorder::PAYMENT_METHOD_PURCHASEORDER_CODE;
|
||||
$purchaseOrderNumber = '123456';
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
payment_method: {
|
||||
code: "$methodCode"
|
||||
purchase_order_number: "$purchaseOrderNumber"
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
purchase_order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
}
|
||||
+481
@@ -0,0 +1,481 @@
|
||||
<?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\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for set shipping addresses on cart mutation
|
||||
*/
|
||||
class SetShippingAddressOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testSetNewShippingAddressOnCartWithSimpleProduct()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
customer_notes: "Test note"
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
firstname
|
||||
lastname
|
||||
company
|
||||
street
|
||||
city
|
||||
postcode
|
||||
telephone
|
||||
country {
|
||||
code
|
||||
label
|
||||
}
|
||||
__typename
|
||||
customer_notes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('cart', $response['setShippingAddressesOnCart']);
|
||||
$cartResponse = $response['setShippingAddressesOnCart']['cart'];
|
||||
self::assertArrayHasKey('shipping_addresses', $cartResponse);
|
||||
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
|
||||
$this->assertNewShippingAddressFields($shippingAddressResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
|
||||
*
|
||||
*/
|
||||
public function testSetNewShippingAddressOnCartWithVirtualProduct()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Shipping address is not allowed on cart: cart contains no items for shipment.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
public function testSetShippingAddressFromAddressBook()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The current customer isn\'t authorized.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
customer_address_id: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
public function testSetShippingAddressToCustomerCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
customer_address_id: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
postcode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testSetNewShippingAddressOnCartWithRedundantStreetLine()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2", "test street 3"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
firstname
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
self::expectExceptionMessage('"Street Address" cannot contain more than 2 lines.');
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
public function testSetMultipleNewShippingAddresses()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('You cannot specify multiple shipping addresses.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
},
|
||||
{
|
||||
address: {
|
||||
firstname: "test firstname 2"
|
||||
lastname: "test lastname 2"
|
||||
company: "test company 2"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testSetShippingAddressOnNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$maskedQuoteId = 'non_existent_masked_id';
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId"
|
||||
shipping_addresses: {
|
||||
address: {
|
||||
firstname: "test firstname"
|
||||
lastname: "test lastname"
|
||||
company: "test company"
|
||||
street: ["test street 1", "test street 2"]
|
||||
city: "test city"
|
||||
region: "AL"
|
||||
postcode: "887766"
|
||||
country_code: "US"
|
||||
telephone: "88776655"
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
city
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testSetShippingAddressWithLowerCaseCountry()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "John"
|
||||
lastname: "Doe"
|
||||
street: ["6161 West Centinella Avenue"]
|
||||
city: "Culver City"
|
||||
region: "CA"
|
||||
postcode: "90230"
|
||||
country_code: "us"
|
||||
telephone: "555-555-55-55"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
region {
|
||||
code
|
||||
}
|
||||
country {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$result = $this->graphQlMutation($query);
|
||||
|
||||
self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
|
||||
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
|
||||
|
||||
$this->assertEquals('US', $address['country']['code']);
|
||||
$this->assertEquals('CA', $address['region']['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
|
||||
*/
|
||||
public function testSetShippingAddressWithLowerCaseRegion()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingAddressesOnCart(
|
||||
input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
shipping_addresses: [
|
||||
{
|
||||
address: {
|
||||
firstname: "John"
|
||||
lastname: "Doe"
|
||||
street: ["6161 West Centinella Avenue"]
|
||||
city: "Culver City"
|
||||
region: "ca"
|
||||
postcode: "90230"
|
||||
country_code: "US"
|
||||
telephone: "555-555-55-55"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
region {
|
||||
code
|
||||
}
|
||||
country {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$result = $this->graphQlMutation($query);
|
||||
|
||||
self::assertCount(1, $result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
|
||||
$address = reset($result['setShippingAddressesOnCart']['cart']['shipping_addresses']);
|
||||
|
||||
$this->assertEquals('US', $address['country']['code']);
|
||||
$this->assertEquals('CA', $address['region']['code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the all the whitelisted fields for a New Address Object
|
||||
*
|
||||
* @param array $shippingAddressResponse
|
||||
*/
|
||||
private function assertNewShippingAddressFields(array $shippingAddressResponse): void
|
||||
{
|
||||
$assertionMap = [
|
||||
['response_field' => 'firstname', 'expected_value' => 'test firstname'],
|
||||
['response_field' => 'lastname', 'expected_value' => 'test lastname'],
|
||||
['response_field' => 'company', 'expected_value' => 'test company'],
|
||||
['response_field' => 'street', 'expected_value' => [0 => 'test street 1', 1 => 'test street 2']],
|
||||
['response_field' => 'city', 'expected_value' => 'test city'],
|
||||
['response_field' => 'postcode', 'expected_value' => '887766'],
|
||||
['response_field' => 'telephone', 'expected_value' => '88776655'],
|
||||
['response_field' => 'country', 'expected_value' => ['code' => 'US', 'label' => 'US']],
|
||||
['response_field' => '__typename', 'expected_value' => 'ShippingCartAddress'],
|
||||
['response_field' => 'customer_notes', 'expected_value' => 'Test note']
|
||||
];
|
||||
|
||||
$this->assertResponseFields($shippingAddressResponse, $assertionMap);
|
||||
}
|
||||
}
|
||||
+373
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\GraphQlAbstract;
|
||||
|
||||
/**
|
||||
* Test for setting shipping methods on cart for guest
|
||||
*/
|
||||
class SetShippingMethodsOnCartTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var GetMaskedQuoteIdByReservedOrderId
|
||||
*/
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$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
|
||||
*/
|
||||
public function testSetShippingMethodOnCartWithSimpleProduct()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$carrierCode = 'flatrate';
|
||||
$methodCode = 'flatrate';
|
||||
|
||||
$query = $this->getQuery(
|
||||
$maskedQuoteId,
|
||||
$methodCode,
|
||||
$carrierCode
|
||||
);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
|
||||
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
|
||||
|
||||
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('flatrate', $shippingAddress['selected_shipping_method']['carrier_code']);
|
||||
|
||||
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('flatrate', $shippingAddress['selected_shipping_method']['method_code']);
|
||||
|
||||
self::assertArrayHasKey('carrier_title', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('Flat Rate', $shippingAddress['selected_shipping_method']['carrier_title']);
|
||||
|
||||
self::assertArrayHasKey('method_title', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals('Fixed', $shippingAddress['selected_shipping_method']['method_title']);
|
||||
|
||||
self::assertArrayHasKey('amount', $shippingAddress['selected_shipping_method']);
|
||||
$amount = $shippingAddress['selected_shipping_method']['amount'];
|
||||
|
||||
self::assertArrayHasKey('value', $amount);
|
||||
self::assertEquals(10, $amount['value']);
|
||||
self::assertArrayHasKey('currency', $amount);
|
||||
self::assertEquals('USD', $amount['currency']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipping address for quote will be created automatically BUT with NULL values (considered that address
|
||||
* is not set)
|
||||
*
|
||||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.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/add_virtual_product.php
|
||||
*
|
||||
*/
|
||||
public function testSetShippingMethodOnCartWithSimpleProductAndWithoutAddress()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The shipping address is missing. Set the address and try again.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$carrierCode = 'flatrate';
|
||||
$methodCode = 'flatrate';
|
||||
|
||||
$query = $this->getQuery(
|
||||
$maskedQuoteId,
|
||||
$methodCode,
|
||||
$carrierCode
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @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/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testReSetShippingMethod()
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$carrierCode = 'freeshipping';
|
||||
$methodCode = 'freeshipping';
|
||||
|
||||
$query = $this->getQuery(
|
||||
$maskedQuoteId,
|
||||
$methodCode,
|
||||
$carrierCode
|
||||
);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
self::assertArrayHasKey('setShippingMethodsOnCart', $response);
|
||||
self::assertArrayHasKey('cart', $response['setShippingMethodsOnCart']);
|
||||
self::assertArrayHasKey('shipping_addresses', $response['setShippingMethodsOnCart']['cart']);
|
||||
self::assertCount(1, $response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
|
||||
|
||||
$shippingAddress = current($response['setShippingMethodsOnCart']['cart']['shipping_addresses']);
|
||||
self::assertArrayHasKey('selected_shipping_method', $shippingAddress);
|
||||
|
||||
self::assertArrayHasKey('carrier_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($carrierCode, $shippingAddress['selected_shipping_method']['carrier_code']);
|
||||
|
||||
self::assertArrayHasKey('method_code', $shippingAddress['selected_shipping_method']);
|
||||
self::assertEquals($methodCode, $shippingAddress['selected_shipping_method']['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
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $message
|
||||
* @dataProvider dataProviderSetShippingMethodWithWrongParameters
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSetShippingMethodWithWrongParameters(string $input, string $message)
|
||||
{
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$input = str_replace('cart_id_value', $maskedQuoteId, $input);
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingMethodsOnCart(input: {
|
||||
{$input}
|
||||
}) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
selected_shipping_method {
|
||||
carrier_code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->expectExceptionMessage($message);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function dataProviderSetShippingMethodWithWrongParameters(): array
|
||||
{
|
||||
return [
|
||||
'shipping_methods_are_empty' => [
|
||||
'cart_id: "cart_id_value" shipping_methods: []',
|
||||
'Required parameter "shipping_methods" is missing'
|
||||
],
|
||||
'empty_carrier_code' => [
|
||||
'cart_id: "cart_id_value", shipping_methods: [{
|
||||
carrier_code: ""
|
||||
method_code: "flatrate"
|
||||
}]',
|
||||
'Required parameter "carrier_code" is missing.'
|
||||
],
|
||||
'non_existent_carrier_code' => [
|
||||
'cart_id: "cart_id_value", shipping_methods: [{
|
||||
carrier_code: "wrong-carrier-code"
|
||||
method_code: "flatrate"
|
||||
}]',
|
||||
'Carrier with such method not found: wrong-carrier-code, flatrate'
|
||||
],
|
||||
'empty_method_code' => [
|
||||
'cart_id: "cart_id_value", shipping_methods: [{
|
||||
carrier_code: "flatrate"
|
||||
method_code: ""
|
||||
}]',
|
||||
'Required parameter "method_code" is missing.'
|
||||
],
|
||||
'non_existent_method_code' => [
|
||||
'cart_id: "cart_id_value", shipping_methods: [{
|
||||
carrier_code: "flatrate"
|
||||
method_code: "wrong-carrier-code"
|
||||
}]',
|
||||
'Carrier with such method not found: flatrate, wrong-carrier-code'
|
||||
],
|
||||
'non_existent_shopping_cart' => [
|
||||
'cart_id: "non_existent_masked_id", shipping_methods: [{
|
||||
carrier_code: "flatrate"
|
||||
method_code: "flatrate"
|
||||
}]',
|
||||
'Could not find a cart with ID "non_existent_masked_id"'
|
||||
],
|
||||
'disabled_shipping_method' => [
|
||||
'cart_id: "cart_id_value", shipping_methods: [{
|
||||
carrier_code: "freeshipping"
|
||||
method_code: "freeshipping"
|
||||
}]',
|
||||
'Carrier with such method not found: freeshipping, freeshipping'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store carriers/flatrate/active 1
|
||||
* @magentoConfigFixture default_store carriers/tablerate/active 1
|
||||
* @magentoConfigFixture default_store carriers/freeshipping/active 1
|
||||
* @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
|
||||
*/
|
||||
public function testSetMultipleShippingMethods()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('You cannot specify multiple shipping methods.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setShippingMethodsOnCart(input: {
|
||||
cart_id: "{$maskedQuoteId}",
|
||||
shipping_methods: [
|
||||
{
|
||||
carrier_code: "flatrate"
|
||||
method_code: "flatrate"
|
||||
}
|
||||
{
|
||||
carrier_code: "flatrate"
|
||||
method_code: "flatrate"
|
||||
}
|
||||
]
|
||||
}) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
selected_shipping_method {
|
||||
carrier_code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* _security
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
public function testSetShippingMethodToCustomerCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$carrierCode = 'flatrate';
|
||||
$methodCode = 'flatrate';
|
||||
$query = $this->getQuery(
|
||||
$maskedQuoteId,
|
||||
$methodCode,
|
||||
$carrierCode
|
||||
);
|
||||
|
||||
$this->expectExceptionMessage(
|
||||
"The current user cannot perform operations on cart \"$maskedQuoteId\""
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/quote_with_address.php
|
||||
*
|
||||
*/
|
||||
public function testSetShippingMethodOnAnEmptyCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('The shipping method can\'t be set for an empty cart. Add an item to cart and try again.');
|
||||
|
||||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
$carrierCode = 'flatrate';
|
||||
$methodCode = 'flatrate';
|
||||
|
||||
$query = $this->getQuery(
|
||||
$maskedQuoteId,
|
||||
$methodCode,
|
||||
$carrierCode
|
||||
);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param string $shippingMethodCode
|
||||
* @param string $shippingCarrierCode
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(
|
||||
string $maskedQuoteId,
|
||||
string $shippingMethodCode,
|
||||
string $shippingCarrierCode
|
||||
): string {
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
setShippingMethodsOnCart(input:
|
||||
{
|
||||
cart_id: "$maskedQuoteId",
|
||||
shipping_methods: [{
|
||||
carrier_code: "$shippingCarrierCode"
|
||||
method_code: "$shippingMethodCode"
|
||||
}]
|
||||
}) {
|
||||
cart {
|
||||
shipping_addresses {
|
||||
selected_shipping_method {
|
||||
carrier_code
|
||||
method_code
|
||||
carrier_title
|
||||
method_title
|
||||
amount {
|
||||
value
|
||||
currency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\GraphQl\Quote\Guest;
|
||||
|
||||
use Exception;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
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 updating/removing shopping cart items
|
||||
*/
|
||||
class UpdateCartItemsTest extends GraphQlAbstract
|
||||
{
|
||||
/**
|
||||
* @var QuoteResource
|
||||
*/
|
||||
private $quoteResource;
|
||||
|
||||
/**
|
||||
* @var QuoteFactory
|
||||
*/
|
||||
private $quoteFactory;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteIdInterface
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
/**
|
||||
* @var ProductRepositoryInterface
|
||||
*/
|
||||
private $productRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->quoteResource = $objectManager->get(QuoteResource::class);
|
||||
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
|
||||
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
|
||||
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
*/
|
||||
public function testUpdateCartItemQuantity()
|
||||
{
|
||||
$quote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
|
||||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
|
||||
$itemId = (int)$quote->getItemByProduct($this->productRepository->get('simple'))->getId();
|
||||
$quantity = 2;
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $itemId, $quantity);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
$this->assertArrayHasKey('updateCartItems', $response);
|
||||
$this->assertArrayHasKey('cart', $response['updateCartItems']);
|
||||
|
||||
$responseCart = $response['updateCartItems']['cart'];
|
||||
$item = current($responseCart['items']);
|
||||
|
||||
$this->assertEquals($itemId, $item['id']);
|
||||
$this->assertEquals($quantity, $item['quantity']);
|
||||
|
||||
//Check that update is correctly reflected in cart
|
||||
$cartQuery = $this->getCartQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($cartQuery);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
|
||||
$responseCart = $response['cart'];
|
||||
$item = current($responseCart['items']);
|
||||
|
||||
$this->assertEquals($quantity, $item['quantity']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
*/
|
||||
public function testRemoveCartItemIfQuantityIsZero()
|
||||
{
|
||||
$quote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
|
||||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
|
||||
$itemId = (int)$quote->getItemByProduct($this->productRepository->get('simple'))->getId();
|
||||
$quantity = 0;
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $itemId, $quantity);
|
||||
$response = $this->graphQlMutation($query);
|
||||
|
||||
$this->assertArrayHasKey('updateCartItems', $response);
|
||||
$this->assertArrayHasKey('cart', $response['updateCartItems']);
|
||||
|
||||
$responseCart = $response['updateCartItems']['cart'];
|
||||
$this->assertCount(0, $responseCart['items']);
|
||||
|
||||
//Check that update is correctly reflected in cart
|
||||
$cartQuery = $this->getCartQuery($maskedQuoteId);
|
||||
$response = $this->graphQlQuery($cartQuery);
|
||||
|
||||
$this->assertArrayHasKey('cart', $response);
|
||||
|
||||
$responseCart = $response['cart'];
|
||||
$this->assertCount(0, $responseCart['items']);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testUpdateItemInNonExistentCart()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not find a cart with ID "non_existent_masked_id"');
|
||||
|
||||
$query = $this->getQuery('non_existent_masked_id', 1, 2);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
*/
|
||||
public function testUpdateNonExistentItem()
|
||||
{
|
||||
$quote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
|
||||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
|
||||
$notExistentItemId = 999;
|
||||
|
||||
$this->expectExceptionMessage("Could not find cart item with id: {$notExistentItemId}.");
|
||||
|
||||
$query = $this->getQuery($maskedQuoteId, $notExistentItemId, 2);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
|
||||
*/
|
||||
public function testUpdateItemIfItemIsNotBelongToCart()
|
||||
{
|
||||
$firstQuote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($firstQuote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
|
||||
$firstQuoteMaskedId = $this->quoteIdToMaskedId->execute((int)$firstQuote->getId());
|
||||
|
||||
$secondQuote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load(
|
||||
$secondQuote,
|
||||
'test_order_with_virtual_product_without_address',
|
||||
'reserved_order_id'
|
||||
);
|
||||
$secondQuoteItemId = (int)$secondQuote
|
||||
->getItemByProduct($this->productRepository->get('virtual-product'))
|
||||
->getId();
|
||||
|
||||
$this->expectExceptionMessage("Could not find cart item with id: {$secondQuoteItemId}.");
|
||||
|
||||
$query = $this->getQuery($firstQuoteMaskedId, $secondQuoteItemId, 2);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
|
||||
*/
|
||||
public function testUpdateItemFromCustomerCart()
|
||||
{
|
||||
$customerQuote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($customerQuote, 'test_order_1', 'reserved_order_id');
|
||||
$customerQuoteMaskedId = $this->quoteIdToMaskedId->execute((int)$customerQuote->getId());
|
||||
$customerQuoteItemId = (int)$customerQuote->getItemByProduct($this->productRepository->get('simple'))->getId();
|
||||
|
||||
$this->expectExceptionMessage("The current user cannot perform operations on cart \"$customerQuoteMaskedId\"");
|
||||
|
||||
$query = $this->getQuery($customerQuoteMaskedId, $customerQuoteItemId, 2);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
* @param string $message
|
||||
* @dataProvider dataProviderUpdateWithMissedRequiredParameters
|
||||
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
*/
|
||||
public function testUpdateWithMissedItemRequiredParameters(string $input, string $message)
|
||||
{
|
||||
$quote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($quote, 'test_order_with_simple_product_without_address', 'reserved_order_id');
|
||||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
updateCartItems(input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
{$input}
|
||||
}) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
$this->expectExceptionMessage($message);
|
||||
$this->graphQlMutation($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderUpdateWithMissedRequiredParameters(): array
|
||||
{
|
||||
return [
|
||||
'missed_cart_item_qty' => [
|
||||
'cart_items: [{ cart_item_id: 1 }]',
|
||||
'Required parameter "quantity" for "cart_items" is missing.'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @param int $itemId
|
||||
* @param float $quantity
|
||||
* @return string
|
||||
*/
|
||||
private function getQuery(string $maskedQuoteId, int $itemId, float $quantity): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
updateCartItems(input: {
|
||||
cart_id: "{$maskedQuoteId}"
|
||||
cart_items: [
|
||||
{
|
||||
cart_item_id: {$itemId}
|
||||
quantity: {$quantity}
|
||||
}
|
||||
]
|
||||
}) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maskedQuoteId
|
||||
* @return string
|
||||
*/
|
||||
private function getCartQuery(string $maskedQuoteId)
|
||||
{
|
||||
return <<<QUERY
|
||||
query {
|
||||
cart(cart_id: "{$maskedQuoteId}"){
|
||||
items{
|
||||
product{
|
||||
name
|
||||
}
|
||||
quantity
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store sales/gift_options/allow_items 0
|
||||
* @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateGiftMessageCartForItemNotAllow()
|
||||
{
|
||||
$messageTo = "";
|
||||
$messageFrom = "";
|
||||
$message = "";
|
||||
$query = $this->getUpdateGiftMessageQuery($messageTo, $messageFrom, $message);
|
||||
foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) {
|
||||
self::assertNull($item['gift_message']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store sales/gift_options/allow_items 1
|
||||
* @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateGiftMessageCartForItem()
|
||||
{
|
||||
$messageTo = "Alex";
|
||||
$messageFrom = "Mike";
|
||||
$message = "Best regards";
|
||||
$query = $this->getUpdateGiftMessageQuery($messageTo, $messageFrom, $message);
|
||||
foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) {
|
||||
self::assertArrayHasKey('gift_message', $item);
|
||||
self::assertSame('Alex', $item['gift_message']['to']);
|
||||
self::assertSame('Mike', $item['gift_message']['from']);
|
||||
self::assertSame('Best regards', $item['gift_message']['message']);
|
||||
}
|
||||
$messageTo = "";
|
||||
$messageFrom = "";
|
||||
$message = "";
|
||||
$query = $this->getUpdateGiftMessageQuery($messageTo, $messageFrom, $message);
|
||||
foreach ($this->graphQlMutation($query)['updateCartItems']['cart']['items'] as $item) {
|
||||
self::assertArrayHasKey('gift_message', $item);
|
||||
self::assertSame(null, $item['gift_message']);
|
||||
}
|
||||
}
|
||||
|
||||
private function getUpdateGiftMessageQuery(string $messageTo, string $messageFrom, string $message)
|
||||
{
|
||||
$quote = $this->quoteFactory->create();
|
||||
$this->quoteResource->load($quote, 'test_guest_order_with_gift_message', 'reserved_order_id');
|
||||
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
|
||||
$itemId = (int)$quote->getItemByProduct($this->productRepository->get('simple'))->getId();
|
||||
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
updateCartItems(
|
||||
input: {
|
||||
cart_id: "$maskedQuoteId",
|
||||
cart_items: [
|
||||
{
|
||||
cart_item_id: $itemId
|
||||
quantity: 3
|
||||
gift_message: {
|
||||
to: "$messageTo"
|
||||
from: "$messageFrom"
|
||||
message: "$message"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
) {
|
||||
cart {
|
||||
items {
|
||||
id
|
||||
product {
|
||||
name
|
||||
}
|
||||
quantity
|
||||
... on SimpleCartItem {
|
||||
gift_message {
|
||||
to
|
||||
from
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user