77
88namespace Magento \GraphQl \Quote \Customer ;
99
10+ use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
1011use 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 ;
1412use Magento \TestFramework \Helper \Bootstrap ;
1513use Magento \TestFramework \TestCase \GraphQlAbstract ;
1614
2018class GetCartTest extends GraphQlAbstract
2119{
2220 /**
23- * @var QuoteResource
21+ * @var GetMaskedQuoteIdByReservedOrderId
2422 */
25- private $ quoteResource ;
26-
27- /**
28- * @var QuoteFactory
29- */
30- private $ quoteFactory ;
31-
32- /**
33- * @var QuoteIdToMaskedQuoteIdInterface
34- */
35- private $ quoteIdToMaskedId ;
23+ private $ getMaskedQuoteIdByReservedOrderId ;
3624
3725 /**
3826 * @var CustomerTokenServiceInterface
@@ -42,19 +30,22 @@ class GetCartTest extends GraphQlAbstract
4230 protected function setUp ()
4331 {
4432 $ objectManager = Bootstrap::getObjectManager ();
45- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
46- $ this ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
47- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
33+ $ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
4834 $ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
4935 }
5036
5137 /**
52- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
38+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
39+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
40+ * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
41+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
42+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
43+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
5344 */
5445 public function testGetCart ()
5546 {
56- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ( ' test_order_item_with_items ' );
57- $ query = $ this ->getCartQuery ($ maskedQuoteId );
47+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
48+ $ query = $ this ->getQuery ($ maskedQuoteId );
5849
5950 $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
6051
@@ -63,22 +54,23 @@ public function testGetCart()
6354 self ::assertCount (2 , $ response ['cart ' ]['items ' ]);
6455
6556 self ::assertNotEmpty ($ response ['cart ' ]['items ' ][0 ]['id ' ]);
66- self ::assertEquals ($ response ['cart ' ]['items ' ][0 ]['qty ' ], 2 );
67- self ::assertEquals ($ response ['cart ' ]['items ' ][0 ]['product ' ]['sku ' ], ' simple ' );
57+ self ::assertEquals (2 , $ response ['cart ' ]['items ' ][0 ]['qty ' ]);
58+ self ::assertEquals (' simple ' , $ response ['cart ' ]['items ' ][0 ]['product ' ]['sku ' ]);
6859
6960 self ::assertNotEmpty ($ response ['cart ' ]['items ' ][1 ]['id ' ]);
70- self ::assertEquals ($ response ['cart ' ]['items ' ][1 ]['qty ' ], 1 );
71- self ::assertEquals ($ response ['cart ' ]['items ' ][1 ]['product ' ]['sku ' ], ' simple_one ' );
61+ self ::assertEquals (2 , $ response ['cart ' ]['items ' ][1 ]['qty ' ]);
62+ self ::assertEquals (' virtual-product ' , $ response ['cart ' ]['items ' ][1 ]['product ' ]['sku ' ]);
7263 }
7364
7465 /**
66+ * _security
7567 * @magentoApiDataFixture Magento/Customer/_files/customer.php
76- * @magentoApiDataFixture Magento/Checkout/ _files/quote_with_simple_product_saved .php
68+ * @magentoApiDataFixture Magento/GraphQl/Quote/ _files/guest/create_empty_cart .php
7769 */
7870 public function testGetGuestCart ()
7971 {
80- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ( ' test_order_with_simple_product_without_address ' );
81- $ query = $ this ->getCartQuery ($ maskedQuoteId );
72+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
73+ $ query = $ this ->getQuery ($ maskedQuoteId );
8274
8375 $ this ->expectExceptionMessage (
8476 "The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
@@ -87,13 +79,14 @@ public function testGetGuestCart()
8779 }
8880
8981 /**
82+ * _security
9083 * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
91- * @magentoApiDataFixture Magento/Checkout/ _files/quote_with_items_saved .php
84+ * @magentoApiDataFixture Magento/GraphQl/Quote/ _files/customer/create_empty_cart .php
9285 */
9386 public function testGetAnotherCustomerCart ()
9487 {
95- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ( ' test_order_item_with_items ' );
96- $ query = $ this ->getCartQuery ($ maskedQuoteId );
88+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
89+ $ query = $ this ->getQuery ($ maskedQuoteId );
9790
9891 $ this ->expectExceptionMessage (
9992 "The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
@@ -103,33 +96,30 @@ public function testGetAnotherCustomerCart()
10396
10497 /**
10598 * @magentoApiDataFixture Magento/Customer/_files/customer.php
99+ *
106100 * @expectedException \Exception
107101 * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
108102 */
109103 public function testGetNonExistentCart ()
110104 {
111105 $ maskedQuoteId = 'non_existent_masked_id ' ;
112- $ query = $ this ->getCartQuery ($ maskedQuoteId );
106+ $ query = $ this ->getQuery ($ maskedQuoteId );
113107
114108 $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
115109 }
116110
117111 /**
118- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
119112 * @magentoApiDataFixture Magento/Customer/_files/customer.php
113+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
114+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php
115+ *
120116 * @expectedException \Exception
121117 * @expectedExceptionMessage Current user does not have an active cart.
122118 */
123119 public function testGetInactiveCart ()
124120 {
125- $ quote = $ this ->quoteFactory ->create ();
126- $ this ->quoteResource ->load ($ quote , 'test_order_with_simple_product_without_address ' , 'reserved_order_id ' );
127- $ quote ->setCustomerId (1 );
128- $ quote ->setIsActive (false );
129- $ this ->quoteResource ->save ($ quote );
130- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
131-
132- $ query = $ this ->getCartQuery ($ maskedQuoteId );
121+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
122+ $ query = $ this ->getQuery ($ maskedQuoteId );
133123
134124 $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
135125 }
@@ -138,12 +128,11 @@ public function testGetInactiveCart()
138128 * @param string $maskedQuoteId
139129 * @return string
140130 */
141- private function getCartQuery (
142- string $ maskedQuoteId
143- ) : string {
131+ private function getQuery (string $ maskedQuoteId ): string
132+ {
144133 return <<<QUERY
145134{
146- cart(cart_id: " $ maskedQuoteId") {
135+ cart(cart_id: " { $ maskedQuoteId} ") {
147136 items {
148137 id
149138 qty
@@ -156,18 +145,6 @@ private function getCartQuery(
156145QUERY ;
157146 }
158147
159- /**
160- * @param string $reversedQuoteId
161- * @return string
162- */
163- private function getMaskedQuoteIdByReversedQuoteId (string $ reversedQuoteId ): string
164- {
165- $ quote = $ this ->quoteFactory ->create ();
166- $ this ->quoteResource ->load ($ quote , $ reversedQuoteId , 'reserved_order_id ' );
167-
168- return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
169- }
170-
171148 /**
172149 * @param string $username
173150 * @param string $password
0 commit comments