public function TfaRecoveryCodePluginTest::testRecoveryCodeSetup in Two-factor Authentication (TFA) 8
Check that the user can setup recovery codes.
File
- tests/
src/ Functional/ TfaRecoveryCodePluginTest.php, line 111
Class
- TfaRecoveryCodePluginTest
- Class TfaRecoveryCodeSetupPluginTest.
Namespace
Drupal\Tests\tfa\FunctionalCode
public function testRecoveryCodeSetup() {
$this
->drupalLogin($this->userAccount);
$this
->drupalGet('user/' . $this->userAccount
->id() . '/security/tfa/' . $this->validationPluginId . '/1');
$assert = $this
->assertSession();
$assert
->statusCodeEquals(200);
$assert
->responseContains('Enter your current password');
// Provide the user's password to continue.
$edit = [
'current_pass' => $this->userAccount->passRaw,
];
$this
->submitForm($edit, 'Confirm');
$assert
->responseContains('Save codes to account');
$this
->submitForm([], 'Save codes to account');
$assert
->pageTextContains('TFA setup complete.');
// Make sure codes were saved to the account.
$codes = $this->validationPlugin
->getCodes();
$assert
->assert(!empty($codes), 'No codes saved to the account data.');
// Now the user should be able to see their existing codes. Let's test that.
$assert
->linkExists('Show codes');
$this
->drupalGet('user/' . $this->userAccount
->id() . '/security/tfa/' . $this->validationPluginId);
$edit = [
'current_pass' => $this->userAccount->passRaw,
];
$this
->submitForm($edit, 'Confirm');
$assert
->statusCodeEquals(200);
// The "save" button should not exists when viewing existing codes.
$assert
->responseNotContains('Save codes to account');
}