ajax_example.test

  1. examples
    1. 7 ajax_example/ajax_example.test
    2. 8 ajax_example/ajax_example.test

Test ajax example module.

Classes

NameDescription
AjaxExampleTestCase@file Test ajax example module.

File

ajax_example/ajax_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test ajax example module.
  5. */
  6. class AjaxExampleTestCase extends DrupalWebTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Ajax example',
  10. 'description' => 'Checks behavior of the Ajax Example',
  11. 'group' => 'Examples',
  12. );
  13. }
  14. /**
  15. * Enable module.
  16. */
  17. function setUp() {
  18. parent::setUp('ajax_example');
  19. }
  20. /**
  21. * Check the non-JS version of the "Dynamic Sections" example.
  22. */
  23. function testDynamicSectionsNoJs() {
  24. // The path to the example form.
  25. $path = 'examples/ajax_example/dynamic_sections_no_js';
  26. // Confirmation text for right and wrong answers.
  27. $wrong = 'Wrong answer. Try again. (Hint: The right answer is "George Washington".)';
  28. $right = 'You got the right answer: George Washington';
  29. // For each question style, choose some parameters.
  30. $params = array(
  31. 'Multiple Choice' => array(
  32. 'value' => 'Abraham Lincoln',
  33. 'answer' => 'Abraham Lincoln',
  34. 'response' => $wrong,
  35. ),
  36. 'True/False' => array(
  37. 'value' => 'George Washington',
  38. 'answer' => 'George Washington',
  39. 'response' => $right,
  40. ),
  41. 'Fill-in-the-blanks' => array(
  42. 'value' => NULL,
  43. 'answer' => 'George Washington',
  44. 'response' => $right,
  45. ),
  46. );
  47. foreach ($params as $style => $QandA) {
  48. // Submit the initial form.
  49. $edit = array('question_type_select' => t($style));
  50. $this->drupalPost($path, $edit, t('Choose'));
  51. $this->assertResponse(200, t('Question style "@style" selected.', array('@style' => t($style))));
  52. // For convenience, make variables out of the entries in $QandA.
  53. extract($QandA);
  54. // Check for the expected input field.
  55. $this->assertFieldByName('question', t($value));
  56. // Now, submit the dynamically generated form.
  57. $edit = array('question' => t($answer));
  58. $this->drupalPost(NULL, $edit, t('Submit your answer'));
  59. $this->assertRaw(t($response), t('Dynamic form has been submitted.'));
  60. }
  61. }
  62. }
Login or register to post comments