You are here

public function CaptchaAdminTest::testCaptchaPlacementCacheClearing in CAPTCHA 8

Test the CAPTCHA placement clearing.

File

tests/src/Functional/CaptchaAdminTest.php, line 242

Class

CaptchaAdminTest
Tests CAPTCHA admin settings.

Namespace

Drupal\Tests\captcha\Functional

Code

public function testCaptchaPlacementCacheClearing() {

  // Set CAPTCHA on user register form.
  captcha_set_form_id_setting('user_register_form', 'captcha/Math');

  // Visit user register form to fill the CAPTCHA placement cache.
  $this
    ->drupalGet('user/register');

  // Check if there is CAPTCHA placement cache.
  $placement_map = $this->container
    ->get('cache.default')
    ->get('captcha_placement_map_cache');
  $this
    ->assertNotNull($placement_map, 'CAPTCHA placement cache should be set.');

  // Clear the cache.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet(self::CAPTCHA_ADMIN_PATH);
  $this
    ->submitForm([], $this
    ->t('Clear the CAPTCHA placement cache'));

  // Check that the placement cache is unset.
  $placement_map = $this->container
    ->get('cache.default')
    ->get('captcha_placement_map_cache');
  $this
    ->assertFalse($placement_map, 'CAPTCHA placement cache should be unset after cache clear.');
}