public function FormExampleTestCase::testElementExample in Examples for Developers 7
Same name and namespace in other branches
- 6 form_example/form_example.test \FormExampleTestCase::testElementExample()
Test the element_example form for correct behavior.
File
- form_example/
form_example.test, line 262 - 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
->drupalPost('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
->drupalPost('examples/form_example/element_example', $edit, t('Submit'));
$this
->assertText(t('a_form_example_checkbox has value 0'));
}