/question/type/gapselect/simpletest/testwalkthrough.php

https://github.com/DeanLennard/Moodle-Question-Engine-2 · PHP · 149 lines · 89 code · 19 blank · 41 comment · 1 complexity · bfbd9259fc6faa56048a680123577bf8 MD5 · raw file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file contains tests that walks a question through the interactive
  18. * behaviour.
  19. *
  20. * @package qtype
  21. * @subpackage gapselect
  22. * @copyright 2011 The Open University
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. defined('MOODLE_INTERNAL') || die();
  26. require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
  27. require_once($CFG->dirroot . '/question/type/gapselect/simpletest/helper.php');
  28. /**
  29. * Unit tests for the gap-select question type.
  30. *
  31. * @copyright 2011 The Open University
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base {
  35. public function test_interactive_behaviour() {
  36. // Create a gapselect question.
  37. $q = qtype_gapselect_test_helper::make_a_gapselect_question();
  38. $q->hints = array(
  39. new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, false, false),
  40. new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, true),
  41. );
  42. $q->shufflechoices = false;
  43. $this->start_attempt_at_question($q, 'interactive', 3);
  44. // Check the initial state.
  45. $this->check_current_state(question_state::$todo);
  46. $this->check_current_mark(null);
  47. $this->check_current_output(
  48. $this->get_contains_select_expectation('p1',
  49. array('' => ' ', '1' => 'quick', '2' => 'slow'), null, true),
  50. $this->get_contains_select_expectation('p2',
  51. array('' => ' ', '1' => 'fox', '2' => 'dog'), null, true),
  52. $this->get_contains_select_expectation('p3',
  53. array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), null, true),
  54. $this->get_contains_submit_button_expectation(true),
  55. $this->get_does_not_contain_feedback_expectation(),
  56. $this->get_tries_remaining_expectation(3),
  57. $this->get_no_hint_visible_expectation());
  58. // Save the wrong answer.
  59. $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2'));
  60. // Verify.
  61. $this->check_current_state(question_state::$todo);
  62. $this->check_current_mark(null);
  63. $this->check_current_output(
  64. $this->get_contains_select_expectation('p1',
  65. array('' => ' ', '1' => 'quick', '2' => 'slow'), 2, true),
  66. $this->get_contains_select_expectation('p2',
  67. array('' => ' ', '1' => 'fox', '2' => 'dog'), 2, true),
  68. $this->get_contains_select_expectation('p3',
  69. array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 2, true),
  70. $this->get_contains_submit_button_expectation(true),
  71. $this->get_does_not_contain_correctness_expectation(),
  72. $this->get_does_not_contain_feedback_expectation(),
  73. $this->get_tries_remaining_expectation(3),
  74. $this->get_no_hint_visible_expectation());
  75. // Submit the wrong answer.
  76. $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));
  77. // Verify.
  78. $this->check_current_state(question_state::$todo);
  79. $this->check_current_mark(null);
  80. $this->check_current_output(
  81. $this->get_contains_select_expectation('p1',
  82. array('' => ' ', '1' => 'quick', '2' => 'slow'), 2, false),
  83. $this->get_contains_select_expectation('p2',
  84. array('' => ' ', '1' => 'fox', '2' => 'dog'), 2, false),
  85. $this->get_contains_select_expectation('p3',
  86. array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 2, false),
  87. $this->get_contains_submit_button_expectation(false),
  88. $this->get_contains_try_again_button_expectation(true),
  89. $this->get_does_not_contain_correctness_expectation(),
  90. new PatternExpectation('/' . preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
  91. $this->get_contains_hint_expectation('This is the first hint'));
  92. // Do try again.
  93. $this->process_submission(array('-tryagain' => 1));
  94. // Verify.
  95. $this->check_current_state(question_state::$todo);
  96. $this->check_current_mark(null);
  97. $this->check_current_output(
  98. $this->get_contains_select_expectation('p1',
  99. array('' => ' ', '1' => 'quick', '2' => 'slow'), 2, true),
  100. $this->get_contains_select_expectation('p2',
  101. array('' => ' ', '1' => 'fox', '2' => 'dog'), 2, true),
  102. $this->get_contains_select_expectation('p3',
  103. array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 2, true),
  104. $this->get_contains_submit_button_expectation(true),
  105. $this->get_does_not_contain_correctness_expectation(),
  106. $this->get_does_not_contain_feedback_expectation(),
  107. $this->get_tries_remaining_expectation(2),
  108. $this->get_no_hint_visible_expectation());
  109. // Submit the right answer.
  110. $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));
  111. // Verify.
  112. $this->check_current_state(question_state::$gradedright);
  113. $this->check_current_mark(2);
  114. $this->check_current_output(
  115. $this->get_contains_select_expectation('p1',
  116. array('' => ' ', '1' => 'quick', '2' => 'slow'), 1, false),
  117. $this->get_contains_select_expectation('p2',
  118. array('' => ' ', '1' => 'fox', '2' => 'dog'), 1, false),
  119. $this->get_contains_select_expectation('p3',
  120. array('' => ' ', '1' => 'lazy', '2' => 'assiduous'), 1, false),
  121. $this->get_contains_submit_button_expectation(false),
  122. $this->get_contains_correct_expectation(),
  123. $this->get_no_hint_visible_expectation());
  124. // Check regrading does not mess anything up.
  125. $this->quba->regrade_all_questions();
  126. // Verify.
  127. $this->check_current_state(question_state::$gradedright);
  128. $this->check_current_mark(2);
  129. }
  130. }