function FormCacheTest::testCacheCustomExpiration

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php \Drupal\KernelTests\Core\Form\FormCacheTest::testCacheCustomExpiration()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php \Drupal\KernelTests\Core\Form\FormCacheTest::testCacheCustomExpiration()
  3. 10 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 114

Class

FormCacheTest
Tests FormBuilder caching.

Namespace

Drupal\KernelTests\Core\Form

Code

public function testCacheCustomExpiration() : void {
    // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.