Test ajax example module.
Classes
| Name | Description |
|---|---|
| AjaxExampleTestCase | @file Test ajax example module. |
File
ajax_example/ajax_example.testView source
- <?php
- /**
- * @file
- * Test ajax example module.
- */
- class AjaxExampleTestCase extends DrupalWebTestCase {
-
- public static function getInfo() {
- return array(
- 'name' => 'Ajax example',
- 'description' => 'Checks behavior of the Ajax Example',
- 'group' => 'Examples',
- );
- }
-
- /**
- * Enable module.
- */
- function setUp() {
- parent::setUp('ajax_example');
- }
-
- /**
- * Check the non-JS version of the "Dynamic Sections" example.
- */
- function testDynamicSectionsNoJs() {
- // The path to the example form.
- $path = 'examples/ajax_example/dynamic_sections_no_js';
- // Confirmation text for right and wrong answers.
- $wrong = 'Wrong answer. Try again. (Hint: The right answer is "George Washington".)';
- $right = 'You got the right answer: George Washington';
- // For each question style, choose some parameters.
- $params = array(
- 'Multiple Choice' => array(
- 'value' => 'Abraham Lincoln',
- 'answer' => 'Abraham Lincoln',
- 'response' => $wrong,
- ),
- 'True/False' => array(
- 'value' => 'George Washington',
- 'answer' => 'George Washington',
- 'response' => $right,
- ),
- 'Fill-in-the-blanks' => array(
- 'value' => NULL,
- 'answer' => 'George Washington',
- 'response' => $right,
- ),
- );
- foreach ($params as $style => $QandA) {
- // Submit the initial form.
- $edit = array('question_type_select' => t($style));
- $this->drupalPost($path, $edit, t('Choose'));
- $this->assertResponse(200, t('Question style "@style" selected.', array('@style' => t($style))));
- // For convenience, make variables out of the entries in $QandA.
- extract($QandA);
- // Check for the expected input field.
- $this->assertFieldByName('question', t($value));
- // Now, submit the dynamically generated form.
- $edit = array('question' => t($answer));
- $this->drupalPost(NULL, $edit, t('Submit your answer'));
- $this->assertRaw(t($response), t('Dynamic form has been submitted.'));
- }
- }
-
- }
-