You are here

function StorageTest::testForm in Zircon Profile 8

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

Tests using the form in a usual way.

File

core/modules/system/src/Tests/Form/StorageTest.php, line 42
Contains \Drupal\system\Tests\Form\StorageTest.

Class

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

Namespace

Drupal\system\Tests\Form

Code

function testForm() {
  $this
    ->drupalGet('form_test/form-storage');
  $this
    ->assertText('Form constructions: 1');
  $edit = array(
    'title' => 'new',
    'value' => 'value_is_set',
  );

  // Use form rebuilding triggered by a submit button.
  $this
    ->drupalPostForm(NULL, $edit, 'Continue submit');
  $this
    ->assertText('Form constructions: 2');
  $this
    ->assertText('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, array(
    'title' => 'changed',
  ), 'Reset');
  $this
    ->assertFieldByName('title', 'new', 'Values have been reset.');

  // After rebuilding, the form has been cached.
  $this
    ->assertText('Form constructions: 4');
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertText('Form constructions: 4');
  $this
    ->assertText('Title: new', 'The form storage has stored the values.');
}