You are here

public function PageCacheTest::testFormImmutability in Zircon Profile 8

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

Test the setting of forms to be immutable.

File

core/modules/page_cache/src/Tests/PageCacheTest.php, line 415
Contains \Drupal\page_cache\Tests\PageCacheTest.

Class

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

Namespace

Drupal\page_cache\Tests

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