You are here

function UserRegistrationTest::testRegistrationEmailDuplicates in Zircon Profile 8

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

File

core/modules/user/src/Tests/UserRegistrationTest.php, line 131
Contains \Drupal\user\Tests\UserRegistrationTest.

Class

UserRegistrationTest
Tests registration of user under different configurations.

Namespace

Drupal\user\Tests

Code

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', USER_REGISTER_VISITORS)
    ->save();

  // Set up a user to check for duplicates.
  $duplicate_user = $this
    ->drupalCreateUser();
  $edit = array();
  $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.', array(
    '@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.', array(
    '@email' => $duplicate_user
      ->getEmail(),
  )), 'Supplying a duplicate email address with added whitespace displays an error message');
}