You are here

public function EmailRegistrationTestCase::testRegistration in Email Registration 7

Same name and namespace in other branches
  1. 6 email_registration.test \EmailRegistrationTestCase::testRegistration()

Test various behaviors for anonymous users.

File

./email_registration.test, line 36
Contains EmailRegistrationTestCase.

Class

EmailRegistrationTestCase
@file Contains EmailRegistrationTestCase.

Code

public function testRegistration() {

  // Try to register a user.
  $name = $this
    ->randomName();
  $pass = $this
    ->randomName(10);
  $register = array(
    'mail' => $name . '@example.com',
    'pass[pass1]' => $pass,
    'pass[pass2]' => $pass,
  );
  $this
    ->drupalPost('/user/register', $register, t('Create new account'));
  $this
    ->drupalLogout();
  $login = array(
    'name' => $name . '@example.com',
    'pass' => $pass,
  );
  $this
    ->drupalPost('user/login', $login, t('Log in'));

  // Get the account to get uid.
  $new_user = user_load_by_mail($name . '@example.com');
  $new_name = $name . '_' . $new_user->uid;

  // Confirm the user was created and logged in with expected username.
  $this
    ->assertTitle($new_name . ' | Drupal', 'User properly created, logged in.');

  // Now try the immediate login.
  $this
    ->drupalLogout();
  $name = $this
    ->randomName();
  $pass = $this
    ->randomName(10);
  $register = array(
    'mail' => $name . '@example.com',
    'pass[pass1]' => $pass,
    'pass[pass2]' => $pass,
  );
  $this
    ->drupalPost('/user/register', $register, t('Create new account'));
  $this
    ->assertRaw('Registration successful. You are now logged in.', 'User properly created, immediately logged in.');

  // Try to login with just username, should succeed by default.
  $this
    ->drupalLogout();

  // User name appended with UID see email_registration_cleanup_username().
  $new_user = user_load_by_mail($name . '@example.com');
  $new_name = $name . '_' . $new_user->uid;
  $login = array(
    'name' => $new_name,
    'pass' => $pass,
  );
  $this
    ->drupalPost('user/login', $login, t('Log in'));
  $this
    ->assertTitle($new_name . ' | Drupal', 'By default, username can log in.');
  $this
    ->drupalLogout();

  // Disallow logins with username and try to login with just username, should fail.
  variable_set('email_registration_login_with_username', FALSE);
  $this
    ->drupalPost('user/login', $login, t('Log in'));
  $this
    ->assertTitle('User account | Drupal', 'When disabled, a user cannot login with just their username.');
}