function UserRegistrationTest::testRegistrationEmailDuplicates

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

File

core/modules/user/tests/src/Functional/UserRegistrationTest.php, line 138

Class

UserRegistrationTest
Tests registration of user under different configurations.

Namespace

Drupal\Tests\user\Functional

Code

public function testRegistrationEmailDuplicates() {
    // Don't require email verification and allow registration by site visitors
    // without administrator approval.
    $this->config('user.settings')
        ->set('verify_mail', FALSE)
        ->set('register', UserInterface::REGISTER_VISITORS)
        ->save();
    // Set up a user to check for duplicates.
    $duplicate_user = $this->drupalCreateUser();
    $edit = [];
    $edit['name'] = $this->randomMachineName();
    $edit['mail'] = $duplicate_user->getEmail();
    // Attempt to create a new account using an existing email address.
    $this->drupalPostForm('user/register', $edit, t('Create new account'));
    $this->assertText(t('The email address @email is already taken.', [
        '@email' => $duplicate_user->getEmail(),
    ]), 'Supplying an exact duplicate email address displays an error message');
    // Attempt to bypass duplicate email registration validation by adding spaces.
    $edit['mail'] = '   ' . $duplicate_user->getEmail() . '   ';
    $this->drupalPostForm('user/register', $edit, t('Create new account'));
    $this->assertText(t('The email address @email is already taken.', [
        '@email' => $duplicate_user->getEmail(),
    ]), 'Supplying a duplicate email address with added whitespace displays an error message');
}

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