function PageCacheTest::testFormImmutability

Same name and namespace in other branches
  1. 8.9.x core/modules/page_cache/tests/src/Functional/PageCacheTest.php \Drupal\Tests\page_cache\Functional\PageCacheTest::testFormImmutability()
  2. 10 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 432

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");
}

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