public function TfaTestCase::testRedirection in Two-factor Authentication (TFA) 7.2
Test redirection.
File
- tests/
tfa.test, line 210 - Drupal test cases for TFA.
Class
- TfaTestCase
- Tests the functionality of the TFA module.
Code
public function testRedirection() {
// Enable test plugin.
variable_set('tfa_validate_plugin', 'tfa_test_send');
$code = $this
->randomName();
variable_set('tfa_test_code', $code);
$account = $this->web_user;
$login = array(
'name' => $account->name,
'pass' => $account->pass_raw,
);
// Set destination to filter tips page.
$options = array(
'query' => array(
'destination' => 'filter/tips',
),
);
$this
->drupalPost('user/login', $login, 'Log in', $options);
// Reload account since login timestamp is updated.
$account = user_load($account->uid);
$login_hash = tfa_login_hash($account);
// Authenticate with code.
$edit = array(
'code' => $code,
);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, $edit, 'Submit', $options);
$this
->assertLink('Log out', 0, 'Logout link appears');
// Confirm user is on filter tips page.
$this
->assertText('Compose tips', 'Redirected page text appears');
$this
->drupalLogout();
// Test form_state redirect. tfa_test module sets filter/tips redirect.
variable_set('tfa_test_login_form_redirect', TRUE);
$this
->drupalPost('user/login', $login, 'Log in');
$edit = array(
'code' => $code,
);
$this
->drupalPost(NULL, $edit, 'Submit');
$this
->assertLink('Log out', 0, 'Logout link appears');
// Confirm user is on filter tips page.
$this
->assertText('Compose tips', 'Redirected page text appears');
// @todo test one-time login redirection.
}