public function AddressBookTest::testCopySingle in Commerce Core 8.2
Test copying when a single profile is allowed per customer.
@covers ::copy @covers ::allowsMultiple
File
- modules/
order/ tests/ src/ Kernel/ AddressBookTest.php, line 255
Class
- AddressBookTest
- Tests the address book.
Namespace
Drupal\Tests\commerce_order\KernelCode
public function testCopySingle() {
$order_address = array_filter($this->orderProfile
->get('address')
->first()
->getValue());
/** @var \Drupal\profile\Entity\ProfileTypeInterface $profile_type */
$profile_type = ProfileType::load('customer');
$profile_type
->setMultiple(FALSE);
$profile_type
->save();
// Confirm that the default profile was updated.
$this->addressBook
->copy($this->orderProfile, $this->user);
$new_profile = Profile::load(3);
$this
->assertEmpty($new_profile);
$this->defaultProfile = $this
->reloadEntity($this->defaultProfile);
$this
->assertEquals($order_address, array_filter($this->defaultProfile
->get('address')
->first()
->getValue()));
$this
->assertNull($this->defaultProfile
->getData('copy_to_address_book'));
// Confirm that the order profile now points to the default profile.
$this->orderProfile = $this
->reloadEntity($this->orderProfile);
$this
->assertEquals($this->defaultProfile
->id(), $this->orderProfile
->getData('address_book_profile_id'));
// Confirm that a default profile will be created, if missing.
$this->defaultProfile
->delete();
$this->addressBook
->copy($this->orderProfile, $this->user);
$new_default_profile = Profile::load(3);
$this
->assertNotEmpty($new_default_profile);
$this
->assertTrue($new_default_profile
->isDefault());
$this
->assertEquals($this->user
->id(), $new_default_profile
->getOwnerId());
$this
->assertEquals($order_address, array_filter($new_default_profile
->get('address')
->first()
->getValue()));
$this
->assertNull($new_default_profile
->getData('copy_to_address_book'));
/** @var \Drupal\profile\Entity\ProfileInterface $profile */
$this->orderProfile = $this
->reloadEntity($this->orderProfile);
$this
->assertEquals($new_default_profile
->id(), $this->orderProfile
->getData('address_book_profile_id'));
}