You are here

function UserRegistrationTestCase::testRegistrationEmailDuplicates in Drupal 7

File

modules/user/user.test, line 111
Tests for user.module.

Class

UserRegistrationTestCase
@file Tests for user.module.

Code

function testRegistrationEmailDuplicates() {

  // Don't require e-mail verification.
  variable_set('user_email_verification', FALSE);

  // Allow registration by site visitors without administrator approval.
  variable_set('user_register', USER_REGISTER_VISITORS);

  // Set up a user to check for duplicates.
  $duplicate_user = $this
    ->drupalCreateUser();
  $edit = array();
  $edit['name'] = $this
    ->randomName();
  $edit['mail'] = $duplicate_user->mail;

  // Attempt to create a new account using an existing e-mail address.
  $this
    ->drupalPost('user/register', $edit, t('Create new account'));
  $this
    ->assertText(t('The e-mail 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
    ->drupalPost('user/register', $edit, t('Create new account'));
  $this
    ->assertText(t('The e-mail address @email is already registered.', array(
    '@email' => $duplicate_user->mail,
  )), 'Supplying a duplicate email address with added whitespace displays an error message');
}