1 form.test FormsRebuildTestCase::testRebuildPreservesValues()

Tests preservation of values.


core/modules/simpletest/tests/form.test, line 1722
Unit tests for the Backdrop Form API.


Tests form rebuilding.


function testRebuildPreservesValues() {
  $edit = array(
    'checkbox_1_default_off' => TRUE,
    'checkbox_1_default_on' => FALSE,
    'text_1' => 'foo',
  $this->backdropPost('form-test/form-rebuild-preserve-values', $edit, 'Add more');

  // Verify that initial elements retained their submitted values.
  $this->assertFieldChecked('edit-checkbox-1-default-off', 'A submitted checked checkbox retained its checked state during a rebuild.');
  $this->assertNoFieldChecked('edit-checkbox-1-default-on', 'A submitted unchecked checkbox retained its unchecked state during a rebuild.');
  $this->assertFieldById('edit-text-1', 'foo', 'A textfield retained its submitted value during a rebuild.');

  // Verify that newly added elements were initialized with their default values.
  $this->assertFieldChecked('edit-checkbox-2-default-on', 'A newly added checkbox was initialized with a default checked state.');
  $this->assertNoFieldChecked('edit-checkbox-2-default-off', 'A newly added checkbox was initialized with a default unchecked state.');
  $this->assertFieldById('edit-text-2', 'DEFAULT 2', 'A newly added textfield was initialized with its default value.');