public function GaLoginBasicPermissionsTestCase::testRequireCodePermissionWithoutCode in Google Authenticator login 7
Test require code permission.
File
- ./
ga_login.test, line 154 - Tests for ga_login.module.
Class
- GaLoginBasicPermissionsTestCase
- Test basic permissions.
Code
public function testRequireCodePermissionWithoutCode() {
// Require code overrides login without code.
$account = $this
->drupalCreateUser(array(
'login without code',
'require code',
));
// Valid password.
$edit = array();
$edit['name'] = $account->name;
$edit['pass'] = $account->pass_raw;
$this
->drupalPost('user', $edit, t('Log in'));
$this
->assertText(t('Your code is required to log in.'));
$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('Your code is required to log in.'));
$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();
}