You are here

public function AjaxFormCacheTest::testFormCacheUsage in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testFormCacheUsage()
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php \Drupal\FunctionalJavascriptTests\Ajax\AjaxFormCacheTest::testFormCacheUsage()

Tests the usage of form cache for AJAX forms.

File

core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php, line 30

Class

AjaxFormCacheTest
Tests the usage of form caching for AJAX forms.

Namespace

Drupal\FunctionalJavascriptTests\Ajax

Code

public function testFormCacheUsage() {

  /** @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable */
  $key_value_expirable = \Drupal::service('keyvalue.expirable')
    ->get('form');
  $this
    ->drupalLogin($this->rootUser);

  // Ensure that the cache is empty.
  $this
    ->assertCount(0, $key_value_expirable
    ->getAll());

  // Visit an AJAX form that is not cached, 3 times.
  $uncached_form_url = Url::fromRoute('ajax_forms_test.commands_form');
  $this
    ->drupalGet($uncached_form_url);
  $this
    ->drupalGet($uncached_form_url);
  $this
    ->drupalGet($uncached_form_url);

  // The number of cache entries should not have changed.
  $this
    ->assertCount(0, $key_value_expirable
    ->getAll());
}