1 ajax_example.test | public AjaxExampleTestCase::testDynamicSectionsNoJs() |
Check the non-JavaScript version of the "Dynamic Sections" example.
File
- modules/
examples/ ajax_example/ tests/ ajax_example.test, line 24 - Test ajax example module.
Class
- AjaxExampleTestCase
- Functional tests for AJAX Example module.
Code
public function testDynamicSectionsNoJs() {
// The path to the example form.
$path = 'examples/ajax_example/dynamic_sections_no_js';
// Confirmation text for right and wrong answers.
$wrong = t('Wrong answer. Try again. (Hint: The right answer is "George Washington".)');
$right = t('You got the right answer: George Washington');
// For each question style, choose some parameters.
$params = array(
t('Multiple Choice') => array(
'value' => t('Abraham Lincoln'),
'answer' => t('Abraham Lincoln'),
'response' => $wrong,
),
t('True/False') => array(
'value' => t('George Washington'),
'answer' => t('George Washington'),
'response' => $right,
),
t('Fill-in-the-blanks') => array(
'value' => NULL,
'answer' => t('George Washington'),
'response' => $right,
),
);
foreach ($params as $style => $q_and_a) {
// Submit the initial form.
$edit = array('question_type_select' => $style);
$this->backdropPost($path, $edit, t('Choose'));
$this->assertResponse(200, format_string('Question style "@style" selected.', array('@style' => $style)));
// For convenience, make variables out of the entries in $q_and_a.
extract($q_and_a);
// Check for the expected input field.
$this->assertFieldByName('question', $value);
// Now, submit the dynamically generated form.
$edit = array('question' => $answer);
$this->backdropPost(NULL, $edit, t('Submit your answer'));
$this->assertRaw($response, 'Dynamic form has been submitted.');
}
}