Merge branch 'MDL-70148-310' of git://github.com/andrewnicols/moodle into MOODLE_310_...
[moodle.git] / question / type / calculatedmulti / tests / walkthrough_test.php
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/>.
17 /**
18  * This file contains overall tests of calculated multiple-choice questions.
19  *
20  * @package    qtype
21  * @subpackage calculatedmulti
22  * @copyright  2011 The Open University
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
27 defined('MOODLE_INTERNAL') || die();
29 global $CFG;
30 require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
33 /**
34  * Unit tests for the calculated multiple-choice question type.
35  *
36  * @copyright  2011 The Open University
37  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38  */
39 class qtype_calculatedmulti_walkthrough_test extends qbehaviour_walkthrough_test_base {
41     public function test_interactive_single_response() {
43         // Create a gapselect question.
44         $q = test_question_maker::make_question('calculatedmulti', 'singleresponse');
45         $q->shuffleanswers = false;
46         $q->hints = array(
47             new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, true, false),
48             new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, false),
49         );
50         $this->start_attempt_at_question($q, 'interactive', 3, 2);
51         $values = $q->vs->get_values();
52         $this->assertEquals($values, $q->datasetloader->load_values(2));
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_marked_out_of_summary(),
59                 $this->get_contains_submit_button_expectation(true),
60                 $this->get_does_not_contain_feedback_expectation(),
61                 $this->get_does_not_contain_validation_error_expectation(),
62                 $this->get_does_not_contain_try_again_button_expectation(),
63                 $this->get_no_hint_visible_expectation());
65         // Submit a wrong answer.
66         $this->process_submission(array('-submit' => 1, 'answer' => '1'));
68         // Verify.
69         $this->check_current_state(question_state::$todo);
70         $this->check_current_mark(null);
71         $this->check_current_output(
72                 $this->get_contains_marked_out_of_summary(),
73                 $this->get_does_not_contain_submit_button_expectation(),
74                 $this->get_contains_try_again_button_expectation(true),
75                 $this->get_contains_hint_expectation('This is the first hint.'));
77         // Do try again.
78         $this->process_submission(array('-tryagain' => 1));
80         // Verify.
81         $this->check_current_state(question_state::$todo);
82         $this->check_current_mark(null);
83         $this->check_current_output(
84                 $this->get_contains_marked_out_of_summary(),
85                 $this->get_contains_submit_button_expectation(true),
86                 $this->get_does_not_contain_feedback_expectation(),
87                 $this->get_does_not_contain_validation_error_expectation(),
88                 $this->get_does_not_contain_try_again_button_expectation(),
89                 $this->get_no_hint_visible_expectation());
91         // Now get it right.
92         $this->process_submission(array('-submit' => 1, 'answer' => '0'));
94         // Verify.
95         $this->check_current_state(question_state::$gradedright);
96         $this->check_current_mark(2);
97         $this->check_current_output(
98                 $this->get_contains_mark_summary(2),
99                 $this->get_does_not_contain_submit_button_expectation(),
100                 $this->get_contains_correct_expectation(),
101                 $this->get_does_not_contain_validation_error_expectation(),
102                 $this->get_no_hint_visible_expectation());
103     }
105     public function test_interactive_multi_response() {
107         // Create a gapselect question.
108         $q = test_question_maker::make_question('calculatedmulti', 'multiresponse');
109         $q->shuffleanswers = false;
110         $q->hints = array(
111                 new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, true, false),
112                 new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, false),
113         );
114         $this->start_attempt_at_question($q, 'interactive', 3, 2);
115         $values = $q->vs->get_values();
116         $this->assertEquals($values, $q->datasetloader->load_values(2));
118         // Check the initial state.
119         $this->check_current_state(question_state::$todo);
120         $this->check_current_mark(null);
121         $this->check_current_output(
122                 $this->get_contains_marked_out_of_summary(),
123                 $this->get_contains_submit_button_expectation(true),
124                 $this->get_does_not_contain_feedback_expectation(),
125                 $this->get_does_not_contain_validation_error_expectation(),
126                 $this->get_does_not_contain_try_again_button_expectation(),
127                 $this->get_no_hint_visible_expectation());
129         // Submit all boxes ticked.
130         $this->process_submission(array('-submit' => 1, 'choice0' => '1', 'choice1' => '1', 'choice2' => '1'));
132         // Verify.
133         $this->check_current_state(question_state::$todo);
134         $this->check_current_mark(null);
135         $this->check_current_output(
136                 $this->get_contains_marked_out_of_summary(),
137                 $this->get_does_not_contain_submit_button_expectation(),
138                 $this->get_contains_try_again_button_expectation(true),
139                 $this->get_contains_hint_expectation('This is the first hint.'));
141         // Do try again.
142         $this->process_submission(array('-tryagain' => 1));
144         // Verify.
145         $this->check_current_state(question_state::$todo);
146         $this->check_current_mark(null);
147         $this->check_current_output(
148                 $this->get_contains_marked_out_of_summary(),
149                 $this->get_contains_submit_button_expectation(true),
150                 $this->get_does_not_contain_feedback_expectation(),
151                 $this->get_does_not_contain_validation_error_expectation(),
152                 $this->get_does_not_contain_try_again_button_expectation(),
153                 $this->get_no_hint_visible_expectation());
155         // Now get it right.
156         $this->process_submission(array('-submit' => 1, 'choice0' => '1', 'choice1' => '1', 'choice2' => '0'));
158         // Verify.
159         $this->check_current_state(question_state::$gradedright);
160         $this->check_current_mark(2);
161         $this->check_current_output(
162                 $this->get_contains_mark_summary(2),
163                 $this->get_does_not_contain_submit_button_expectation(),
164                 $this->get_contains_correct_expectation(),
165                 $this->get_does_not_contain_validation_error_expectation(),
166                 $this->get_no_hint_visible_expectation());
167     }