diff --git a/core/modules/page_cache/src/Tests/PageCacheTest.php b/core/modules/page_cache/src/Tests/PageCacheTest.php index a00416c..b21a4b1 100644 --- a/core/modules/page_cache/src/Tests/PageCacheTest.php +++ b/core/modules/page_cache/src/Tests/PageCacheTest.php @@ -254,34 +254,19 @@ public function testPageCacheWithoutVaryCookie() { * Test the setting of forms to be immutable. */ public function testFormImmutability() { - // Install the module that provide sthe test form. + // Install the module that provides the test form. $this->container->get('module_installer') ->install(['page_cache_form_test']); - $verify_immutable_flag = function ($request_method, $immutable_flag_exists) { - // Mock a request. - $request = Request::create($this->buildUrl('')); - $request->setMethod($request_method); - $this->container->get('request_stack')->push($request); + $this->drupalGet('page_cache_form_test_immutability'); - // Build a form while the page_cache module is enabled, , the - $form_state = new FormState(); - \Drupal::formBuilder() - ->buildForm('\Drupal\page_cache_form_test\Form\TestForm', $form_state); + $this->assertText("Immutable: TRUE", "Form is immutable."); - $this->assertIdentical($immutable_flag_exists, array_key_exists('immutable', $form_state->getBuildInfo())); - if ($immutable_flag_exists) { - $this->assertIdentical($form_state->getBuildInfo()['immutable'], TRUE); - } - }; + // Uninstall the page_cache module, verify the flag is not set. + $this->container->get('module_installer')->uninstall(['page_cache']); - // Verify the immutable flag is being set on cacheable requests. - $verify_immutable_flag('POST', FALSE); - $verify_immutable_flag('GET', TRUE); + $this->drupalGet('page_cache_form_test_immutability'); - // Uninstall the page_cache module, verify the flag is never set. - $this->container->get('module_installer')->uninstall(['page_cache']); - $verify_immutable_flag('POST', FALSE); - $verify_immutable_flag('GET', FALSE); + $this->assertText("Immutable: FALSE", "Form is not immutable,"); } } diff --git a/core/modules/page_cache/tests/modules/page_cache_form_test.module b/core/modules/page_cache/tests/modules/page_cache_form_test.module new file mode 100644 index 0000000..5cd2b15 --- /dev/null +++ b/core/modules/page_cache/tests/modules/page_cache_form_test.module @@ -0,0 +1,20 @@ +getBuildInfo()['immutable']) && $form_state->getBuildInfo()['immutable']) { + $form['#suffix'] = 'Immutable: TRUE'; + } + else { + $form['#suffix'] = 'Immutable: FALSE'; + } +} \ No newline at end of file diff --git a/core/modules/page_cache/tests/modules/page_cache_form_test.routing.yml b/core/modules/page_cache/tests/modules/page_cache_form_test.routing.yml new file mode 100644 index 0000000..d28f166 --- /dev/null +++ b/core/modules/page_cache/tests/modules/page_cache_form_test.routing.yml @@ -0,0 +1,6 @@ +page_cache_form_test.test_immutability: + path: '/page_cache_form_test_immutability' + defaults: + _form: '\Drupal\page_cache_form_test\Form\TestForm' + requirements: + _access: 'TRUE' \ No newline at end of file