1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2019 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
18
18
use Magento \Quote \Test \Fixture \CustomerCart ;
19
19
use Magento \Quote \Test \Fixture \GuestCart as GuestCartFixture ;
20
20
use Magento \Quote \Test \Fixture \QuoteIdMask ;
21
+ use Magento \QuoteGraphQl \Model \ErrorMapper ;
21
22
use Magento \Sales \Api \OrderRepositoryInterface ;
22
23
use Magento \Sales \Model \ResourceModel \Order \CollectionFactory ;
23
24
use Magento \TestFramework \Fixture \Config ;
24
25
use Magento \TestFramework \Fixture \DataFixture ;
25
26
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
26
27
use Magento \TestFramework \Helper \Bootstrap ;
28
+ use Magento \TestFramework \TestCase \GraphQl \ResponseContainsErrorsException ;
27
29
use Magento \TestFramework \TestCase \GraphQlAbstract ;
28
30
use Magento \Checkout \Test \Fixture \SetBillingAddress as SetBillingAddressFixture ;
29
31
use Magento \Checkout \Test \Fixture \SetDeliveryMethod as SetDeliveryMethodFixture ;
@@ -139,18 +141,25 @@ public function testPlaceOrderIfCartIdIsEmpty()
139
141
),
140
142
DataFixture(QuoteIdMask::class, ['cart_id ' => '$cart.id$ ' ], 'quoteIdMask ' ),
141
143
]
142
- public function testPlaceOrderWithNoItemsInCart ()
144
+ public function testPlaceOrderWithNoItemsInCart (): void
143
145
{
144
146
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
145
147
$ query = $ this ->getQuery ($ maskedQuoteId );
146
-
147
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
148
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
149
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
150
- self ::assertEquals (
151
- 'A server error stopped your order from being placed. Please try to place your order again. ' ,
152
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
153
- );
148
+ try {
149
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
150
+ } catch (ResponseContainsErrorsException $ exception ) {
151
+ $ exceptionData = $ exception ->getResponseData ();
152
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
153
+ self ::assertEquals (
154
+ 'Unable to place order: A server error stopped your order from being placed. ' .
155
+ ' Please try to place your order again ' ,
156
+ $ exceptionData ['errors ' ][0 ]['message ' ]
157
+ );
158
+ self ::assertEquals (
159
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
160
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
161
+ );
162
+ }
154
163
}
155
164
156
165
#[
@@ -173,13 +182,20 @@ public function testPlaceOrderWithNoShippingAddress()
173
182
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
174
183
$ query = $ this ->getQuery ($ maskedQuoteId );
175
184
176
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
177
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
178
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
179
- self ::assertEquals (
180
- 'Some addresses can \'t be used due to the configurations for specific countries. ' ,
181
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
182
- );
185
+ try {
186
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
187
+ } catch (ResponseContainsErrorsException $ exception ) {
188
+ $ exceptionData = $ exception ->getResponseData ();
189
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
190
+ self ::assertEquals (
191
+ 'Unable to place order: Some addresses can \'t be used due to the configurations for specific countries. ' ,
192
+ $ exceptionData ['errors ' ][0 ]['message ' ]
193
+ );
194
+ self ::assertEquals (
195
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
196
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
197
+ );
198
+ }
183
199
}
184
200
185
201
#[
@@ -203,13 +219,20 @@ public function testPlaceOrderWithNoShippingMethod()
203
219
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
204
220
$ query = $ this ->getQuery ($ maskedQuoteId );
205
221
206
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
207
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
208
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
209
- self ::assertEquals (
210
- 'The shipping method is missing. Select the shipping method and try again. ' ,
211
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
212
- );
222
+ try {
223
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
224
+ } catch (ResponseContainsErrorsException $ exception ) {
225
+ $ exceptionData = $ exception ->getResponseData ();
226
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
227
+ self ::assertEquals (
228
+ 'Unable to place order: The shipping method is missing. Select the shipping method and try again. ' ,
229
+ $ exceptionData ['errors ' ][0 ]['message ' ]
230
+ );
231
+ self ::assertEquals (
232
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
233
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
234
+ );
235
+ }
213
236
}
214
237
215
238
#[
@@ -237,13 +260,24 @@ public function testPlaceOrderWithNoBillingAddress()
237
260
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
238
261
$ query = $ this ->getQuery ($ maskedQuoteId );
239
262
240
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
241
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
242
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
243
- self ::assertStringContainsString (
244
- 'Please check the billing address information. ' ,
245
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
246
- );
263
+ try {
264
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
265
+ } catch (ResponseContainsErrorsException $ exception ) {
266
+ $ exceptionData = $ exception ->getResponseData ();
267
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
268
+ self ::assertEquals (
269
+ 'Unable to place order: Please check the billing address information. ' .
270
+ ' "firstname" is required. Enter and try again. "lastname" is required. Enter and try again. ' .
271
+ ' "street" is required. Enter and try again. "city" is required. ' .
272
+ 'Enter and try again. "telephone" is required. Enter and try again. ' .
273
+ '"postcode" is required. Enter and try again. "countryId" is required. Enter and try again. ' ,
274
+ $ exceptionData ['errors ' ][0 ]['message ' ]
275
+ );
276
+ self ::assertEquals (
277
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
278
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
279
+ );
280
+ }
247
281
}
248
282
249
283
#[
@@ -272,13 +306,20 @@ public function testPlaceOrderWithNoPaymentMethod()
272
306
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
273
307
$ query = $ this ->getQuery ($ maskedQuoteId );
274
308
275
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
276
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
277
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
278
- self ::assertEquals (
279
- 'Enter a valid payment method and try again. ' ,
280
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
281
- );
309
+ try {
310
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
311
+ } catch (ResponseContainsErrorsException $ exception ) {
312
+ $ exceptionData = $ exception ->getResponseData ();
313
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
314
+ self ::assertEquals (
315
+ 'Unable to place order: Enter a valid payment method and try again. ' ,
316
+ $ exceptionData ['errors ' ][0 ]['message ' ]
317
+ );
318
+ self ::assertEquals (
319
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
320
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
321
+ );
322
+ }
282
323
}
283
324
284
325
#[
@@ -317,13 +358,20 @@ public function testPlaceOrderWithOutOfStockProduct()
317
358
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
318
359
$ query = $ this ->getQuery ($ maskedQuoteId );
319
360
320
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
321
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
322
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
323
- self ::assertEquals (
324
- 'Some of the products are out of stock. ' ,
325
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
326
- );
361
+ try {
362
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
363
+ } catch (ResponseContainsErrorsException $ exception ) {
364
+ $ exceptionData = $ exception ->getResponseData ();
365
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
366
+ self ::assertEquals (
367
+ 'Unable to place order: Some of the products are out of stock. ' ,
368
+ $ exceptionData ['errors ' ][0 ]['message ' ]
369
+ );
370
+ self ::assertEquals (
371
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
372
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
373
+ );
374
+ }
327
375
}
328
376
329
377
#[
@@ -362,13 +410,20 @@ public function testPlaceOrderWithOutOfStockProductWithDisabledInventoryCheck()
362
410
$ maskedQuoteId = DataFixtureStorageManager::getStorage ()->get ('quoteIdMask ' )->getMaskedId ();
363
411
$ query = $ this ->getQuery ($ maskedQuoteId );
364
412
365
- $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
366
- self ::assertEquals (1 , count ($ response ['placeOrder ' ]['errors ' ]));
367
- self ::assertEquals ('UNABLE_TO_PLACE_ORDER ' , $ response ['placeOrder ' ]['errors ' ][0 ]['code ' ]);
368
- self ::assertEquals (
369
- 'Enter a valid payment method and try again. ' ,
370
- $ response ['placeOrder ' ]['errors ' ][0 ]['message ' ]
371
- );
413
+ try {
414
+ $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
415
+ } catch (ResponseContainsErrorsException $ exception ) {
416
+ $ exceptionData = $ exception ->getResponseData ();
417
+ self ::assertEquals (1 , count ($ exceptionData ['errors ' ]));
418
+ self ::assertEquals (
419
+ 'Unable to place order: Enter a valid payment method and try again. ' ,
420
+ $ exceptionData ['errors ' ][0 ]['message ' ]
421
+ );
422
+ self ::assertEquals (
423
+ ErrorMapper::ERROR_UNABLE_TO_PLACE_ORDER ,
424
+ $ exceptionData ['errors ' ][0 ]['extensions ' ]['error_code ' ]
425
+ );
426
+ }
372
427
}
373
428
374
429
#[
0 commit comments