MDL-37506 question code: incorrect preg_quote uses.
[moodle.git] / question / behaviour / informationitem / 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 question through the information item
19  * behaviour.
20  *
21  * @package    qbehaviour
22  * @subpackage informationitem
23  * @copyright  2009 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(dirname(__FILE__) . '/../../../engine/lib.php');
32 require_once(dirname(__FILE__) . '/../../../engine/tests/helpers.php');
35 /**
36  * Unit tests for the information item behaviour.
37  *
38  * @copyright  2009 The Open University
39  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40  */
41 class qbehaviour_informationitem_walkthrough_test extends qbehaviour_walkthrough_test_base {
42     public function test_informationitem_feedback_description() {
44         // Create a true-false question with correct answer true.
45         $description = test_question_maker::make_question('description');
46         $this->start_attempt_at_question($description, 'deferredfeedback');
48         // Check the initial state.
49         $this->check_current_state(question_state::$todo);
50         $this->check_current_mark(null);
51         $this->check_current_output($this->get_contains_question_text_expectation($description),
52                 new question_contains_tag_with_attributes('input', array('type' => 'hidden',
53                 'name' => $this->quba->get_field_prefix($this->slot) . '-seen', 'value' => 1)),
54                 $this->get_does_not_contain_feedback_expectation());
56         // Process a submission indicating this question has been seen.
57         $this->process_submission(array('-seen' => 1));
59         $this->check_current_state(question_state::$complete);
60         $this->check_current_mark(null);
61         $this->check_current_output($this->get_does_not_contain_correctness_expectation(),
62                 new question_no_pattern_expectation(
63                 '/type=\"hidden\"[^>]*name=\"[^"]*seen\"|name=\"[^"]*seen\"[^>]*type=\"hidden\"/'),
64                 $this->get_does_not_contain_feedback_expectation());
66         // Finish the attempt.
67         $this->quba->finish_all_questions();
69         // Verify.
70         $this->check_current_state(question_state::$finished);
71         $this->check_current_mark(null);
72         $this->check_current_output(
73                 $this->get_contains_question_text_expectation($description),
74                 $this->get_contains_general_feedback_expectation($description));
76         // Process a manual comment.
77         $this->manual_grade('Not good enough!', null);
79         $this->check_current_state(question_state::$manfinished);
80         $this->check_current_mark(null);
81         $this->check_current_output(
82                 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
84         // Check that trying to process a manual comment with a grade causes an exception.
85         $this->setExpectedException('moodle_exception');
86         $this->manual_grade('Not good enough!', 1);
87     }
88 }