function StorageTest::testForm

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/StorageTest.php \Drupal\Tests\system\Functional\Form\StorageTest::testForm()
  2. 10 core/modules/system/tests/src/Functional/Form/StorageTest.php \Drupal\Tests\system\Functional\Form\StorageTest::testForm()
  3. 11.x 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->drupalPostForm(NULL, $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->drupalPostForm(NULL, [
        'title' => 'changed',
    ], 'Reset');
    $assert_session->fieldValueEquals('title', 'new');
    // After rebuilding, the form has been cached.
    $assert_session->pageTextContains('Form constructions: 4');
    $this->drupalPostForm(NULL, $edit, 'Save');
    $assert_session->pageTextContains('Form constructions: 4');
    $assert_session->pageTextContains('Title: new', 'The form storage has stored the values.');
}

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