function UserCreateFailMailTest::testUserAdd

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/UserCreateFailMailTest.php \Drupal\Tests\user\Functional\UserCreateFailMailTest::testUserAdd()
  2. 10 core/modules/user/tests/src/Functional/UserCreateFailMailTest.php \Drupal\Tests\user\Functional\UserCreateFailMailTest::testUserAdd()
  3. 11.x core/modules/user/tests/src/Functional/UserCreateFailMailTest.php \Drupal\Tests\user\Functional\UserCreateFailMailTest::testUserAdd()

Tests the create user administration page.

File

core/modules/user/tests/src/Functional/UserCreateFailMailTest.php, line 29

Class

UserCreateFailMailTest
Tests the create user administration page.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserAdd() {
    $user = $this->drupalCreateUser([
        'administer users',
    ]);
    $this->drupalLogin($user);
    // Replace the mail functionality with a fake, malfunctioning service.
    $this->config('system.mail')
        ->set('interface.default', 'test_php_mail_failure')
        ->save();
    // Create a user, but fail to send an email.
    $name = $this->randomMachineName();
    $edit = [
        'name' => $name,
        'mail' => $this->randomMachineName() . '@example.com',
        'pass[pass1]' => $pass = $this->randomString(),
        'pass[pass2]' => $pass,
        'notify' => TRUE,
    ];
    $this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
    $this->assertText(t('Unable to send email. Contact the site administrator if the problem persists.'));
    $this->assertNoText(t('A welcome message with further instructions has been emailed to the new user @name.', [
        '@name' => $edit['name'],
    ]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.