MDL-37506 question code: incorrect preg_quote uses.
[moodle.git] / question / type / calculatedsimple / tests / walkthrough_test.php
CommitLineData
603bd001
PS
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/>.
16
17/**
18 * This file contains overall tests of simple calculated questions.
19 *
20 * @package qtype
21 * @subpackage calculatedsimple
22 * @copyright 2011 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
31
32
33/**
34 * Unit tests for the simple calculated question type.
35 *
36 * @copyright 2011 The Open University
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class qtype_calculatedsimple_walkthrough_test extends qbehaviour_walkthrough_test_base {
40 public function test_interactive() {
41
42 // Create a gapselect question.
43 $q = test_question_maker::make_question('calculatedsimple');
44 $q->hints = array(
45 new question_hint(1, 'This is the first hint.', FORMAT_HTML),
46 new question_hint(2, 'This is the second hint.', FORMAT_HTML),
47 );
48 $this->start_attempt_at_question($q, 'interactive', 3);
49 $values = $q->vs->get_values();
50
51 // Check the initial state.
52 $this->check_current_state(question_state::$todo);
53 $this->check_current_mark(null);
54 $this->check_current_output(
55 $this->get_contains_marked_out_of_summary(),
56 $this->get_contains_submit_button_expectation(true),
57 $this->get_does_not_contain_feedback_expectation(),
58 $this->get_does_not_contain_validation_error_expectation(),
59 $this->get_does_not_contain_try_again_button_expectation(),
60 $this->get_no_hint_visible_expectation());
61
62 // Submit blank.
63 $this->process_submission(array('-submit' => 1, 'answer' => ''));
64
65 // Verify.
66 $this->check_current_state(question_state::$invalid);
67 $this->check_current_mark(null);
68 $this->check_current_output(
69 $this->get_contains_marked_out_of_summary(),
70 $this->get_contains_submit_button_expectation(true),
71 $this->get_does_not_contain_feedback_expectation(),
72 $this->get_contains_validation_error_expectation(),
73 $this->get_does_not_contain_try_again_button_expectation(),
74 $this->get_no_hint_visible_expectation());
75
76 // Sumit something that does not look like a number.
77 $this->process_submission(array('-submit' => 1, 'answer' => 'newt'));
78
79 // Verify.
80 $this->check_current_state(question_state::$invalid);
81 $this->check_current_mark(null);
82 $this->check_current_output(
83 $this->get_contains_marked_out_of_summary(),
84 $this->get_contains_submit_button_expectation(true),
85 $this->get_does_not_contain_feedback_expectation(),
86 $this->get_contains_validation_error_expectation(),
87 new question_pattern_expectation('/' .
03cefcc9 88 preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'),
603bd001
PS
89 $this->get_does_not_contain_try_again_button_expectation(),
90 $this->get_no_hint_visible_expectation());
91
92 // Now get it right.
93 $this->process_submission(array('-submit' => 1, 'answer' => $values['a'] + $values['b']));
94
95 // Verify.
96 $this->check_current_state(question_state::$gradedright);
97 $this->check_current_mark(3);
98 $this->check_current_output(
99 $this->get_contains_mark_summary(3),
100 $this->get_contains_submit_button_expectation(false),
101 $this->get_contains_correct_expectation(),
102 $this->get_does_not_contain_validation_error_expectation(),
103 $this->get_no_hint_visible_expectation());
104 }
105}