1 user.test UserLoginTestCase::testLoginMethods()

Test that login credentials work (or not) in different login modes.

File

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

Class

UserLoginTestCase
Functional tests for user logins, including rate limiting of login attempts.

Code

function testLoginMethods() {
  $account = $this->backdropCreateUser(array());

  // Login via name or email (both succeed). The default for new sites.
  config_set('system.core', 'user_login_method', USER_LOGIN_USERNAME_OR_EMAIL);
  $this->backdropLogin($account, TRUE);
  $this->backdropLogin($account);

  // Login via email only.
  config_set('system.core', 'user_login_method', USER_LOGIN_EMAIL_ONLY);
  $this->backdropLogin($account, TRUE);
  // Fail login via name.
  $this->assertFailedLogin($account);

  // Login via name.
  config_set('system.core', 'user_login_method', USER_LOGIN_USERNAME_ONLY);
  $this->backdropLogin($account);
  // Fail login via email.
  $this->assertFailedLogin($account, TRUE);

  // Test login when no user_login_method is set. Allows for logging in for
  // users that are upgrading their site for the first time to support login
  // by username.
  config_set('system.core', 'user_login_method', NULL);
  $this->backdropLogin($account);
  // Fail login via email.
  $this->assertFailedLogin($account, TRUE);
}