protected function UserCreateFailMailTest::testUserAdd

Tests the create user administration page.

File

drupal/core/modules/user/lib/Drupal/user/Tests/UserCreateFailMailTest.php, line 35
Contains Drupal\user\Tests\UserCreateFailMailTest.

Class

UserCreateFailMailTest
Tests the create user administration page.

Namespace

Drupal\user\Tests

Code

protected function testUserAdd() {
  $user = $this
    ->drupalCreateUser(array(
    'administer users',
  ));
  $this
    ->drupalLogin($user);

  // Replace the mail functionality with a fake, malfunctioning service.
  config('system.mail')
    ->set('interface.default', 'Drupal\\system_mail_failure_test\\TestPhpMailFailure')
    ->save();

  // Create a user, but fail to send an email.
  $name = $this
    ->randomName();
  $edit = array(
    'name' => $name,
    'mail' => $this
      ->randomName() . '@example.com',
    'pass[pass1]' => $pass = $this
      ->randomString(),
    'pass[pass2]' => $pass,
    'notify' => TRUE,
  );
  $this
    ->drupalPost('admin/people/create', $edit, t('Create new account'));
  $this
    ->assertText(t('Unable to send e-mail. Contact the site administrator if the problem persists.'));
  $this
    ->assertNoText(t('A welcome message with further instructions has been e-mailed to the new user @name.', array(
    '@name' => $edit['name'],
  )));
}