You are here

protected function TfaTestBase::canEnableValidationPlugin in Two-factor Authentication (TFA) 8

Reusable test for enabling a validation plugin on the configuration form.

Parameters

string $validation_plugin_id: A validation plugin id.

3 calls to TfaTestBase::canEnableValidationPlugin()
TfaConfigTest::testTfaConfigForm in tests/src/Functional/TfaConfigTest.php
Test to check if configurations are working as desired.
TfaLoginTest::setUp in tests/src/Functional/TfaLoginTest.php
TfaRecoveryCodePluginTest::testEnableValidationPlugin in tests/src/Functional/TfaRecoveryCodePluginTest.php
Test that we can enable the plugin.

File

tests/src/Functional/TfaTestBase.php, line 96

Class

TfaTestBase
Base class for testing the Tfa module.

Namespace

Drupal\Tests\tfa\Functional

Code

protected function canEnableValidationPlugin($validation_plugin_id) {
  $assert = $this
    ->assertSession();
  $adminUser = $this
    ->drupalCreateUser([
    'admin tfa settings',
  ]);
  $this
    ->drupalLogin($adminUser);
  $this
    ->drupalGet('admin/config/people/tfa');
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('TFA Settings');
  $edit = [
    'tfa_enabled' => TRUE,
    'tfa_validate' => $validation_plugin_id,
    "tfa_allowed_validation_plugins[{$validation_plugin_id}]" => $validation_plugin_id,
    'encryption_profile' => $this->encryptionProfile
      ->id(),
  ];
  $this
    ->submitForm($edit, 'Save configuration');
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('The configuration options have been saved.');
  $select_field_id = 'edit-tfa-validate';
  $option_field = $assert
    ->optionExists($select_field_id, $validation_plugin_id);
  $result = $option_field
    ->hasAttribute('selected');
  $assert
    ->assert($result, "Option {$validation_plugin_id} for field {$select_field_id} is selected.");
}