You are here

public function StorageTest::testFormCached in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/StorageTest.php \Drupal\Tests\system\Functional\Form\StorageTest::testFormCached()
  2. 10 core/modules/system/tests/src/Functional/Form/StorageTest.php \Drupal\Tests\system\Functional\Form\StorageTest::testFormCached()

Tests using the form after calling $form_state->setCached().

File

core/modules/system/tests/src/Functional/Form/StorageTest.php, line 75

Class

StorageTest
Tests a multistep form using form storage and makes sure validation and caching works right.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testFormCached() {
  $this
    ->drupalGet('form_test/form-storage', [
    'query' => [
      'cache' => 1,
    ],
  ]);
  $this
    ->assertSession()
    ->pageTextContains('Form constructions: 1');
  $edit = [
    'title' => 'new',
    'value' => 'value_is_set',
  ];

  // Use form rebuilding triggered by a submit button.
  $this
    ->drupalPostForm(NULL, $edit, 'Continue submit');

  // The first one is for the building of the form.
  $this
    ->assertSession()
    ->pageTextContains('Form constructions: 2');

  // The second one is for the rebuilding of the form.
  $this
    ->assertSession()
    ->pageTextContains('Form constructions: 3');

  // Reset the form to the values of the storage, using a form rebuild
  // triggered by button of type button.
  $this
    ->drupalPostForm(NULL, [
    'title' => 'changed',
  ], 'Reset');
  $this
    ->assertSession()
    ->fieldValueEquals('title', 'new');
  $this
    ->assertSession()
    ->pageTextContains('Form constructions: 4');
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('Form constructions: 4');
  $this
    ->assertSession()
    ->pageTextContains('Title: new', 'The form storage has stored the values.');
}