You are here

public function PageCacheTest::testFormImmutability in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::testFormImmutability()

Tests the setting of forms to be immutable.

File

core/modules/page_cache/tests/src/Functional/PageCacheTest.php, line 473

Class

PageCacheTest
Enables the page cache and tests it with various HTTP requests.

Namespace

Drupal\Tests\page_cache\Functional

Code

public function testFormImmutability() {

  // Install the module that provides the test form.
  $this->container
    ->get('module_installer')
    ->install([
    'page_cache_form_test',
  ]);

  // Uninstall the page_cache module to verify that form is immutable
  // regardless of the internal page cache module.
  $this->container
    ->get('module_installer')
    ->uninstall([
    'page_cache',
  ]);
  $this
    ->drupalGet('page_cache_form_test_immutability');
  $this
    ->assertSession()
    ->pageTextContains("Immutable: TRUE");

  // The immutable flag is set unconditionally by system_form_alter(), set
  // a flag to tell page_cache_form_test_module_implements_alter() to disable
  // that implementation.
  \Drupal::state()
    ->set('page_cache_bypass_form_immutability', TRUE);
  \Drupal::moduleHandler()
    ->resetImplementations();
  Cache::invalidateTags([
    'rendered',
  ]);
  $this
    ->drupalGet('page_cache_form_test_immutability');
  $this
    ->assertSession()
    ->pageTextContains("Immutable: FALSE");
}