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. 8.9.x 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 146

Class

UserRegistrationTest
Tests registration of user under different configurations.

Namespace

Drupal\Tests\user\Functional

Code

public function testRegistrationEmailDuplicates() : void {
    // 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->drupalGet('user/register');
    $this->submitForm($edit, 'Create new account');
    $this->assertSession()
        ->pageTextContains('The email address ' . $duplicate_user->getEmail() . ' is already taken.');
    // Attempt to bypass duplicate email registration validation by adding spaces.
    $edit['mail'] = '   ' . $duplicate_user->getEmail() . '   ';
    $this->drupalGet('user/register');
    $this->submitForm($edit, 'Create new account');
    $this->assertSession()
        ->pageTextContains('The email address ' . $duplicate_user->getEmail() . ' is already taken.');
}

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