You are here

public function PageCacheTest::testFormImmutability in Drupal 8

Same name and namespace in other branches
  1. 9 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()

Test the setting of forms to be immutable.

File

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

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',
  ]);
  \Drupal::service('router.builder')
    ->rebuild();
  $this
    ->drupalGet('page_cache_form_test_immutability');
  $this
    ->assertText("Immutable: TRUE", "Form is immutable.");

  // 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
    ->assertText("Immutable: FALSE", "Form is not immutable,");
}