public function AddressBookTest::testDefaultOverview in Commerce Core 8.2
Tests the address book overview page with the default profile type.
File
- modules/
order/ tests/ src/ FunctionalJavascript/ AddressBookTest.php, line 293
Class
- AddressBookTest
- Tests the address book pages.
Namespace
Drupal\Tests\commerce_order\FunctionalJavascriptCode
public function testDefaultOverview() {
$customer = $this
->createUser([
'access user profiles',
'create customer profile',
'update own customer profile',
'delete own customer profile',
'view own customer profile',
'administer profile',
]);
$this
->drupalLogin($customer);
$this
->drupalGet(Url::fromRoute('commerce_order.address_book.overview', [
'user' => $customer
->id(),
]));
$this
->assertSession()
->pageTextContains('There are no addresses yet.');
// Confirm that a profile can be created.
$this
->getSession()
->getPage()
->clickLink('Add address');
$this
->getSession()
->getPage()
->fillField('address[0][address][country_code]', 'FR');
$this
->assertSession()
->assertWaitOnAjaxRequest();
foreach ($this->fourthAddress as $property => $value) {
$this
->getSession()
->getPage()
->fillField("address[0][address][{$property}]", $value);
}
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains('Saved the 38 Rue du Sentier address.');
$rendered_address = $this
->getSession()
->getPage()
->find('css', 'p.address');
$this
->assertNotEmpty($rendered_address);
$this
->assertStringContainsString('38 Rue du Sentier', $rendered_address
->getText());
// Confirm that a profile can be edited.
$this
->getSession()
->getPage()
->clickLink('Edit');
foreach ($this->fourthAddress as $property => $value) {
$this
->assertSession()
->fieldValueEquals("address[0][address][{$property}]", $value);
}
$this
->submitForm([
'address[0][address][address_line1]' => '39 Rue du Sentier',
], 'Save');
$this
->assertSession()
->pageTextContains('Saved the 39 Rue du Sentier address.');
$rendered_address = $this
->getSession()
->getPage()
->find('css', 'p.address');
$this
->assertNotEmpty($rendered_address);
$this
->assertStringContainsString('39 Rue du Sentier', $rendered_address
->getText());
// Confirm that a profile can be set as default.
/** @var \Drupal\profile\Entity\ProfileInterface $second_profile */
$second_profile = $this
->createEntity('profile', [
'type' => 'customer',
'uid' => $customer
->id(),
'address' => $this->secondAddress,
]);
$this
->assertFalse($second_profile
->isDefault());
$this
->drupalGet(Url::fromRoute('commerce_order.address_book.overview', [
'user' => $customer
->id(),
]));
$this
->assertSession()
->pageTextContains('39 Rue du Sentier');
$this
->assertSession()
->pageTextContains($this->secondAddress['address_line1']);
$set_default_links = $this
->getSession()
->getPage()
->findAll('css', '.address-book__set-default-link');
$this
->assertCount(1, $set_default_links);
$set_default_link = reset($set_default_links);
$set_default_link
->click();
$this
->assertSession()
->pageTextContains($this->secondAddress['address_line1'] . ' is now the default address.');
$set_default_links = $this
->getSession()
->getPage()
->findAll('css', '.address-book__set-default-link');
$this
->assertCount(1, $set_default_links);
$set_default_link = reset($set_default_links);
$set_default_link
->click();
$this
->assertSession()
->pageTextContains('39 Rue du Sentier is now the default address.');
// Confirm that a profile can be deleted.
$delete_links = $this
->getSession()
->getPage()
->findAll('css', '.address-book__delete-link');
$this
->assertCount(2, $delete_links);
$delete_link = reset($delete_links);
$delete_link
->click();
$this
->assertSession()
->pageTextContains('Are you sure you want to delete the 39 Rue du Sentier address?');
$this
->submitForm([], 'Delete');
$this
->assertSession()
->pageTextContains('The 39 Rue du Sentier address has been deleted.');
}