You are here

public function StorageTest::testForm in Drupal 10

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

Tests using the form in a usual way.

File

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

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 testForm() {
  $this
    ->drupalGet('form_test/form-storage');
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->pageTextContains('Form constructions: 1');
  $edit = [
    'title' => 'new',
    'value' => 'value_is_set',
  ];

  // Use form rebuilding triggered by a submit button.
  $this
    ->submitForm($edit, 'Continue submit');
  $assert_session
    ->pageTextContains('Form constructions: 2');
  $assert_session
    ->pageTextContains('Form constructions: 3');

  // Reset the form to the values of the storage, using a form rebuild
  // triggered by button of type button.
  $this
    ->submitForm([
    'title' => 'changed',
  ], 'Reset');
  $assert_session
    ->fieldValueEquals('title', 'new');

  // After rebuilding, the form has been cached.
  $assert_session
    ->pageTextContains('Form constructions: 4');
  $this
    ->submitForm($edit, 'Save');
  $assert_session
    ->pageTextContains('Form constructions: 4');

  // Verify that the form storage has stored the values.
  $assert_session
    ->pageTextContains('Title: new');
}