MDL-77564 Quiz display options: Hide or show the grade information
[moodle.git] / mod / quiz / tests / quizobj_test.php
blobce6e4fb2f216ec049c7736b683dfe09988682697
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;
19 use mod_quiz\question\display_options;
20 use mod_quiz\quiz_settings;
22 defined('MOODLE_INTERNAL') || die();
24 global $CFG;
25 require_once($CFG->dirroot . '/mod/quiz/locallib.php');
27 /**
28 * Unit tests for the quiz class
30 * @package mod_quiz
31 * @copyright 2008 The Open University
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class quizobj_test extends \basic_testcase {
35 public function test_cannot_review_message() {
36 $quiz = new \stdClass();
37 $quiz->reviewattempt = 0x10010;
38 $quiz->timeclose = 0;
39 $quiz->attempts = 0;
41 $cm = new \stdClass();
42 $cm->id = 123;
44 $quizobj = new quiz_settings($quiz, $cm, new \stdClass(), false);
46 $this->assertEquals('',
47 $quizobj->cannot_review_message(display_options::DURING));
48 $this->assertEquals('',
49 $quizobj->cannot_review_message(display_options::IMMEDIATELY_AFTER));
50 $this->assertEquals(get_string('noreview', 'quiz'),
51 $quizobj->cannot_review_message(display_options::LATER_WHILE_OPEN));
52 $this->assertEquals(get_string('noreview', 'quiz'),
53 $quizobj->cannot_review_message(display_options::AFTER_CLOSE));
55 $closetime = time() + 10000;
56 $quiz->timeclose = $closetime;
57 $quizobj = new quiz_settings($quiz, $cm, new \stdClass(), false);
59 $this->assertEquals(get_string('noreviewuntil', 'quiz', userdate($closetime)),
60 $quizobj->cannot_review_message(display_options::LATER_WHILE_OPEN));