public function FormStoragePageCacheTest::testValidateFormStorageOnCachedPage in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/src/Tests/Form/FormStoragePageCacheTest.php \Drupal\system\Tests\Form\FormStoragePageCacheTest::testValidateFormStorageOnCachedPage()
Build-id is regenerated when validating cached form.
File
- core/
modules/ system/ src/ Tests/ Form/ FormStoragePageCacheTest.php, line 47 - Contains \Drupal\system\Tests\Form\FormStoragePageCacheTest.
Class
- FormStoragePageCacheTest
- Tests form storage from cached pages.
Namespace
Drupal\system\Tests\FormCode
public function testValidateFormStorageOnCachedPage() {
$this
->drupalGet('form-test/form-storage-page-cache');
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
$this
->assertText('No old build id', 'No old build id on the page');
$build_id_initial = $this
->getFormBuildId();
// Trigger validation error by submitting an empty title.
$edit = [
'title' => '',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText('No old build id', 'No old build id on the page');
$build_id_first_validation = $this
->getFormBuildId();
$this
->assertNotEqual($build_id_initial, $build_id_first_validation, 'Build id changes when form validation fails');
// Trigger validation error by again submitting an empty title.
$edit = [
'title' => '',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText('No old build id', 'No old build id on the page');
$build_id_second_validation = $this
->getFormBuildId();
$this
->assertEqual($build_id_first_validation, $build_id_second_validation, 'Build id remains the same when form validation fails subsequently');
// Repeat the test sequence but this time with a page loaded from the cache.
$this
->drupalGet('form-test/form-storage-page-cache');
$this
->assertEqual($this
->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this
->assertText('No old build id', 'No old build id on the page');
$build_id_from_cache_initial = $this
->getFormBuildId();
$this
->assertEqual($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request');
// Trigger validation error by submitting an empty title.
$edit = [
'title' => '',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText('No old build id', 'No old build id on the page');
$build_id_from_cache_first_validation = $this
->getFormBuildId();
$this
->assertNotEqual($build_id_initial, $build_id_from_cache_first_validation, 'Build id changes when form validation fails');
$this
->assertNotEqual($build_id_first_validation, $build_id_from_cache_first_validation, 'Build id from first user is not reused');
// Trigger validation error by again submitting an empty title.
$edit = [
'title' => '',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertText('No old build id', 'No old build id on the page');
$build_id_from_cache_second_validation = $this
->getFormBuildId();
$this
->assertEqual($build_id_from_cache_first_validation, $build_id_from_cache_second_validation, 'Build id remains the same when form validation fails subsequently');
}