Skip to content

Commit 2aeb874

Browse files
committed
Test case for getting totals with no quote address set
1 parent 2697303 commit 2aeb874

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/CartTotalsTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function testGetCartTotalsWithTaxApplied()
7373

7474
/**
7575
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
76-
* @group last
7776
*/
7877
public function testGetTotalsWithNoTaxApplied()
7978
{
@@ -89,6 +88,26 @@ public function testGetTotalsWithNoTaxApplied()
8988
self::assertEmpty($pricesResponse['applied_taxes']);
9089
}
9190

91+
/**
92+
* The totals calculation is based on quote address.
93+
* But the totals should be calculated even if no address is set
94+
*
95+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_customer_no_address.php
96+
*/
97+
public function testGetCartTotalsWithNoAddressSet()
98+
{
99+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1');
100+
$query = $this->getCartTotalsGraphqlQuery($maskedQuoteId);
101+
$response = $this->sendRequestWithToken($query);
102+
103+
$pricesResponse = $response['cart']['prices'];
104+
self::assertEquals(10, $pricesResponse['grand_total']['value']);
105+
self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']);
106+
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
107+
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
108+
self::assertEmpty($pricesResponse['applied_taxes']);
109+
}
110+
92111
/**
93112
* Generates GraphQl query for retrieving cart totals
94113
*

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ public function testGetTotalsWithNoTaxApplied()
8181
self::assertEmpty($pricesResponse['applied_taxes']);
8282
}
8383

84+
/**
85+
* The totals calculation is based on quote address.
86+
* But the totals should be calculated even if no address is set
87+
*
88+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
89+
*/
90+
public function testGetCartTotalsWithNoAddressSet()
91+
{
92+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_with_simple_product_without_address');
93+
$query = $this->getCartTotalsGraphqlQuery($maskedQuoteId);
94+
$response = $this->graphQlQuery($query);
95+
96+
$pricesResponse = $response['cart']['prices'];
97+
self::assertEquals(10, $pricesResponse['grand_total']['value']);
98+
self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']);
99+
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
100+
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
101+
self::assertEmpty($pricesResponse['applied_taxes']);
102+
}
103+
84104
/**
85105
* Generates GraphQl query for retrieving cart totals
86106
*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Quote\Model\Quote;
8+
use Magento\Quote\Model\QuoteIdMask;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\TestFramework\ObjectManager;
11+
12+
require __DIR__ . '/../../Customer/_files/customer_rollback.php';
13+
require __DIR__ . '/../../../Magento/Catalog/_files/products_rollback.php';
14+
15+
/** @var $objectManager ObjectManager */
16+
$objectManager = Bootstrap::getObjectManager();
17+
$quote = $objectManager->create(Quote::class);
18+
$quote->load('test_order_1', 'reserved_order_id')->delete();
19+
20+
/** @var QuoteIdMask $quoteIdMask */
21+
$quoteIdMask = $objectManager->create(QuoteIdMask::class);
22+
$quoteIdMask->delete($quote->getId());

dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_customer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
$quoteRepository->save($quote);
6060

6161
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
62-
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
63-
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
62+
$quoteIdMask = $objectManager
63+
->get(\Magento\Quote\Model\QuoteIdMaskFactory::class)
6464
->create();
6565
$quoteIdMask->setQuoteId($quote->getId());
6666
$quoteIdMask->setDataChanges(true);

dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_tax_guest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)->setBillingAddress(
4040
$quoteAddress
4141
)->setCheckoutMethod(
42-
'customer'
42+
'guest'
4343
)->setReservedOrderId(
4444
'test_order_tax'
4545
)->addProduct(
@@ -55,8 +55,8 @@
5555
$quoteRepository->save($quote);
5656

5757
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
58-
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
59-
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
58+
$quoteIdMask = $objectManager
59+
->get(\Magento\Quote\Model\QuoteIdMaskFactory::class)
6060
->create();
6161
$quoteIdMask->setQuoteId($quote->getId());
6262
$quoteIdMask->setDataChanges(true);

0 commit comments

Comments
 (0)