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