walkthrough_test.php 7.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * This file contains tests that walks a question through the interactive
 * behaviour.
 *
21
 * @package    qtype
22
 * @subpackage gapselect
23
 * @copyright  2012 The Open University
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
26
27
 */


28
defined('MOODLE_INTERNAL') || die();
29
global $CFG;
30

31
32
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
33
34


35
36
37
/**
 * Unit tests for the gap-select question type.
 *
38
 * @copyright  2012 The Open University
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 * @group      qtype_gapselect
41
 */
42
class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base {
43
    public function test_interactive_behaviour() {
44

45
46
47
        // Create a gapselect question.
        $q = qtype_gapselect_test_helper::make_a_gapselect_question();
        $q->hints = array(
48
49
            new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, false, false),
            new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, true),
50
        );
51
        $q->shufflechoices = false;
52
        $this->start_attempt_at_question($q, 'interactive', 3);
53

54
55
56
57
58
        // Check the initial state.
        $this->check_current_state(question_state::$todo);
        $this->check_current_mark(null);
        $this->check_current_output(
                $this->get_contains_select_expectation('p1',
59
                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), null, true),
60
                $this->get_contains_select_expectation('p2',
61
                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), null, true),
62
                $this->get_contains_select_expectation('p3',
63
                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), null, true),
64
65
66
67
68
69
70
71
72
73
74
75
76
                $this->get_contains_submit_button_expectation(true),
                $this->get_does_not_contain_feedback_expectation(),
                $this->get_tries_remaining_expectation(3),
                $this->get_no_hint_visible_expectation());

        // Save the wrong answer.
        $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2'));

        // Verify.
        $this->check_current_state(question_state::$todo);
        $this->check_current_mark(null);
        $this->check_current_output(
                $this->get_contains_select_expectation('p1',
77
                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true),
78
                $this->get_contains_select_expectation('p2',
79
                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true),
80
                $this->get_contains_select_expectation('p3',
81
                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true),
82
83
84
85
86
87
88
89
90
91
92
93
94
95
                $this->get_contains_submit_button_expectation(true),
                $this->get_does_not_contain_correctness_expectation(),
                $this->get_does_not_contain_feedback_expectation(),
                $this->get_tries_remaining_expectation(3),
                $this->get_no_hint_visible_expectation());

        // Submit the wrong answer.
        $this->process_submission(array('p1' => '2', 'p2' => '2', 'p3' => '2', '-submit' => 1));

        // Verify.
        $this->check_current_state(question_state::$todo);
        $this->check_current_mark(null);
        $this->check_current_output(
                $this->get_contains_select_expectation('p1',
96
                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, false),
97
                $this->get_contains_select_expectation('p2',
98
                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, false),
99
                $this->get_contains_select_expectation('p3',
100
                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, false),
101
102
103
                        $this->get_contains_submit_button_expectation(false),
                $this->get_contains_try_again_button_expectation(true),
                $this->get_does_not_contain_correctness_expectation(),
104
                new question_pattern_expectation('/' . preg_quote(
105
                        get_string('notcomplete', 'qbehaviour_interactive'), '/') . '/'),
106
107
108
109
110
111
112
113
114
115
                $this->get_contains_hint_expectation('This is the first hint'));

        // Do try again.
        $this->process_submission(array('-tryagain' => 1));

        // Verify.
        $this->check_current_state(question_state::$todo);
        $this->check_current_mark(null);
        $this->check_current_output(
                $this->get_contains_select_expectation('p1',
116
                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 2, true),
117
                $this->get_contains_select_expectation('p2',
118
                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 2, true),
119
                $this->get_contains_select_expectation('p3',
120
                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 2, true),
121
122
123
124
125
126
127
128
129
130
131
132
133
134
                $this->get_contains_submit_button_expectation(true),
                $this->get_does_not_contain_correctness_expectation(),
                $this->get_does_not_contain_feedback_expectation(),
                $this->get_tries_remaining_expectation(2),
                $this->get_no_hint_visible_expectation());

        // Submit the right answer.
        $this->process_submission(array('p1' => '1', 'p2' => '1', 'p3' => '1', '-submit' => 1));

        // Verify.
        $this->check_current_state(question_state::$gradedright);
        $this->check_current_mark(2);
        $this->check_current_output(
                $this->get_contains_select_expectation('p1',
135
                                array('' => get_string('choosedots'), '1' => 'quick', '2' => 'slow'), 1, false),
136
                $this->get_contains_select_expectation('p2',
137
                                array('' => get_string('choosedots'), '1' => 'fox', '2' => 'dog'), 1, false),
138
                $this->get_contains_select_expectation('p3',
139
                                array('' => get_string('choosedots'), '1' => 'lazy', '2' => 'assiduous'), 1, false),
140
141
142
143
144
145
146
147
148
149
150
                $this->get_contains_submit_button_expectation(false),
                $this->get_contains_correct_expectation(),
                $this->get_no_hint_visible_expectation());

        // Check regrading does not mess anything up.
        $this->quba->regrade_all_questions();

        // Verify.
        $this->check_current_state(question_state::$gradedright);
        $this->check_current_mark(2);
    }
151
}