You are here

public function CaptchaTest::testCaptchaResponseErrorMenssage in CAPTCHA 8

Testing the response error menssage.

File

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

Class

CaptchaTest
Tests CAPTCHA main test case sensitivity.

Namespace

Drupal\Tests\captcha\Functional

Code

public function testCaptchaResponseErrorMenssage() {

  // Customize the response error message.
  $this
    ->drupalLogin($this->adminUser);
  $customized_menssage = 'The answer you entered is wrong.';
  $edit = [
    'wrong_captcha_response_message' => $customized_menssage,
  ];
  $this
    ->drupalGet("admin/config/people/captcha");
  $this
    ->submitForm($edit, $this
    ->t('Save configuration'));

  // Set a CAPTCHA on login form.

  /* @var \Drupal\captcha\Entity\CaptchaPoint $captcha_point */
  $captcha_point = \Drupal::entityTypeManager()
    ->getStorage('captcha_point')
    ->load('user_login_form');
  $captcha_point
    ->setCaptchaType('captcha/Math');
  $captcha_point
    ->enable()
    ->save();

  // Check if the menssage is default.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('user');

  // Try to log in, which should fail.
  $edit = [
    'name' => $this->adminUser
      ->getDisplayName(),
    'pass' => $this->adminUser->pass_raw,
    'captcha_response' => '?',
  ];
  $this
    ->submitForm($edit, $this
    ->t('Log in'), self::LOGIN_HTML_FORM_ID);
  $this
    ->assertSession()
    ->pageTextContains($customized_menssage, 'CAPTCHA should block user login form', 'CAPTCHA');
}