You are here

public function AjaxFormCacheTest::testFormCacheUsage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Ajax/AjaxFormCacheTest.php \Drupal\system\Tests\Ajax\AjaxFormCacheTest::testFormCacheUsage()

Tests the usage of form cache for AJAX forms.

File

core/modules/system/src/Tests/Ajax/AjaxFormCacheTest.php, line 24
Contains \Drupal\system\Tests\Ajax\AjaxFormCacheTest.

Class

AjaxFormCacheTest
Tests the usage of form caching for AJAX forms.

Namespace

Drupal\system\Tests\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
    ->assertEqual(0, count($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
    ->assertEqual(0, count($key_value_expirable
    ->getAll()));
}