You are here

function MultipleEmailBasicUserTestCase::testMultipleEmailBasicUser in Multiple E-mail Addresses 7

Same name and namespace in other branches
  1. 6 multiple_email.test \MultipleEmailBasicUserTestCase::testMultipleEmailBasicUser()

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

File

./multiple_email.test, line 182
Tests for the Multiple E-mail module

Class

MultipleEmailBasicUserTestCase

Code

function testMultipleEmailBasicUser() {

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

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

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

  // Test submitting the user edit form with the same address.
  $this
    ->drupalGet('user/' . $this->loggedInUser->uid . '/edit');
  $this
    ->assertRaw($address->email);
  $edit = array(
    'mail' => $address->email,
  );
  $this
    ->drupalPost('user/' . $this->loggedInUser->uid . '/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
      ->randomName() . '@example.com',
    'current_pass' => $this->loggedInUser->pass_raw,
  );
  $this
    ->drupalPost('user/' . $this->loggedInUser->uid . '/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->uid . '/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'],
  )));
}