You are here

public function BasicUserTest::testMultipleEmailBasicUser in Multiple E-mail Addresses 2.x

Test that the Multiple E-mails user can add a new e-mail address.

File

src/Tests/BasicUserTest.php, line 39
Definition of Drupal\multiple_email\Tests\BasicUserTest.

Class

BasicUserTest
Test basic user registration without 'use multiple email permissions' and its interactions with the module.

Namespace

Drupal\multiple_email\Tests

Code

public function testMultipleEmailBasicUser() {

  // Test that the e-mail address appears on the page
  $this
    ->drupalGet('user/' . $this->loggedInUser
    ->id() . '/edit');
  $this
    ->assertRaw($this->loggedInUser
    ->getEmail(), t('Registered e-mail successfully added'));

  // Test can't add a new e-mail address.
  $edit = array(
    'email' => $this
      ->randomMachineName() . '@example.com',
    'current_pass' => $this->loggedInUser->pass_raw,
  );
  $this
    ->drupalGet('user/' . $this->loggedInUser
    ->id() . '/edit/email-addresses');
  $this
    ->assertNoText(t('Add E-mail Address'));

  // Load the address object.
  $addresses = multiple_email_load_addresses($this->loggedInUser
    ->id());
  array_shift($addresses);
  foreach ($addresses as $address) {
    if ($address->email == $this->loggedInUser
      ->getEmail()) {
      break;
    }
  }

  // Test submitting the user edit form with the same address.
  $this
    ->drupalGet('user/' . $this->loggedInUser
    ->id() . '/edit');
  $this
    ->assertRaw($address->email);
  $edit = array(
    'mail' => $address->email,
  );
  $this
    ->drupalPostForm('user/' . $this->loggedInUser
    ->id() . '/edit', $edit, t('Save'));
  $this
    ->assertText(t('The changes have been saved.'));
  $this
    ->assertRaw($edit['mail']);

  // Test submitting the user edit  form with a different address.
  $edit = array(
    'mail' => $this
      ->randomMachineName() . '@example.com',
    'current_pass' => $this->loggedInUser->pass_raw,
  );
  $this
    ->drupalPostForm('user/' . $this->loggedInUser
    ->id() . '/edit', $edit, t('Save'));
  $this
    ->assertText(t('The changes have been saved.'));
  $this
    ->assertRaw($edit['mail']);

  // Test deleting the address.
  $this
    ->drupalGet('user/' . $this->loggedInUser
    ->id() . '/edit/email-addresses/delete/' . $address->eid);
  $this
    ->assertNoRaw(t('Are you sure you wish to delete the address %email from your user account?', array(
    '%email' => $edit['mail'],
  )));
}