7
7
8
8
namespace Magento \GraphQl \Quote \Customer ;
9
9
10
- use Magento \Catalog \Api \ProductRepositoryInterface ;
10
+ use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
11
+ use Magento \GraphQl \Quote \GetQuoteItemIdByReservedQuoteIdAndSku ;
11
12
use Magento \Integration \Api \CustomerTokenServiceInterface ;
12
- use Magento \Quote \Model \QuoteFactory ;
13
- use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
14
- use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
15
13
use Magento \TestFramework \Helper \Bootstrap ;
16
14
use Magento \TestFramework \TestCase \GraphQlAbstract ;
17
15
@@ -26,49 +24,37 @@ class RemoveItemFromCartTest extends GraphQlAbstract
26
24
private $ customerTokenService ;
27
25
28
26
/**
29
- * @var QuoteResource
27
+ * @var GetMaskedQuoteIdByReservedOrderId
30
28
*/
31
- private $ quoteResource ;
29
+ private $ getMaskedQuoteIdByReservedOrderId ;
32
30
33
31
/**
34
- * @var QuoteFactory
32
+ * @var GetQuoteItemIdByReservedQuoteIdAndSku
35
33
*/
36
- private $ quoteFactory ;
37
-
38
- /**
39
- * @var QuoteIdToMaskedQuoteIdInterface
40
- */
41
- private $ quoteIdToMaskedId ;
42
-
43
- /**
44
- * @var ProductRepositoryInterface
45
- */
46
- private $ productRepository ;
34
+ private $ getQuoteItemIdByReservedQuoteIdAndSku ;
47
35
48
36
protected function setUp ()
49
37
{
50
38
$ objectManager = Bootstrap::getObjectManager ();
51
- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
52
- $ this ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
53
- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
54
39
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
55
- $ this ->productRepository = $ objectManager ->get (ProductRepositoryInterface::class);
40
+ $ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
41
+ $ this ->getQuoteItemIdByReservedQuoteIdAndSku = $ objectManager ->get (
42
+ GetQuoteItemIdByReservedQuoteIdAndSku::class
43
+ );
56
44
}
57
45
58
46
/**
59
47
* @magentoApiDataFixture Magento/Customer/_files/customer.php
60
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
48
+ * @magentoApiDataFixture Magento/GraphQl/ Catalog/_files/simple_product .php
61
49
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
62
50
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
63
51
*/
64
52
public function testRemoveItemFromCart ()
65
53
{
66
- $ quote = $ this ->quoteFactory ->create ();
67
- $ this ->quoteResource ->load ($ quote , 'test_quote ' , 'reserved_order_id ' );
68
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
69
- $ itemId = (int )$ quote ->getItemByProduct ($ this ->productRepository ->get ('simple ' ))->getId ();
54
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
55
+ $ itemId = $ this ->getQuoteItemIdByReservedQuoteIdAndSku ->execute ('test_quote ' , 'simple_product ' );
70
56
71
- $ query = $ this ->prepareMutationQuery ($ maskedQuoteId , $ itemId );
57
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ itemId );
72
58
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
73
59
74
60
$ this ->assertArrayHasKey ('removeItemFromCart ' , $ response );
@@ -83,116 +69,24 @@ public function testRemoveItemFromCart()
83
69
*/
84
70
public function testRemoveItemFromNonExistentCart ()
85
71
{
86
- $ query = $ this ->prepareMutationQuery ('non_existent_masked_id ' , 1 );
72
+ $ query = $ this ->getQuery ('non_existent_masked_id ' , 1 );
87
73
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
88
74
}
89
75
90
76
/**
91
77
* @magentoApiDataFixture Magento/Customer/_files/customer.php
92
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
78
+ * @magentoApiDataFixture Magento/GraphQl/ Catalog/_files/simple_product .php
93
79
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
94
80
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
95
81
*/
96
82
public function testRemoveNonExistentItem ()
97
83
{
98
- $ quote = $ this ->quoteFactory ->create ();
99
- $ this ->quoteResource ->load ($ quote , 'test_quote ' , 'reserved_order_id ' );
100
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
84
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
101
85
$ notExistentItemId = 999 ;
102
86
103
87
$ this ->expectExceptionMessage ("Cart doesn't contain the {$ notExistentItemId } item. " );
104
88
105
- $ query = $ this ->prepareMutationQuery ($ maskedQuoteId , $ notExistentItemId );
106
- $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
107
- }
108
-
109
- /**
110
- * @magentoApiDataFixture Magento/Customer/_files/customer.php
111
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
112
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
113
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
114
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
115
- */
116
- public function testRemoveItemIfItemIsNotBelongToCart ()
117
- {
118
- $ firstQuote = $ this ->quoteFactory ->create ();
119
- $ this ->quoteResource ->load ($ firstQuote , 'test_quote ' , 'reserved_order_id ' );
120
- $ firstQuoteMaskedId = $ this ->quoteIdToMaskedId ->execute ((int )$ firstQuote ->getId ());
121
-
122
- $ secondQuote = $ this ->quoteFactory ->create ();
123
- $ this ->quoteResource ->load (
124
- $ secondQuote ,
125
- 'test_order_with_virtual_product_without_address ' ,
126
- 'reserved_order_id '
127
- );
128
- $ secondQuote ->setCustomerId (1 );
129
- $ this ->quoteResource ->save ($ secondQuote );
130
- $ secondQuoteItemId = (int )$ secondQuote
131
- ->getItemByProduct ($ this ->productRepository ->get ('virtual-product ' ))
132
- ->getId ();
133
-
134
- $ this ->expectExceptionMessage ("Cart doesn't contain the {$ secondQuoteItemId } item. " );
135
-
136
- $ query = $ this ->prepareMutationQuery ($ firstQuoteMaskedId , $ secondQuoteItemId );
137
- $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
138
- }
139
-
140
- /**
141
- * @magentoApiDataFixture Magento/Customer/_files/customer.php
142
- * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
143
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
144
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
145
- */
146
- public function testRemoveItemFromGuestCart ()
147
- {
148
- $ guestQuote = $ this ->quoteFactory ->create ();
149
- $ this ->quoteResource ->load (
150
- $ guestQuote ,
151
- 'test_quote ' ,
152
- 'reserved_order_id '
153
- );
154
- $ guestQuoteMaskedId = $ this ->quoteIdToMaskedId ->execute ((int )$ guestQuote ->getId ());
155
- $ guestQuoteItemId = (int )$ guestQuote
156
- ->getItemByProduct ($ this ->productRepository ->get ('virtual-product ' ))
157
- ->getId ();
158
-
159
- $ this ->expectExceptionMessage (
160
- "The current user cannot perform operations on cart \"$ guestQuoteMaskedId \""
161
- );
162
-
163
- $ query = $ this ->prepareMutationQuery ($ guestQuoteMaskedId , $ guestQuoteItemId );
164
- $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
165
- }
166
-
167
- /**
168
- * @magentoApiDataFixture Magento/Customer/_files/customer.php
169
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
170
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
171
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
172
- * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
173
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
174
- */
175
- public function testRemoveItemFromAnotherCustomerCart ()
176
- {
177
- $ anotherCustomerQuote = $ this ->quoteFactory ->create ();
178
- $ this ->quoteResource ->load (
179
- $ anotherCustomerQuote ,
180
- 'test_order_with_virtual_product_without_address ' ,
181
- 'reserved_order_id '
182
- );
183
- $ anotherCustomerQuote ->setCustomerId (2 );
184
- $ this ->quoteResource ->save ($ anotherCustomerQuote );
185
-
186
- $ anotherCustomerQuoteMaskedId = $ this ->quoteIdToMaskedId ->execute ((int )$ anotherCustomerQuote ->getId ());
187
- $ anotherCustomerQuoteItemId = (int )$ anotherCustomerQuote
188
- ->getItemByProduct ($ this ->productRepository ->get ('virtual-product ' ))
189
- ->getId ();
190
-
191
- $ this ->expectExceptionMessage (
192
- "The current user cannot perform operations on cart \"$ anotherCustomerQuoteMaskedId \""
193
- );
194
-
195
- $ query = $ this ->prepareMutationQuery ($ anotherCustomerQuoteMaskedId , $ anotherCustomerQuoteItemId );
89
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ notExistentItemId );
196
90
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
197
91
}
198
92
@@ -240,12 +134,77 @@ public function dataProviderUpdateWithMissedRequiredParameters(): array
240
134
];
241
135
}
242
136
137
+ /**
138
+ * _security
139
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
140
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
141
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
142
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
143
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
144
+ */
145
+ public function testRemoveItemIfItemIsNotBelongToCart ()
146
+ {
147
+ $ firstQuoteMaskedId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
148
+ $ secondQuoteItemId = $ this ->getQuoteItemIdByReservedQuoteIdAndSku ->execute (
149
+ 'test_order_with_virtual_product ' ,
150
+ 'virtual-product '
151
+ );
152
+
153
+ $ this ->expectExceptionMessage ("Cart doesn't contain the {$ secondQuoteItemId } item. " );
154
+
155
+ $ query = $ this ->getQuery ($ firstQuoteMaskedId , $ secondQuoteItemId );
156
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
157
+ }
158
+
159
+ /**
160
+ * _security
161
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
162
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
163
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
164
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
165
+ */
166
+ public function testRemoveItemFromGuestCart ()
167
+ {
168
+ $ guestQuoteMaskedId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
169
+ $ guestQuoteItemId = $ this ->getQuoteItemIdByReservedQuoteIdAndSku ->execute ('test_quote ' , 'simple_product ' );
170
+
171
+ $ this ->expectExceptionMessage (
172
+ "The current user cannot perform operations on cart \"$ guestQuoteMaskedId \""
173
+ );
174
+
175
+ $ query = $ this ->getQuery ($ guestQuoteMaskedId , $ guestQuoteItemId );
176
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
177
+ }
178
+
179
+ /**
180
+ * _security
181
+ * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
182
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
183
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
184
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
185
+ */
186
+ public function testRemoveItemFromAnotherCustomerCart ()
187
+ {
188
+ $ anotherCustomerQuoteMaskedId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
189
+ $ anotherCustomerQuoteItemId = $ this ->getQuoteItemIdByReservedQuoteIdAndSku ->execute (
190
+ 'test_quote ' ,
191
+ 'simple_product '
192
+ );
193
+
194
+ $ this ->expectExceptionMessage (
195
+ "The current user cannot perform operations on cart \"$ anotherCustomerQuoteMaskedId \""
196
+ );
197
+
198
+ $ query = $ this ->getQuery ($ anotherCustomerQuoteMaskedId , $ anotherCustomerQuoteItemId );
199
+ $ this ->
graphQlQuery (
$ query, [],
'' ,
$ this ->
getHeaderMap (
'[email protected] ' ));
200
+ }
201
+
243
202
/**
244
203
* @param string $maskedQuoteId
245
204
* @param int $itemId
246
205
* @return string
247
206
*/
248
- private function prepareMutationQuery (string $ maskedQuoteId , int $ itemId ): string
207
+ private function getQuery (string $ maskedQuoteId , int $ itemId ): string
249
208
{
250
209
return <<<QUERY
251
210
mutation {
0 commit comments