Commit | Line | Data |
---|---|---|
0d24b17a | 1 | <?php |
0d24b17a TH |
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 | ||
0d24b17a TH |
17 | /** |
18 | * This file contains tests that walks a question through the interactive | |
19 | * behaviour. | |
20 | * | |
9df0480d | 21 | * @package qtype |
0d24b17a | 22 | * @subpackage gapselect |
b3adccfb | 23 | * @copyright 2012 The Open University |
9df0480d | 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
0d24b17a TH |
25 | */ |
26 | ||
27 | ||
b28ad86a | 28 | defined('MOODLE_INTERNAL') || die(); |
b3adccfb | 29 | global $CFG; |
b28ad86a | 30 | |
b3adccfb JP |
31 | require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); |
32 | require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php'); | |
0d24b17a TH |
33 | |
34 | ||
9df0480d TH |
35 | /** |
36 | * Unit tests for the gap-select question type. | |
37 | * | |
b3adccfb | 38 | * @copyright 2012 The Open University |
9df0480d | 39 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
b3adccfb | 40 | * @group qtype_gapselect |
9df0480d | 41 | */ |
0d24b17a | 42 | class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base { |
43df6cac | 43 | public function test_interactive_behaviour() { |
0d24b17a | 44 | |
43df6cac TH |
45 | // Create a gapselect question. |
46 | $q = qtype_gapselect_test_helper::make_a_gapselect_question(); | |
47 | $q->hints = array( | |
7540fcdc TH |
48 | new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, false, false), |
49 | new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, true), | |
43df6cac | 50 | ); |
7540fcdc | 51 | $q->shufflechoices = false; |
43df6cac | 52 | $this->start_attempt_at_question($q, 'interactive', 3); |
0d24b17a | 53 | |
43df6cac TH |
54 | // Check the initial state. |
55 | $this->check_current_state(question_state::$todo); | |
56 | $this->check_current_mark(null); | |
57 | $this->check_current_output( | |
58 | $this->get_contains_select_expectation('p1', | |
5283ee02 | 59 | array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), null, true), |
43df6cac | 60 | $this->get_contains_select_expectation('p2', |
5283ee02 | 61 | array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), null, true), |
43df6cac | 62 | $this->get_contains_select_expectation('p3', |
5283ee02 | 63 | array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), null, true), |
43df6cac TH |
64 | $this->get_contains_submit_button_expectation(true), |
65 | $this->get_does_not_contain_feedback_expectation(), | |
66 | $this->get_tries_remaining_expectation(3), | |
67 | $this->get_no_hint_visible_expectation()); | |
68 | ||
69 | // Save the wrong answer. | |
70 | $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2')); | |
71 | ||
72 | // Verify. | |
73 | $this->check_current_state(question_state::$todo); | |
74 | $this->check_current_mark(null); | |
75 | $this->check_current_output( | |
76 | $this->get_contains_select_expectation('p1', | |
5283ee02 | 77 | array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true), |
43df6cac | 78 | $this->get_contains_select_expectation('p2', |
5283ee02 | 79 | array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true), |
43df6cac | 80 | $this->get_contains_select_expectation('p3', |
5283ee02 | 81 | array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true), |
43df6cac TH |
82 | $this->get_contains_submit_button_expectation(true), |
83 | $this->get_does_not_contain_correctness_expectation(), | |
84 | $this->get_does_not_contain_feedback_expectation(), | |
85 | $this->get_tries_remaining_expectation(3), | |
86 | $this->get_no_hint_visible_expectation()); | |
87 | ||
88 | // Submit the wrong answer. | |
89 | $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1)); | |
90 | ||
91 | // Verify. | |
92 | $this->check_current_state(question_state::$todo); | |
93 | $this->check_current_mark(null); | |
94 | $this->check_current_output( | |
95 | $this->get_contains_select_expectation('p1', | |
5283ee02 | 96 | array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, false), |
43df6cac | 97 | $this->get_contains_select_expectation('p2', |
5283ee02 | 98 | array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, false), |
43df6cac | 99 | $this->get_contains_select_expectation('p3', |
5283ee02 | 100 | array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, false), |
43df6cac TH |
101 | $this->get_contains_submit_button_expectation(false), |
102 | $this->get_contains_try_again_button_expectation(true), | |
103 | $this->get_does_not_contain_correctness_expectation(), | |
b3adccfb | 104 | new question_pattern_expectation('/' . preg_quote( |
61ba43b0 | 105 | get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'), |
43df6cac TH |
106 | $this->get_contains_hint_expectation('This is the first hint')); |
107 | ||
108 | // Do try again. | |
109 | $this->process_submission(array('-tryagain' => 1)); | |
110 | ||
111 | // Verify. | |
112 | $this->check_current_state(question_state::$todo); | |
113 | $this->check_current_mark(null); | |
114 | $this->check_current_output( | |
115 | $this->get_contains_select_expectation('p1', | |
5283ee02 | 116 | array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true), |
43df6cac | 117 | $this->get_contains_select_expectation('p2', |
5283ee02 | 118 | array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true), |
43df6cac | 119 | $this->get_contains_select_expectation('p3', |
5283ee02 | 120 | array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true), |
43df6cac TH |
121 | $this->get_contains_submit_button_expectation(true), |
122 | $this->get_does_not_contain_correctness_expectation(), | |
123 | $this->get_does_not_contain_feedback_expectation(), | |
124 | $this->get_tries_remaining_expectation(2), | |
125 | $this->get_no_hint_visible_expectation()); | |
126 | ||
127 | // Submit the right answer. | |
128 | $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1)); | |
129 | ||
130 | // Verify. | |
131 | $this->check_current_state(question_state::$gradedright); | |
132 | $this->check_current_mark(2); | |
133 | $this->check_current_output( | |
134 | $this->get_contains_select_expectation('p1', | |
5283ee02 | 135 | array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 1, false), |
43df6cac | 136 | $this->get_contains_select_expectation('p2', |
5283ee02 | 137 | array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 1, false), |
43df6cac | 138 | $this->get_contains_select_expectation('p3', |
5283ee02 | 139 | array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 1, false), |
43df6cac TH |
140 | $this->get_contains_submit_button_expectation(false), |
141 | $this->get_contains_correct_expectation(), | |
142 | $this->get_no_hint_visible_expectation()); | |
143 | ||
144 | // Check regrading does not mess anything up. | |
145 | $this->quba->regrade_all_questions(); | |
146 | ||
147 | // Verify. | |
148 | $this->check_current_state(question_state::$gradedright); | |
149 | $this->check_current_mark(2); | |
150 | } | |
0d24b17a | 151 | } |