@@ -294,8 +294,6 @@ public function testUpdateCustomerPreserveAllAddresses()
294
294
$ customerId = 1 ;
295
295
$ customer = $ this ->customerRepository ->getById ($ customerId );
296
296
$ customerDetails = $ customer ->__toArray ();
297
- $ defaultBilling = $ customerDetails ['default_billing ' ];
298
- $ defaultShipping = $ customerDetails ['default_shipping ' ];
299
297
$ newCustomerEntity = $ this ->customerFactory ->create ();
300
298
$ this ->dataObjectHelper ->populateWithArray (
301
299
$ newCustomerEntity ,
@@ -307,19 +305,8 @@ public function testUpdateCustomerPreserveAllAddresses()
307
305
$ this ->customerRepository ->save ($ newCustomerEntity );
308
306
309
307
$ newCustomerDetails = $ this ->customerRepository ->getById ($ customerId );
310
- $ newCustomerArray = $ newCustomerDetails ->__toArray ();
311
308
//Verify that old addresses are still present
312
309
$ this ->assertEquals (2 , count ($ newCustomerDetails ->getAddresses ()));
313
- $ this ->assertEquals (
314
- $ defaultBilling ,
315
- $ newCustomerArray ['default_billing ' ],
316
- "Default billing invalid value "
317
- );
318
- $ this ->assertEquals (
319
- $ defaultShipping ,
320
- $ newCustomerArray ['default_shipping ' ],
321
- "Default shipping invalid value "
322
- );
323
310
}
324
311
325
312
/**
@@ -345,19 +332,51 @@ public function testUpdateCustomerDeleteAllAddressesWithEmptyArray()
345
332
$ this ->customerRepository ->save ($ newCustomerEntity );
346
333
347
334
$ newCustomerDetails = $ this ->customerRepository ->getById ($ customerId );
348
- $ newCustomerArray = $ newCustomerDetails ->__toArray ();
349
335
//Verify that old addresses are removed
350
336
$ this ->assertEquals (0 , count ($ newCustomerDetails ->getAddresses ()));
351
- $ this ->assertEquals (
352
- $ newCustomerArray ['default_billing ' ],
353
- null ,
354
- "Default billing invalid value "
337
+ }
338
+
339
+ /**
340
+ * Test customer update with new address
341
+ *
342
+ * @magentoAppArea frontend
343
+ * @magentoDataFixture Magento/Customer/_files/customer.php
344
+ * @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
345
+ */
346
+ public function testUpdateCustomerWithNewAddress ()
347
+ {
348
+ $ customerId = 1 ;
349
+ $ customer = $ this ->customerRepository ->getById ($ customerId );
350
+ $ customerDetails = $ customer ->__toArray ();
351
+ unset($ customerDetails ['default_billing ' ]);
352
+ unset($ customerDetails ['default_shipping ' ]);
353
+
354
+ $ beforeSaveCustomer = $ this ->customerFactory ->create ();
355
+ $ this ->dataObjectHelper ->populateWithArray (
356
+ $ beforeSaveCustomer ,
357
+ $ customerDetails ,
358
+ CustomerInterface::class
355
359
);
356
- $ this ->assertEquals (
357
- $ newCustomerArray ['default_shipping ' ],
358
- null ,
359
- "Default shipping invalid value "
360
+
361
+ $ addresses = $ customer ->getAddresses ();
362
+ $ beforeSaveAddress = $ addresses [0 ]->__toArray ();
363
+ unset($ beforeSaveAddress ['id ' ]);
364
+ $ newAddressDataObject = $ this ->addressFactory ->create ();
365
+ $ this ->dataObjectHelper ->populateWithArray (
366
+ $ newAddressDataObject ,
367
+ $ beforeSaveAddress ,
368
+ AddressInterface::class
360
369
);
370
+
371
+ $ beforeSaveCustomer ->setAddresses ([$ newAddressDataObject ]);
372
+ $ this ->customerRepository ->save ($ beforeSaveCustomer );
373
+
374
+ $ newCustomer = $ this ->customerRepository ->getById ($ customerId );
375
+ $ newCustomerAddresses = $ newCustomer ->getAddresses ();
376
+ $ addressId = $ newCustomerAddresses [0 ]->getId ();
377
+
378
+ $ this ->assertEquals ($ newCustomer ->getDefaultBilling (), $ addressId , "Default billing invalid value " );
379
+ $ this ->assertEquals ($ newCustomer ->getDefaultShipping (), $ addressId , "Default shipping invalid value " );
361
380
}
362
381
363
382
/**
0 commit comments