You are here

public function ReCaptchaBasicTest::testReCaptchaAdminSettingsForm in reCAPTCHA 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/ReCaptchaBasicTest.php \Drupal\Tests\recaptcha\Functional\ReCaptchaBasicTest::testReCaptchaAdminSettingsForm()

Test the reCAPTCHA settings form.

File

tests/src/Functional/ReCaptchaBasicTest.php, line 79

Class

ReCaptchaBasicTest
Test basic functionality of reCAPTCHA module.

Namespace

Drupal\Tests\recaptcha\Functional

Code

public function testReCaptchaAdminSettingsForm() {
  $this
    ->drupalLogin($this->adminUser);
  $site_key = $this
    ->randomMachineName(40);
  $secret_key = $this
    ->randomMachineName(40);

  // Check form validation.
  $edit['recaptcha_site_key'] = '';
  $edit['recaptcha_secret_key'] = '';
  $this
    ->drupalPostForm('admin/config/people/captcha/recaptcha', $edit, $this
    ->t('Save configuration'));
  $this
    ->assertSession()
    ->responseContains($this
    ->t('Site key field is required.'), '[testReCaptchaConfiguration]: Empty site key detected.');
  $this
    ->assertSession()
    ->responseContains($this
    ->t('Secret key field is required.'), '[testReCaptchaConfiguration]: Empty secret key detected.');

  // Save form with valid values.
  $edit['recaptcha_site_key'] = $site_key;
  $edit['recaptcha_secret_key'] = $secret_key;
  $edit['recaptcha_tabindex'] = 0;
  $this
    ->drupalPostForm('admin/config/people/captcha/recaptcha', $edit, $this
    ->t('Save configuration'));
  $this
    ->assertSession()
    ->responseContains($this
    ->t('The configuration options have been saved.'), '[testReCaptchaConfiguration]: The configuration options have been saved.');
  $this
    ->assertSession()
    ->responseNotContains($this
    ->t('Site key field is required.'), '[testReCaptchaConfiguration]: Site key was not empty.');
  $this
    ->assertSession()
    ->responseNotContains($this
    ->t('Secret key field is required.'), '[testReCaptchaConfiguration]: Secret key was not empty.');
  $this
    ->assertSession()
    ->responseNotContains($this
    ->t('The tabindex must be an integer.'), '[testReCaptchaConfiguration]: Tab index had a valid input.');
  $this
    ->drupalLogout();
}