function FormStoragePageCacheTest::testRebuildFormStorageOnCachedPage

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/FormStoragePageCacheTest.php \Drupal\Tests\system\Functional\Form\FormStoragePageCacheTest::testRebuildFormStorageOnCachedPage()
  2. 8.9.x core/modules/system/tests/src/Functional/Form/FormStoragePageCacheTest.php \Drupal\Tests\system\Functional\Form\FormStoragePageCacheTest::testRebuildFormStorageOnCachedPage()
  3. 11.x core/modules/system/tests/src/Functional/Form/FormStoragePageCacheTest.php \Drupal\Tests\system\Functional\Form\FormStoragePageCacheTest::testRebuildFormStorageOnCachedPage()

Build-id is regenerated when rebuilding cached form.

File

core/modules/system/tests/src/Functional/Form/FormStoragePageCacheTest.php, line 95

Class

FormStoragePageCacheTest
Tests form storage from cached pages.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRebuildFormStorageOnCachedPage() : void {
    $this->drupalGet('form-test/form-storage-page-cache');
    $this->assertSession()
        ->responseHeaderEquals('X-Drupal-Cache', 'MISS');
    $this->assertSession()
        ->pageTextContains('No old build id');
    $build_id_initial = $this->getFormBuildId();
    // Trigger rebuild, should regenerate build id. When a submit handler
    // triggers a rebuild, the form is built twice in the same POST request,
    // and during the second build, there is an old build ID, but because the
    // form is not cached during the initial GET request, it is different from
    // that initial build ID.
    $edit = [
        'title' => 'something',
    ];
    $this->submitForm($edit, 'Rebuild');
    $this->assertSession()
        ->pageTextNotContains('No old build id');
    $this->assertSession()
        ->pageTextNotContains($build_id_initial);
    $build_id_first_rebuild = $this->getFormBuildId();
    $this->assertNotEquals($build_id_initial, $build_id_first_rebuild, 'Build id changes on first rebuild.');
    // Trigger subsequent rebuild, should regenerate the build id again.
    $edit = [
        'title' => 'something',
    ];
    $this->submitForm($edit, 'Rebuild');
    $this->assertSession()
        ->pageTextContains($build_id_first_rebuild);
    $build_id_second_rebuild = $this->getFormBuildId();
    $this->assertNotEquals($build_id_first_rebuild, $build_id_second_rebuild, 'Build id changes on second rebuild.');
}

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