7
7
8
8
namespace Magento \GraphQl \Quote \Customer ;
9
9
10
+ use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
10
11
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
12
use Magento \TestFramework \Helper \Bootstrap ;
15
13
use Magento \TestFramework \TestCase \GraphQlAbstract ;
16
14
20
18
class GetCartTest extends GraphQlAbstract
21
19
{
22
20
/**
23
- * @var QuoteResource
21
+ * @var GetMaskedQuoteIdByReservedOrderId
24
22
*/
25
- private $ quoteResource ;
26
-
27
- /**
28
- * @var QuoteFactory
29
- */
30
- private $ quoteFactory ;
31
-
32
- /**
33
- * @var QuoteIdToMaskedQuoteIdInterface
34
- */
35
- private $ quoteIdToMaskedId ;
23
+ private $ getMaskedQuoteIdByReservedOrderId ;
36
24
37
25
/**
38
26
* @var CustomerTokenServiceInterface
@@ -42,19 +30,22 @@ class GetCartTest extends GraphQlAbstract
42
30
protected function setUp ()
43
31
{
44
32
$ 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);
48
34
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
49
35
}
50
36
51
37
/**
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
53
44
*/
54
45
public function testGetCart ()
55
46
{
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 );
58
49
59
50
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
60
51
@@ -63,22 +54,23 @@ public function testGetCart()
63
54
self ::assertCount (2 , $ response ['cart ' ]['items ' ]);
64
55
65
56
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 ' ]);
68
59
69
60
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 ' ]);
72
63
}
73
64
74
65
/**
66
+ * _security
75
67
* @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
77
69
*/
78
70
public function testGetGuestCart ()
79
71
{
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 );
82
74
83
75
$ this ->expectExceptionMessage (
84
76
"The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
@@ -87,13 +79,14 @@ public function testGetGuestCart()
87
79
}
88
80
89
81
/**
82
+ * _security
90
83
* @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
92
85
*/
93
86
public function testGetAnotherCustomerCart ()
94
87
{
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 );
97
90
98
91
$ this ->expectExceptionMessage (
99
92
"The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
@@ -103,33 +96,30 @@ public function testGetAnotherCustomerCart()
103
96
104
97
/**
105
98
* @magentoApiDataFixture Magento/Customer/_files/customer.php
99
+ *
106
100
* @expectedException \Exception
107
101
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
108
102
*/
109
103
public function testGetNonExistentCart ()
110
104
{
111
105
$ maskedQuoteId = 'non_existent_masked_id ' ;
112
- $ query = $ this ->getCartQuery ($ maskedQuoteId );
106
+ $ query = $ this ->getQuery ($ maskedQuoteId );
113
107
114
108
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
115
109
}
116
110
117
111
/**
118
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
119
112
* @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
+ *
120
116
* @expectedException \Exception
121
117
* @expectedExceptionMessage Current user does not have an active cart.
122
118
*/
123
119
public function testGetInactiveCart ()
124
120
{
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 );
133
123
134
124
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
135
125
}
@@ -138,12 +128,11 @@ public function testGetInactiveCart()
138
128
* @param string $maskedQuoteId
139
129
* @return string
140
130
*/
141
- private function getCartQuery (
142
- string $ maskedQuoteId
143
- ) : string {
131
+ private function getQuery (string $ maskedQuoteId ): string
132
+ {
144
133
return <<<QUERY
145
134
{
146
- cart(cart_id: " $ maskedQuoteId") {
135
+ cart(cart_id: " { $ maskedQuoteId} ") {
147
136
items {
148
137
id
149
138
qty
@@ -156,18 +145,6 @@ private function getCartQuery(
156
145
QUERY ;
157
146
}
158
147
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
-
171
148
/**
172
149
* @param string $username
173
150
* @param string $password
0 commit comments