MDL-29571 qtype description refactor unit test code a bit.
[moodle.git] / question / behaviour / informationitem / simpletest / testwalkthrough.php
blob68b70867b78a2ab8054b692657cf59121f2e5857
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.
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.
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
28 defined('MOODLE_INTERNAL') || die();
30 require_once(dirname(__FILE__) . '/../../../engine/lib.php');
31 require_once(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php');
34 /**
35 * Unit tests for the information item behaviour.
37 * @copyright 2009 The Open University
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class qbehaviour_informationitem_walkthrough_test extends qbehaviour_walkthrough_test_base {
41 public function test_informationitem_feedback_description() {
43 // Create a true-false question with correct answer true.
44 $description = test_question_maker::make_question('description');
45 $this->start_attempt_at_question($description, 'deferredfeedback');
47 // Check the initial state.
48 $this->check_current_state(question_state::$todo);
49 $this->check_current_mark(null);
50 $this->check_current_output($this->get_contains_question_text_expectation($description),
51 new ContainsTagWithAttributes('input', array('type' => 'hidden',
52 'name' => $this->quba->get_field_prefix($this->slot) . '-seen', 'value' => 1)),
53 $this->get_does_not_contain_feedback_expectation());
55 // Process a submission indicating this question has been seen.
56 $this->process_submission(array('-seen' => 1));
58 $this->check_current_state(question_state::$complete);
59 $this->check_current_mark(null);
60 $this->check_current_output($this->get_does_not_contain_correctness_expectation(),
61 new NoPatternExpectation(
62 '/type=\"hidden\"[^>]*name=\"[^"]*seen\"|name=\"[^"]*seen\"[^>]*type=\"hidden\"/'),
63 $this->get_does_not_contain_feedback_expectation());
65 // Finish the attempt.
66 $this->quba->finish_all_questions();
68 // Verify.
69 $this->check_current_state(question_state::$finished);
70 $this->check_current_mark(null);
71 $this->check_current_output(
72 $this->get_contains_question_text_expectation($description),
73 $this->get_contains_general_feedback_expectation($description));
75 // Process a manual comment.
76 $this->manual_grade('Not good enough!', null);
78 $this->check_current_state(question_state::$manfinished);
79 $this->check_current_mark(null);
80 $this->check_current_output(
81 new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
83 // Check that trying to process a manual comment with a grade causes an exception.
84 $this->expectException();
85 $this->manual_grade('Not good enough!', 1);