ajax_example.test 2.2 KB

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