5
5
*/
6
6
declare (strict_types=1 );
7
7
8
- namespace Magento \GraphQl \Quote ;
8
+ namespace Magento \GraphQl \Quote \ Customer ;
9
9
10
- use Magento \Framework \App \Config \ScopeConfigInterface ;
11
10
use Magento \Integration \Api \CustomerTokenServiceInterface ;
12
- use Magento \Multishipping \Helper \Data ;
13
11
use Magento \Quote \Model \QuoteFactory ;
14
12
use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
15
13
use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
16
14
use Magento \TestFramework \Helper \Bootstrap ;
17
15
use Magento \TestFramework \TestCase \GraphQlAbstract ;
18
- use Magento \TestFramework \ObjectManager ;
19
16
20
17
/**
21
18
* Test for set shipping addresses on cart mutation
@@ -53,10 +50,11 @@ protected function setUp()
53
50
54
51
/**
55
52
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
53
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
56
54
*/
57
- public function testSetNewShippingAddressByGuest ()
55
+ public function testSetNewShippingAddress ()
58
56
{
59
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ( ' test_order_with_simple_product_without_address ' );
57
+ $ maskedQuoteId = $ this ->assignQuoteToCustomer ( );
60
58
61
59
$ query = <<<QUERY
62
60
mutation {
@@ -91,16 +89,16 @@ public function testSetNewShippingAddressByGuest()
91
89
postcode
92
90
telephone
93
91
country {
94
- code
95
92
label
93
+ code
96
94
}
97
95
address_type
98
96
}
99
97
}
100
98
}
101
99
}
102
100
QUERY ;
103
- $ response = $ this ->graphQlQuery ($ query );
101
+ $ response = $ this ->graphQlQuery ($ query, [], '' , $ this -> getHeaderMap () );
104
102
105
103
self ::assertArrayHasKey ('cart ' , $ response ['setShippingAddressesOnCart ' ]);
106
104
$ cartResponse = $ response ['setShippingAddressesOnCart ' ]['cart ' ];
@@ -111,12 +109,15 @@ public function testSetNewShippingAddressByGuest()
111
109
112
110
/**
113
111
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
114
- * @expectedException \Exception
115
- * @expectedExceptionMessage The current customer isn't authorized.
112
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
113
+ * @dataProvider requestWithoutRequiredParamsDataProvider
114
+ * @param string $params
115
+ * @param string $expectedException
116
+ * @throws \Exception
116
117
*/
117
- public function testSetShippingAddressFromAddressBookByGuest ( )
118
+ public function testSetNewShippingAddressWithEmptyRequiredParams ( string $ params , string $ expectedException )
118
119
{
119
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ( ' test_order_with_simple_product_without_address ' );
120
+ $ maskedQuoteId = $ this ->assignQuoteToCustomer ( );
120
121
121
122
$ query = <<<QUERY
122
123
mutation {
@@ -125,7 +126,9 @@ public function testSetShippingAddressFromAddressBookByGuest()
125
126
cart_id: " $ maskedQuoteId"
126
127
shipping_addresses: [
127
128
{
128
- customer_address_id: 1
129
+ address: {
130
+ $ params
131
+ }
129
132
}
130
133
]
131
134
}
@@ -138,16 +141,21 @@ public function testSetShippingAddressFromAddressBookByGuest()
138
141
}
139
142
}
140
143
QUERY ;
141
- $ this ->graphQlQuery ($ query );
144
+ $ this ->expectExceptionMessage (
145
+ $ expectedException
146
+ );
147
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
142
148
}
143
149
144
150
/**
145
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved .php
151
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved .php
146
152
* @magentoApiDataFixture Magento/Customer/_files/customer.php
153
+ * @expectedException \Exception
154
+ * @expectedExceptionMessage The Cart includes virtual product(s) only, so a shipping address is not used.
147
155
*/
148
- public function testSetNewShippingAddressByRegisteredCustomer ()
156
+ public function testSetNewShippingAddressOnQuoteWithVirtualProducts ()
149
157
{
150
- $ maskedQuoteId = $ this ->assignQuoteToCustomer ();
158
+ $ maskedQuoteId = $ this ->assignQuoteToCustomer (' test_order_with_virtual_product_without_address ' );
151
159
152
160
$ query = <<<QUERY
153
161
mutation {
@@ -174,38 +182,21 @@ public function testSetNewShippingAddressByRegisteredCustomer()
174
182
) {
175
183
cart {
176
184
shipping_addresses {
177
- firstname
178
- lastname
179
- company
180
- street
181
185
city
182
- postcode
183
- telephone
184
- country {
185
- label
186
- code
187
- }
188
- address_type
189
186
}
190
187
}
191
188
}
192
189
}
193
190
QUERY ;
194
- $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
195
-
196
- self ::assertArrayHasKey ('cart ' , $ response ['setShippingAddressesOnCart ' ]);
197
- $ cartResponse = $ response ['setShippingAddressesOnCart ' ]['cart ' ];
198
- self ::assertArrayHasKey ('shipping_addresses ' , $ cartResponse );
199
- $ shippingAddressResponse = current ($ cartResponse ['shipping_addresses ' ]);
200
- $ this ->assertNewShippingAddressFields ($ shippingAddressResponse );
191
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
201
192
}
202
193
203
194
/**
204
195
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
205
196
* @magentoApiDataFixture Magento/Customer/_files/customer.php
206
197
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
207
198
*/
208
- public function testSetShippingAddressFromAddressBookByRegisteredCustomer ()
199
+ public function testSetShippingAddressFromAddressBook ()
209
200
{
210
201
$ maskedQuoteId = $ this ->assignQuoteToCustomer ();
211
202
@@ -277,36 +268,6 @@ public function testSetNotExistedShippingAddressFromAddressBook()
277
268
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
278
269
}
279
270
280
- /**
281
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
282
- * @expectedException \Exception
283
- * @expectedExceptionMessage The shipping address must contain either "customer_address_id" or "address".
284
- */
285
- public function testSetShippingAddressWithoutAddresses ()
286
- {
287
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ('test_order_with_simple_product_without_address ' );
288
-
289
- $ query = <<<QUERY
290
- mutation {
291
- setShippingAddressesOnCart(
292
- input: {
293
- cart_id: " $ maskedQuoteId"
294
- shipping_addresses: [
295
- {}
296
- ]
297
- }
298
- ) {
299
- cart {
300
- shipping_addresses {
301
- city
302
- }
303
- }
304
- }
305
- }
306
- QUERY ;
307
- $ this ->graphQlQuery ($ query );
308
- }
309
-
310
271
/**
311
272
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
312
273
* @magentoApiDataFixture Magento/Customer/_files/customer.php
@@ -355,13 +316,15 @@ public function testSetNewShippingAddressAndFromAddressBookAtSameTime()
355
316
}
356
317
357
318
/**
319
+ * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
320
+ * @magentoApiDataFixture Magento/Customer/_files/customer_address.php
358
321
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
359
322
* @expectedException \Exception
360
- * @expectedExceptionMessage You cannot specify multiple shipping addresses.
323
+ * @expectedExceptionMessage The current user cannot use address with ID "1"
361
324
*/
362
- public function testSetMultipleNewShippingAddresses ()
325
+ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress ()
363
326
{
364
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ('test_order_with_simple_product_without_address ' );
327
+ $ maskedQuoteId = $ this ->assignQuoteToCustomer ('test_order_with_simple_product_without_address ' , 2 );
365
328
366
329
$ query = <<<QUERY
367
330
mutation {
@@ -370,69 +333,32 @@ public function testSetMultipleNewShippingAddresses()
370
333
cart_id: " $ maskedQuoteId"
371
334
shipping_addresses: [
372
335
{
373
- address: {
374
- firstname: "test firstname"
375
- lastname: "test lastname"
376
- company: "test company"
377
- street: ["test street 1", "test street 2"]
378
- city: "test city"
379
- region: "test region"
380
- postcode: "887766"
381
- country_code: "US"
382
- telephone: "88776655"
383
- save_in_address_book: false
384
- }
385
- },
386
- {
387
- address: {
388
- firstname: "test firstname 2"
389
- lastname: "test lastname 2"
390
- company: "test company 2"
391
- street: ["test street 1", "test street 2"]
392
- city: "test city"
393
- region: "test region"
394
- postcode: "887766"
395
- country_code: "US"
396
- telephone: "88776655"
397
- save_in_address_book: false
398
- }
336
+ customer_address_id: 1
399
337
}
400
338
]
401
339
}
402
340
) {
403
341
cart {
404
342
shipping_addresses {
405
- city
343
+ postcode
406
344
}
407
345
}
408
346
}
409
347
}
410
348
QUERY ;
411
- /** @var \Magento\Config\Model\ResourceModel\Config $config */
412
- $ config = ObjectManager::getInstance ()->get (\Magento \Config \Model \ResourceModel \Config::class);
413
- $ config ->saveConfig (
414
- Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE ,
415
- null ,
416
- ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
417
- 0
418
- );
419
- /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
420
- $ config = ObjectManager::getInstance ()->get (\Magento \Framework \App \Config \ReinitableConfigInterface::class);
421
- $ config ->reinit ();
422
349
423
- $ this ->graphQlQuery ($ query );
350
+ $ this ->graphQlQuery ($ query, [], '' , $ this -> getHeaderMap ( ' customer2@search.example.com ' ) );
424
351
}
425
352
426
353
/**
427
354
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
428
355
* @magentoApiDataFixture Magento/Customer/_files/customer_address.php
429
356
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
430
357
* @expectedException \Exception
431
- * @expectedExceptionMessage The current user cannot use address with ID "1"
432
358
*/
433
- public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress ()
359
+ public function testSetShippingAddressIfCustomerIsNotOwnerOfCart ()
434
360
{
435
- $ maskedQuoteId = $ this ->assignQuoteToCustomer ('test_order_with_simple_product_without_address ' , 2 );
361
+ $ maskedQuoteId = $ this ->assignQuoteToCustomer ('test_order_with_simple_product_without_address ' , 1 );
436
362
437
363
$ query = <<<QUERY
438
364
mutation {
@@ -454,10 +380,27 @@ public function testSetShippingAddressIfCustomerIsNotOwnerOfAddress()
454
380
}
455
381
}
456
382
QUERY ;
383
+ $ this ->expectExceptionMessage (
384
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
385
+ );
457
386
458
387
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ('customer2@search.example.com ' ));
459
388
}
460
389
390
+ /**
391
+ * TODO: currently only the city param is required, do we need to add at least ZIP code?
392
+ * @return array
393
+ */
394
+ public function requestWithoutRequiredParamsDataProvider ()
395
+ {
396
+ return [
397
+ [
398
+ 'save_in_address_book: false ' ,
399
+ 'Field CartAddressInput.city of required type String! was not provided '
400
+ ]
401
+ ];
402
+ }
403
+
461
404
/**
462
405
* Verify the all the whitelisted fields for a New Address Object
463
406
*
@@ -512,18 +455,6 @@ private function getHeaderMap(string $username = 'customer@example.com', string
512
455
return $ headerMap ;
513
456
}
514
457
515
- /**
516
- * @param string $reversedQuoteId
517
- * @return string
518
- */
519
- private function getMaskedQuoteIdByReversedQuoteId (string $ reversedQuoteId ): string
520
- {
521
- $ quote = $ this ->quoteFactory ->create ();
522
- $ this ->quoteResource ->load ($ quote , $ reversedQuoteId , 'reserved_order_id ' );
523
-
524
- return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
525
- }
526
-
527
458
/**
528
459
* @param string $reversedQuoteId
529
460
* @param int $customerId
@@ -539,22 +470,4 @@ private function assignQuoteToCustomer(
539
470
$ this ->quoteResource ->save ($ quote );
540
471
return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
541
472
}
542
-
543
- public function tearDown ()
544
- {
545
- /** @var \Magento\Config\Model\ResourceModel\Config $config */
546
- $ config = ObjectManager::getInstance ()->get (\Magento \Config \Model \ResourceModel \Config::class);
547
-
548
- //default state of multishipping config
549
- $ config ->saveConfig (
550
- Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE ,
551
- 1 ,
552
- ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
553
- 0
554
- );
555
-
556
- /** @var \Magento\Framework\App\Config\ReinitableConfigInterface $config */
557
- $ config = ObjectManager::getInstance ()->get (\Magento \Framework \App \Config \ReinitableConfigInterface::class);
558
- $ config ->reinit ();
559
- }
560
473
}
0 commit comments