You are here

public function FormCacheTest::testCacheCustomExpiration in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php \Drupal\KernelTests\Core\Form\FormCacheTest::testCacheCustomExpiration()
  2. 9 core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php \Drupal\KernelTests\Core\Form\FormCacheTest::testCacheCustomExpiration()

Tests the form cache with an overridden cache expiration.

File

core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php, line 107

Class

FormCacheTest
Tests \Drupal::formBuilder()->setCache() and \Drupal::formBuilder()->getCache().

Namespace

Drupal\KernelTests\Core\Form

Code

public function testCacheCustomExpiration() {

  // Override form cache expiration so that the cached form expired yesterday.
  new Settings([
    'form_cache_expiration' => -1 * (24 * 60 * 60),
    'hash_salt' => $this
      ->randomMachineName(),
  ]);
  \Drupal::formBuilder()
    ->setCache($this->formBuildId, $this->form, $this->formState);
  $cached_form_state = new FormState();
  $this
    ->assertNull(\Drupal::formBuilder()
    ->getCache($this->formBuildId, $cached_form_state), 'Expired form not returned from cache');
}