You are here

public function CaptchaTest::testCaptchaOnLoginBlockOnAdminPagesIssue893810 in CAPTCHA 8

CAPTCHA should be put on admin pages even if visitor has no access.

File

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

Class

CaptchaTest
Tests CAPTCHA main test case sensitivity.

Namespace

Drupal\Tests\captcha\Functional

Code

public function testCaptchaOnLoginBlockOnAdminPagesIssue893810() {

  // Set a CAPTCHA on login block 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();

  // Enable the user login block.
  $this
    ->drupalPlaceBlock('user_login_block', [
    'id' => 'login',
  ]);

  // Check if there is a CAPTCHA on home page.
  $this
    ->drupalGet('');
  $this
    ->assertCaptchaPresence(TRUE);

  // Check there is a CAPTCHA on "forbidden" admin pages.
  $this
    ->drupalGet('admin');
  $this
    ->assertCaptchaPresence(TRUE);
}