You are here

public function GaLoginBasicPermissionsTestCase::testRegularLogin in Google Authenticator login 7

Test regualr login.

File

./ga_login.test, line 35
Tests for ga_login.module.

Class

GaLoginBasicPermissionsTestCase
Test basic permissions.

Code

public function testRegularLogin() {
  $account = $this
    ->drupalCreateUser();

  // Valid password.
  $edit = array();
  $edit['name'] = $account->name;
  $edit['pass'] = $account->pass_raw;
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Member for'));

  // Make sure we can not access the ga_login tab.
  $edit = array();
  $this
    ->drupalGet("user/{$account->uid}/ga_login");
  $this
    ->assertText(t("You are not authorized to access this page."));
  $this
    ->drupalLogout();

  // Wrong password.
  $edit = array();
  $edit['name'] = $account->name;
  $edit['pass'] = "Wrong password" . $account->pass_raw;
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'));

  // Valid password with invalid code and invalid format.
  $edit = array();
  $edit['name'] = $account->name;
  $edit['pass'] = $account->pass_raw;
  $edit['gacode'] = '12345';
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Code has to be exactly 6 digits.'));
  $this
    ->drupalLogout();

  // Valid password with invalid code, but valid format.
  $edit = array();
  $edit['name'] = $account->name;
  $edit['pass'] = $account->pass_raw;
  $edit['gacode'] = '123456';
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Member for'));
  $this
    ->drupalLogout();

  // Wrong password with invalid code, but valid format.
  $edit = array();
  $edit['name'] = $account->name;
  $edit['pass'] = "Wrong password" . $account->pass_raw;
  $edit['gacode'] = '123456';
  $this
    ->drupalPost('user', $edit, t('Log in'));
  $this
    ->assertText(t('Sorry, unrecognized username or password'));

  // Use reset login link.
  $full_account = user_load($account->uid, TRUE);
  $timestamp = $full_account->login;
  $this
    ->drupalGet("user/reset/{$full_account->uid}/{$timestamp}/" . user_pass_rehash($full_account->pass, $timestamp, $full_account->login, $full_account->uid));
  $this
    ->assertText(t('Click on this button to log in to the site and change your password.'));
  $this
    ->drupalLogout();
}