MDL-43874 quiz, teacher comments should respect display options.
[moodle.git] / mod / quiz / tests / quizdisplayoptions_test.php
blobe0b51b0076b42fb1a38cfd5d711e0961b8d721de
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 * Unit tests for the mod_quiz_display_options class.
20 * @package mod_quiz
21 * @category phpunit
22 * @copyright 2010 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 global $CFG;
30 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
33 /**
34 * Unit tests for {@link mod_quiz_display_options}.
36 * @copyright 2010 The Open University
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class mod_quiz_display_options_testcase extends basic_testcase {
40 public function test_num_attempts_access_rule() {
41 $quiz = new stdClass();
42 $quiz->decimalpoints = 2;
43 $quiz->questiondecimalpoints = -1;
44 $quiz->reviewattempt = 0x11110;
45 $quiz->reviewcorrectness = 0x10000;
46 $quiz->reviewmarks = 0x01110;
47 $quiz->reviewspecificfeedback = 0x10000;
48 $quiz->reviewgeneralfeedback = 0x01000;
49 $quiz->reviewrightanswer = 0x00100;
50 $quiz->reviewoverallfeedback = 0x00010;
52 $options = mod_quiz_display_options::make_from_quiz($quiz,
53 mod_quiz_display_options::DURING);
55 $this->assertEquals(true, $options->attempt);
56 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->correctness);
57 $this->assertEquals(mod_quiz_display_options::MAX_ONLY, $options->marks);
58 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->feedback);
59 // The next two should be controlled by the same settings as ->feedback.
60 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->numpartscorrect);
61 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->manualcomment);
62 $this->assertEquals(2, $options->markdp);
64 $quiz->questiondecimalpoints = 5;
65 $options = mod_quiz_display_options::make_from_quiz($quiz,
66 mod_quiz_display_options::IMMEDIATELY_AFTER);
68 $this->assertEquals(mod_quiz_display_options::MARK_AND_MAX, $options->marks);
69 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->generalfeedback);
70 $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->feedback);
71 // The next two should be controlled by the same settings as ->feedback.
72 $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->numpartscorrect);
73 $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->manualcomment);
74 $this->assertEquals(5, $options->markdp);
76 $options = mod_quiz_display_options::make_from_quiz($quiz,
77 mod_quiz_display_options::LATER_WHILE_OPEN);
79 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->rightanswer);
80 $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->generalfeedback);
82 $options = mod_quiz_display_options::make_from_quiz($quiz,
83 mod_quiz_display_options::AFTER_CLOSE);
85 $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->overallfeedback);
86 $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->rightanswer);