You are here

public function UserRegistrationTest::testRegistrationEmailDuplicates in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserRegistrationTest.php \Drupal\Tests\user\Functional\UserRegistrationTest::testRegistrationEmailDuplicates()

File

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

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
    ->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.');
}