Skip to content

Commit 8ef99e0

Browse files
committed
Added test coverage for guest user
1 parent 4b89ee0 commit 8ef99e0

File tree

6 files changed

+202
-1
lines changed

6 files changed

+202
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function setUp()
4949
}
5050

5151
/**
52-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax.php
52+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_customer.php
5353
*/
5454
public function testGetCartTotalsForCustomerWithTaxApplied()
5555
{
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Quote\Guest;
9+
10+
use Magento\Integration\Api\CustomerTokenServiceInterface;
11+
use Magento\Quote\Model\QuoteFactory;
12+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
13+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\TestCase\GraphQlAbstract;
16+
17+
/**
18+
* Test getting cart totals for guest
19+
*/
20+
class CartTotalsTest extends GraphQlAbstract
21+
{
22+
/**
23+
* @var CustomerTokenServiceInterface
24+
*/
25+
private $customerTokenService;
26+
27+
/**
28+
* @var QuoteResource
29+
*/
30+
private $quoteResource;
31+
32+
/**
33+
* @var QuoteFactory
34+
*/
35+
private $quoteFactory;
36+
37+
/**
38+
* @var QuoteIdToMaskedQuoteIdInterface
39+
*/
40+
private $quoteIdToMaskedId;
41+
42+
protected function setUp()
43+
{
44+
$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);
49+
}
50+
51+
/**
52+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_tax_guest.php
53+
*/
54+
public function testGetCartTotalsForCustomerWithTaxApplied()
55+
{
56+
$maskedQuoteId = $this->getMaskedQuoteIdByReversedQuoteId('test_order_tax');
57+
58+
$query = <<<QUERY
59+
{
60+
cart(cart_id: "$maskedQuoteId") {
61+
prices {
62+
grand_total {
63+
value,
64+
currency
65+
}
66+
subtotal_including_tax {
67+
value
68+
currency
69+
}
70+
subtotal_excluding_tax {
71+
value
72+
currency
73+
}
74+
subtotal_with_discount_excluding_tax {
75+
value
76+
currency
77+
}
78+
applied_taxes {
79+
label
80+
amount {
81+
value
82+
currency
83+
}
84+
}
85+
}
86+
}
87+
}
88+
QUERY;
89+
$response = $this->graphQlQuery($query);
90+
91+
self::assertArrayHasKey('prices', $response['cart']);
92+
$pricesResponse = $response['cart']['prices'];
93+
self::assertEquals(10, $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']);
103+
}
104+
105+
/**
106+
* @param string $reversedQuoteId
107+
* @return string
108+
*/
109+
private function getMaskedQuoteIdByReversedQuoteId(string $reversedQuoteId): string
110+
{
111+
$quote = $this->quoteFactory->create();
112+
$this->quoteResource->load($quote, $reversedQuoteId, 'reserved_order_id');
113+
114+
return $this->quoteIdToMaskedId->execute((int)$quote->getId());
115+
}
116+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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/product_simple_with_tax.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' => 12
26+
]
27+
);
28+
//$quoteAddress->save();
29+
30+
/** @var Quote $quote */
31+
$quote = $objectManager->create(Quote::class);
32+
$quote->setStoreId(
33+
1
34+
)->setIsActive(
35+
true
36+
)->setIsMultiShipping(
37+
false
38+
)->setShippingAddress(
39+
$quoteAddress
40+
)->setBillingAddress(
41+
$quoteAddress
42+
)->setCheckoutMethod(
43+
'customer'
44+
)->setReservedOrderId(
45+
'test_order_tax'
46+
)->addProduct(
47+
$product
48+
);
49+
50+
$quote->getShippingAddress()->setRegionId(12);
51+
52+
$quoteRepository = $objectManager->get(
53+
\Magento\Quote\Api\CartRepositoryInterface::class
54+
);
55+
56+
$quoteRepository->save($quote);
57+
58+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
59+
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
60+
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
61+
->create();
62+
$quoteIdMask->setQuoteId($quote->getId());
63+
$quoteIdMask->setDataChanges(true);
64+
$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/product_simple_with_tax_rollback.php';
13+
14+
/** @var $objectManager ObjectManager */
15+
$objectManager = Bootstrap::getObjectManager();
16+
$quote = $objectManager->create(Quote::class);
17+
$quote->load('test_order_tax', 'reserved_order_id')->delete();
18+
19+
/** @var QuoteIdMask $quoteIdMask */
20+
$quoteIdMask = $objectManager->create(QuoteIdMask::class);
21+
$quoteIdMask->delete($quote->getId());

0 commit comments

Comments
 (0)