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