Skip to content

Commit 2697303

Browse files
committed
Test coverage for cart with no tax applied
1 parent 8210d82 commit 2697303

File tree

5 files changed

+176
-47
lines changed

5 files changed

+176
-47
lines changed

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

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,62 @@ class CartTotalsTest extends GraphQlAbstract
4242
protected function setUp()
4343
{
4444
$objectManager = Bootstrap::getObjectManager();
45-
$this->quoteResource = $objectManager->create(QuoteResource::class);
46-
$this->quoteFactory = $objectManager->create(QuoteFactory::class);
47-
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
48-
$this->customerTokenService = $objectManager->create(CustomerTokenServiceInterface::class);
45+
$this->quoteResource = $objectManager->get(QuoteResource::class);
46+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
47+
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
48+
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
4949
}
5050

5151
/**
5252
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_customer.php
5353
*/
54-
public function testGetCartTotalsForCustomerWithTaxApplied()
54+
public function testGetCartTotalsWithTaxApplied()
5555
{
5656
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax');
57+
$query = $this->getCartTotalsGraphqlQuery($maskedQuoteId);
58+
$response = $this->sendRequestWithToken($query);
59+
60+
self::assertArrayHasKey('prices', $response['cart']);
61+
$pricesResponse = $response['cart']['prices'];
62+
self::assertEquals(10.83, $pricesResponse['grand_total']['value']);
63+
self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']);
64+
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
65+
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
66+
67+
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
68+
69+
self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']);
70+
self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']);
71+
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
72+
}
73+
74+
/**
75+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
76+
* @group last
77+
*/
78+
public function testGetTotalsWithNoTaxApplied()
79+
{
80+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1');
81+
$query = $this->getCartTotalsGraphqlQuery($maskedQuoteId);
82+
$response = $this->sendRequestWithToken($query);
83+
84+
$pricesResponse = $response['cart']['prices'];
85+
self::assertEquals(20, $pricesResponse['grand_total']['value']);
86+
self::assertEquals(20, $pricesResponse['subtotal_including_tax']['value']);
87+
self::assertEquals(20, $pricesResponse['subtotal_excluding_tax']['value']);
88+
self::assertEquals(20, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
89+
self::assertEmpty($pricesResponse['applied_taxes']);
90+
}
5791

58-
$query = <<<QUERY
92+
/**
93+
* Generates GraphQl query for retrieving cart totals
94+
*
95+
* @param string $maskedQuoteId
96+
* @return string
97+
*/
98+
private function getCartTotalsGraphqlQuery(string $maskedQuoteId): string
99+
{
100+
return <<<QUERY
59101
{
60102
cart(cart_id: "$maskedQuoteId") {
61103
prices {
@@ -86,20 +128,6 @@ public function testGetCartTotalsForCustomerWithTaxApplied()
86128
}
87129
}
88130
QUERY;
89-
$response = $this->sendRequestWithToken($query);
90-
91-
self::assertArrayHasKey('prices', $response['cart']);
92-
$pricesResponse = $response['cart']['prices'];
93-
self::assertEquals(10.83, $pricesResponse['grand_total']['value']);
94-
self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']);
95-
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
96-
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
97-
98-
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
99-
100-
self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']);
101-
self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']);
102-
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
103131
}
104132

105133
/**

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

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\GraphQl\Quote\Guest;
99

10-
use Magento\Integration\Api\CustomerTokenServiceInterface;
1110
use Magento\Quote\Model\QuoteFactory;
1211
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1312
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
@@ -19,11 +18,6 @@
1918
*/
2019
class CartTotalsTest extends GraphQlAbstract
2120
{
22-
/**
23-
* @var CustomerTokenServiceInterface
24-
*/
25-
private $customerTokenService;
26-
2721
/**
2822
* @var QuoteResource
2923
*/
@@ -42,20 +36,60 @@ class CartTotalsTest extends GraphQlAbstract
4236
protected function setUp()
4337
{
4438
$objectManager = Bootstrap::getObjectManager();
45-
$this->quoteResource = $objectManager->create(QuoteResource::class);
46-
$this->quoteFactory = $objectManager->create(QuoteFactory::class);
47-
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
48-
$this->customerTokenService = $objectManager->create(CustomerTokenServiceInterface::class);
39+
$this->quoteResource = $objectManager->get(QuoteResource::class);
40+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
41+
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
4942
}
5043

5144
/**
5245
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_guest.php
5346
*/
54-
public function testGetCartTotalsForCustomerWithTaxApplied()
47+
public function testGetCartTotalsWithTaxApplied()
5548
{
5649
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax');
50+
$query = $this->getCartTotalsGraphqlQuery($maskedQuoteId);
51+
$response = $this->graphQlQuery($query);
52+
53+
self::assertArrayHasKey('prices', $response['cart']);
54+
$pricesResponse = $response['cart']['prices'];
55+
self::assertEquals(10.83, $pricesResponse['grand_total']['value']);
56+
self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']);
57+
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
58+
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
59+
60+
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
61+
62+
self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']);
63+
self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']);
64+
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
65+
}
66+
67+
/**
68+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_guest.php
69+
*/
70+
public function testGetTotalsWithNoTaxApplied()
71+
{
72+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_1');
73+
$query = $this->getCartTotalsGraphqlQuery($maskedQuoteId);
74+
$response = $this->graphQlQuery($query);
5775

58-
$query = <<<QUERY
76+
$pricesResponse = $response['cart']['prices'];
77+
self::assertEquals(10, $pricesResponse['grand_total']['value']);
78+
self::assertEquals(10, $pricesResponse['subtotal_including_tax']['value']);
79+
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
80+
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
81+
self::assertEmpty($pricesResponse['applied_taxes']);
82+
}
83+
84+
/**
85+
* Generates GraphQl query for retrieving cart totals
86+
*
87+
* @param string $maskedQuoteId
88+
* @return string
89+
*/
90+
private function getCartTotalsGraphqlQuery(string $maskedQuoteId): string
91+
{
92+
return <<<QUERY
5993
{
6094
cart(cart_id: "$maskedQuoteId") {
6195
prices {
@@ -86,20 +120,6 @@ public function testGetCartTotalsForCustomerWithTaxApplied()
86120
}
87121
}
88122
QUERY;
89-
$response = $this->graphQlQuery($query);
90-
91-
self::assertArrayHasKey('prices', $response['cart']);
92-
$pricesResponse = $response['cart']['prices'];
93-
self::assertEquals(10.83, $pricesResponse['grand_total']['value']);
94-
self::assertEquals(10.83, $pricesResponse['subtotal_including_tax']['value']);
95-
self::assertEquals(10, $pricesResponse['subtotal_excluding_tax']['value']);
96-
self::assertEquals(10, $pricesResponse['subtotal_with_discount_excluding_tax']['value']);
97-
98-
$appliedTaxesResponse = $pricesResponse['applied_taxes'];
99-
100-
self::assertEquals('US-CA-*-Rate 1', $appliedTaxesResponse[0]['label']);
101-
self::assertEquals(0.83, $appliedTaxesResponse[0]['amount']['value']);
102-
self::assertEquals('USD', $appliedTaxesResponse[0]['amount']['currency']);
103123
}
104124

105125
/**
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Quote\Api\Data\AddressInterface;
8+
use Magento\Quote\Model\Quote;
9+
10+
require __DIR__ . '/../../../Magento/Catalog/_files/products.php';
11+
12+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
13+
/** @var AddressInterface $quoteAddress */
14+
$quoteAddress = $objectManager->create(AddressInterface::class);
15+
$quoteAddress->setData(
16+
[
17+
'telephone' => 3468676,
18+
'postcode' => 75477,
19+
'country_id' => 'US',
20+
'city' => 'CityM',
21+
'company' => 'CompanyName',
22+
'street' => 'Green str, 67',
23+
'lastname' => 'Smith',
24+
'firstname' => 'John',
25+
'region_id' => 1
26+
]
27+
);
28+
29+
/** @var Quote $quote */
30+
$quote = $objectManager->create(Quote::class);
31+
$quote->setStoreId(
32+
1
33+
)->setIsActive(
34+
true
35+
)->setIsMultiShipping(
36+
false
37+
)->setShippingAddress(
38+
$quoteAddress
39+
)->setBillingAddress(
40+
$quoteAddress
41+
)->setCheckoutMethod(
42+
'customer'
43+
)->setReservedOrderId(
44+
'test_order_1'
45+
)->addProduct(
46+
$product
47+
);
48+
49+
$quoteRepository = $objectManager->get(
50+
\Magento\Quote\Api\CartRepositoryInterface::class
51+
);
52+
53+
$quoteRepository->save($quote);
54+
55+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
56+
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
57+
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
58+
->create();
59+
$quoteIdMask->setQuoteId($quote->getId());
60+
$quoteIdMask->setDataChanges(true);
61+
$quoteIdMask->save();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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__ . '/../../../Magento/Catalog/_files/products_rollback.php';
13+
14+
/** @var $objectManager ObjectManager */
15+
$objectManager = Bootstrap::getObjectManager();
16+
$quote = $objectManager->create(Quote::class);
17+
$quote->load('test_order_1', 'reserved_order_id')->delete();
18+
19+
/** @var QuoteIdMask $quoteIdMask */
20+
$quoteIdMask = $objectManager->create(QuoteIdMask::class);
21+
$quoteIdMask->delete($quote->getId());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
'region_id' => 12
2626
]
2727
);
28-
//$quoteAddress->save();
2928

3029
/** @var Quote $quote */
3130
$quote = $objectManager->create(Quote::class);

0 commit comments

Comments
 (0)