1 form_example.test public FormExampleTestCase::testWizard()

Test Wizard tutorial.

@TODO improve this using backdrop_form_submit


modules/examples/form_example/form_example.test, line 159
Test file for form_example module.


Default test case for the form_example module.


public function testWizard() {
  // Check if the wizard is there.
  $this->assertText(t('Extensible wizard'));

  $first_name = $this->randomName(8);
  $last_name = $this->randomName(8);
  $city = $this->randomName(8);
  $aunts_name = $this->randomName(8);

  // Submit the first step of the wizard.
  $options = array(
    'first_name' => $first_name,
    'last_name' => $last_name,
  $this->backdropPost('examples/form_example/wizard', $options, t('Next'));

  // A label city is created, and two buttons appear, Preivous and Next.
  $this->assertText(t('Hint: Do not enter "San Francisco", and do not leave this out.'));

  // Go back to the beginning and verify that the value is there.
  $this->backdropPost(NULL, array(), t('Previous'));
  $this->assertFieldByName('first_name', $first_name);
  $this->assertFieldByName('last_name', $last_name);

  // Go next. We should keep our values.
  $this->backdropPost(NULL, array(), t('Next'));
  $this->assertText(t('Hint: Do not enter "San Francisco", and do not leave this out.'));

  // Try "San Francisco".
  $this->backdropPost(NULL, array('city' => 'San Francisco'), t('Next'));
  $this->assertText(t('You were warned not to enter "San Francisco"'));

  // Try the real city.
  $this->backdropPost(NULL, array('city' => $city), t('Next'));

  // Enter the Aunt's name, but then the previous button.
  $this->backdropPost(NULL, array('aunts_name' => $aunts_name), t('Previous'));
  $this->assertFieldByName('city', $city);

  // Now go forward and then press finish; check for correct values.
  $this->backdropPost(NULL, array(), t('Next'));
  $this->backdropPost(NULL, array('aunts_name' => $aunts_name), t('Finish'));

  $this->assertRaw(t('[first_name] => @first_name', array('@first_name' => $first_name)));
  $this->assertRaw(t('[last_name] => @last_name', array('@last_name' => $last_name)));
  $this->assertRaw(t('[city] => @city', array('@city' => $city)));
  $this->assertRaw(t('[aunts_name] => @aunts_name', array('@aunts_name' => $aunts_name)));