public function TfaTestCase::testSetup in Two-factor Authentication (TFA) 7.2
Test the TfaSetup forms and process in tfa_test.module.
This test illustrates how a user would setup a TFA send plugin. See tfa_test.module tfa_test_setup_form() for how to use.
File
- tests/
tfa.test, line 329 - Drupal test cases for TFA.
Class
- TfaTestCase
- Tests the functionality of the TFA module.
Code
public function testSetup() {
variable_set('tfa_enabled', FALSE);
$account = $this->web_user;
$this
->drupalLogin($account);
// Enable TFA and begin configuration.
variable_set('tfa_enabled', TRUE);
variable_set('tfa_validate_plugin', 'tfa_test_send');
variable_set('tfa_test_setup_class', 'TfaTestSendSetup');
$this
->drupalGet('user/' . $account->uid . '/tfa');
$edit = array();
$this
->drupalPost(NULL, $edit, 'Setup send');
// Set plugin location to account name.
$edit = array(
'location' => $account->name,
);
$this
->drupalPost(NULL, $edit, 'Submit');
// Enter default test code.
$edit = array(
'code' => variable_get('tfa_test_code', 'TEST'),
);
$this
->drupalPost(NULL, $edit, 'Submit');
// Logout to now test TFA process.
$this
->drupalGet('user/logout');
$edit = array(
'name' => $account->name,
'pass' => $account->pass_raw,
);
// Not using drupalLogin() since it tests for actual login.
$this
->drupalPost('user/login', $edit, 'Log in');
// Get login hash. Could user tfa_login_hash() but would require reloading
// account.
$url_parts = explode('/', $this->url);
$login_hash = array_pop($url_parts);
// Confirm login with code as account name.
// TfaTestSendSetup::submitSetupForm() would have set the test code to it.
$edit = array(
'code' => $account->name,
);
$this
->drupalPost('system/tfa/' . $account->uid . '/' . $login_hash, $edit, 'Submit');
$this
->assertLink('Log out', 0, 'Logout link appears');
}