MDL-77564 Quiz display options: Hide or show the grade information
[moodle.git] / mod / quiz / tests / question / display_options_test.php
blob21e245c8f06cdc1388dd3992ea1cbc1a23fe7283
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 namespace mod_quiz\question;
19 defined('MOODLE_INTERNAL') || die();
21 global $CFG;
22 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
24 /**
25 * Unit tests for {@see display_options}.
27 * @package mod_quiz
28 * @category test
29 * @copyright 2010 The Open University
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 * @covers \mod_quiz\question\display_options
33 class display_options_test extends \basic_testcase {
34 public function test_num_attempts_access_rule() {
35 $quiz = new \stdClass();
36 $quiz->decimalpoints = 2;
37 $quiz->questiondecimalpoints = -1;
38 $quiz->reviewattempt = 0x11110;
39 $quiz->reviewcorrectness = 0x10000;
40 $quiz->reviewmaxmarks = 0x10000; // Max marks is set.
41 $quiz->reviewmarks = 0x00000; // Marks is not set.
42 $quiz->reviewspecificfeedback = 0x10000;
43 $quiz->reviewgeneralfeedback = 0x01000;
44 $quiz->reviewrightanswer = 0x00100;
45 $quiz->reviewoverallfeedback = 0x00010;
47 $options = display_options::make_from_quiz($quiz,
48 display_options::DURING);
50 $this->assertEquals(true, $options->attempt);
51 $this->assertEquals(display_options::VISIBLE, $options->correctness);
52 $this->assertEquals(display_options::MAX_ONLY, $options->marks);
53 $this->assertEquals(display_options::VISIBLE, $options->feedback);
54 // The next two should be controlled by the same settings as ->feedback.
55 $this->assertEquals(display_options::VISIBLE, $options->numpartscorrect);
56 $this->assertEquals(display_options::VISIBLE, $options->manualcomment);
57 $this->assertEquals(2, $options->markdp);
59 $quiz->questiondecimalpoints = 5;
60 $quiz->reviewmaxmarks = 0x11000; // Max marks is set.
61 $quiz->reviewmarks = 0x11000; // Marks is also set.
62 $options = display_options::make_from_quiz($quiz,
63 display_options::IMMEDIATELY_AFTER);
65 $this->assertEquals(display_options::MARK_AND_MAX, $options->marks);
66 $this->assertEquals(display_options::VISIBLE, $options->generalfeedback);
67 $this->assertEquals(display_options::HIDDEN, $options->feedback);
68 // The next two should be controlled by the same settings as ->feedback.
69 $this->assertEquals(display_options::HIDDEN, $options->numpartscorrect);
70 $this->assertEquals(display_options::HIDDEN, $options->manualcomment);
71 $this->assertEquals(5, $options->markdp);
73 $quiz->reviewmaxmarks = 0x00000; // Max marks is NOT set.
74 $quiz->reviewmarks = 0x00000; // Marks is also NOT set.
75 $options = display_options::make_from_quiz($quiz,
76 display_options::LATER_WHILE_OPEN);
78 $this->assertEquals(display_options::HIDDEN, $options->marks);
79 $this->assertEquals(display_options::VISIBLE, $options->rightanswer);
80 $this->assertEquals(display_options::HIDDEN, $options->generalfeedback);
82 $options = display_options::make_from_quiz($quiz,
83 display_options::AFTER_CLOSE);
85 $this->assertEquals(display_options::VISIBLE, $options->overallfeedback);
86 $this->assertEquals(display_options::HIDDEN, $options->rightanswer);