function RebuildTest::testRebuildPreservesValues

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/RebuildTest.php \Drupal\Tests\system\Functional\Form\RebuildTest::testRebuildPreservesValues()
  2. 10 core/modules/system/tests/src/Functional/Form/RebuildTest.php \Drupal\Tests\system\Functional\Form\RebuildTest::testRebuildPreservesValues()
  3. 11.x core/modules/system/tests/src/Functional/Form/RebuildTest.php \Drupal\Tests\system\Functional\Form\RebuildTest::testRebuildPreservesValues()

Tests preservation of values.

File

core/modules/system/tests/src/Functional/Form/RebuildTest.php, line 45

Class

RebuildTest
Tests functionality of <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormBuilderInterface.php/function/FormBuilderInterface%3A%3ArebuildForm/8.9.x" title="Constructs a new $form from the information in $form_state." class="local">\Drupal\Core\Form\FormBuilderInterface::rebuildForm</a>().

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRebuildPreservesValues() {
    $edit = [
        'checkbox_1_default_off' => TRUE,
        'checkbox_1_default_on' => FALSE,
        'text_1' => 'foo',
    ];
    $this->drupalPostForm('form-test/form-rebuild-preserve-values', $edit, 'Add more');
    $assert_session = $this->assertSession();
    // Verify that initial elements retained their submitted values.
    $assert_session->checkboxChecked('edit-checkbox-1-default-off');
    $assert_session->checkboxNotChecked('edit-checkbox-1-default-on');
    $assert_session->fieldValueEquals('edit-text-1', 'foo');
    // Verify that newly added elements were initialized with their default values.
    $assert_session->checkboxChecked('edit-checkbox-2-default-on');
    $assert_session->checkboxNotChecked('edit-checkbox-2-default-off');
    $assert_session->fieldValueEquals('edit-text-2', 'DEFAULT 2');
}

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