Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Form / FormCacheTest.php
index 6425a3099d5c58db401320b595d094ca58020b30..f6fb4f8713a42a26d00c7ef522a36f11378ed6ae 100644 (file)
@@ -5,6 +5,7 @@ namespace Drupal\KernelTests\Core\Form;
 use Drupal\Core\Form\FormState;
 use Drupal\Core\Session\AnonymousUserSession;
 use Drupal\Core\Session\UserSession;
+use Drupal\Core\Site\Settings;
 use Drupal\KernelTests\KernelTestBase;
 
 /**
@@ -101,4 +102,16 @@ class FormCacheTest extends KernelTestBase {
     $account_switcher->switchBack();
   }
 
+  /**
+   * Tests the form cache with an overridden cache expiration.
+   */
+  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->assertFalse(\Drupal::formBuilder()->getCache($this->formBuildId, $cached_form_state), 'Expired form not returned from cache');
+  }
+
 }