1 user.test UserRegistrationTestCase::testRegistrationEmailDuplicates()

File

core/modules/user/tests/user.test, line 173
Tests for user.module.

Class

UserRegistrationTestCase

Code

function testRegistrationEmailDuplicates() {
  $config = config('system.core');

  // Don't require email verification.
  $config->set('user_email_verification', FALSE)->save();

  // Allow registration by site visitors without administrator approval.
  $config->set('user_register', USER_REGISTER_VISITORS)->save();

  // Set up a user to check for duplicates.
  $duplicate_user = $this->backdropCreateUser();

  $edit = array();
  $edit['name'] = $this->randomName();
  $edit['mail'] = $duplicate_user->mail;

  // Attempt to create a new account using an existing email address.
  $this->backdropPost('user/register', $edit, t('Create new account'));
  $this->assertRaw(t('The email address %email is already registered.', array('%email' => $duplicate_user->mail)), 'Supplying an exact duplicate email address displays an error message');

  // Attempt to bypass duplicate email registration validation by adding spaces.
  $edit['mail'] = '   ' . $duplicate_user->mail . '   ';

  $this->backdropPost('user/register', $edit, t('Create new account'));
  $this->assertRaw(t('The email address %email is already registered.', array('%email' => $duplicate_user->mail)), 'Supplying a duplicate email address with added whitespace displays an error message');
}