1 form_example.test public FormExampleTestCase::testElementExample()

Test the element_example form for correct behavior.

File

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

Class

FormExampleTestCase
Default test case for the form_example module.

Code

public function testElementExample() {
  // Make one basic POST with a set of values and check for correct responses.
  $edit = array(
    'a_form_example_textfield' => $this->randomName(),
    'a_form_example_checkbox' => TRUE,
    'a_form_example_element_discrete[areacode]' => sprintf('%03d', rand(0, 999)),
    'a_form_example_element_discrete[prefix]' => sprintf('%03d', rand(0, 999)),
    'a_form_example_element_discrete[extension]' => sprintf('%04d', rand(0, 9999)),
    'a_form_example_element_combined[areacode]' => sprintf('%03d', rand(0, 999)),
    'a_form_example_element_combined[prefix]' => sprintf('%03d', rand(0, 999)),
    'a_form_example_element_combined[extension]' => sprintf('%04d', rand(0, 9999)),
  );
  $this->backdropPost('examples/form_example/element_example', $edit, t('Submit'));
  $this->assertText(t('a_form_example_textfield has value @value', array('@value' => $edit['a_form_example_textfield'])));
  $this->assertText(t('a_form_example_checkbox has value 1'));
  $this->assertPattern(t('/areacode.*!areacode/', array('!areacode' => $edit['a_form_example_element_discrete[areacode]'])));
  $this->assertPattern(t('/prefix.*!prefix/', array('!prefix' => $edit['a_form_example_element_discrete[prefix]'])));
  $this->assertPattern(t('/extension.*!extension/', array('!extension' => $edit['a_form_example_element_discrete[extension]'])));

  $this->assertText(t('a_form_example_element_combined has value @value', array('@value' => $edit['a_form_example_element_combined[areacode]'] . $edit['a_form_example_element_combined[prefix]'] . $edit['a_form_example_element_combined[extension]'])));

  // Now flip the checkbox and check for correct behavior.
  $edit['a_form_example_checkbox'] = FALSE;
  $this->backdropPost('examples/form_example/element_example', $edit, t('Submit'));
  $this->assertText(t('a_form_example_checkbox has value 0'));
}