You are here

public function UserTest::testNoEmailsError in Multiple E-mail Addresses 2.x

File

src/Tests/UserTest.php, line 131
Definition of Drupal\multiple_email\Tests\UserTest.

Class

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

Namespace

Drupal\multiple_email\Tests

Code

public function testNoEmailsError() {

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

  // Test adding a new e-mail address.
  $edit = array(
    'email' => $this
      ->randomMachineName() . '@example.com',
  );
  $this
    ->drupalPostForm('user/' . $this->loggedInUser
    ->id() . '/edit/email-addresses', $edit, t('Save'));
  $this
    ->assertRaw(t('The e-mail address %email has been added to your account. Check your e-mail in order to confirm this new address.', array(
    '%email' => $edit['email'],
  )), t('Email successfully added.'));

  // Lets delete these emails via sql query
  // @TODO Can it be done via UI?
  $deleteQuery = db_delete('multiple_email')
    ->condition('uid', $this->loggedInUser
    ->id())
    ->execute();
  $this
    ->drupalGet('user/' . $this->loggedInUser
    ->id() . '/edit/email-addresses');
  $this
    ->assertText('Unable to find any e-mail addresses.', 'Error message was shown');
  $this
    ->assertNoRaw($this->loggedInUser
    ->getEmail(), 'Primary email was deleted from this view');
  $this
    ->assertNoRaw($edit['email'], 'Secondary email was deleted from this view');
}