MDL-37506 question code: incorrect preg_quote uses.
[moodle.git] / question / type / truefalse / 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 tests that walks a truefalse question through various
19  * behaviours.
20  *
21  * @package    qtype
22  * @subpackage truefalse
23  * @copyright  2011 The Open University
24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
28 defined('MOODLE_INTERNAL') || die();
30 global $CFG;
31 require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
34 /**
35  * Walkthrough tests for the truefalse question type.
36  *
37  * @copyright  2011 The Open University
38  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39  */
40 class qtype_truefalse_walkthrough_test extends qbehaviour_walkthrough_test_base {
41     public function test_false_right_does_not_show_feedback_when_not_answered() {
43         // Create a true-false question with correct answer false.
44         $tf = test_question_maker::make_question('truefalse', 'false');
45         $this->start_attempt_at_question($tf, 'deferredfeedback', 1);
47         // Check the initial state.
48         $this->check_current_state(question_state::$todo);
49         $this->check_current_mark(null);
50         $this->check_current_output(
51                 $this->get_contains_question_text_expectation($tf),
52                 $this->get_does_not_contain_feedback_expectation(),
53                 new question_contains_tag_with_contents('h3',
54                         get_string('questiontext', 'question')));
55         $this->assertEquals(get_string('false', 'qtype_truefalse'),
56                 $this->quba->get_right_answer_summary($this->slot));
57         $this->assertRegExp('/' . preg_quote($tf->questiontext, '/') . '/',
58                 $this->quba->get_question_summary($this->slot));
59         $this->assertNull($this->quba->get_response_summary($this->slot));
61         // Finish the attempt without answering.
62         $this->quba->finish_all_questions();
64         // Verify.
65         $this->check_current_state(question_state::$gaveup);
66         $this->check_current_mark(null);
67         $this->check_current_output(
68                 $this->get_contains_tf_true_radio_expectation(false, false),
69                 $this->get_contains_tf_false_radio_expectation(false, false),
71                 // In particular, check that the false feedback is not displayed.
72                 new question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback, '/') . '/'));
74     }
75 }