You are here

public function CaptchaTest::testLongFormId in CAPTCHA 8

Test that forms with IDs exceeding 64 characters can be assigned captchas.

File

tests/src/Functional/CaptchaTest.php, line 256

Class

CaptchaTest
Tests CAPTCHA main test case sensitivity.

Namespace

Drupal\Tests\captcha\Functional

Code

public function testLongFormId() {

  // We add the form manually so we can mimic the character
  // truncation of the label field as formId.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH);
  $label = 'this_formid_is_intentionally_longer_than_64_characters_to_test_captcha';

  // Truncated to 64 chars so it can be a machine name.
  $formId = substr($label, 0, 64);
  $form_values = [
    'label' => $label,
    'formId' => $formId,
    'captchaType' => 'captcha/Math',
  ];

  // Create intentionally long id Captcha Point.
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH . '/captcha-points/add');
  $this
    ->submitForm($form_values, $this
    ->t('Save'));
  $this
    ->assertSession()
    ->responseContains($this
    ->t('Captcha Point for %label form was created.', [
    '%label' => $formId,
  ]));

  // We need to log out to test the captcha.
  $this
    ->drupalLogout();

  // Navigate to the form with a >64 char id and confirm there is Captcha.
  $this
    ->drupalGet('captcha/test_form/long_id');
  $this
    ->assertCaptchaPresence(TRUE);
}