Merge branch 'MDL-43757_master' of git://github.com/dmonllao/moodle
[moodle.git] / mod / quiz / tests / quizdisplayoptions_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  * Unit tests for the mod_quiz_display_options class.
19  *
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
24  */
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}.
35  *
36  * @copyright  2010 The Open University
37  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38  */
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(2, $options->markdp);
60         $quiz->questiondecimalpoints = 5;
61         $options = mod_quiz_display_options::make_from_quiz($quiz,
62             mod_quiz_display_options::IMMEDIATELY_AFTER);
64         $this->assertEquals(mod_quiz_display_options::MARK_AND_MAX, $options->marks);
65         $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->generalfeedback);
66         $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->feedback);
67         $this->assertEquals(5, $options->markdp);
69         $options = mod_quiz_display_options::make_from_quiz($quiz,
70             mod_quiz_display_options::LATER_WHILE_OPEN);
72         $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->rightanswer);
73         $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->generalfeedback);
75         $options = mod_quiz_display_options::make_from_quiz($quiz,
76             mod_quiz_display_options::AFTER_CLOSE);
78         $this->assertEquals(mod_quiz_display_options::VISIBLE, $options->overallfeedback);
79         $this->assertEquals(mod_quiz_display_options::HIDDEN, $options->rightanswer);
80     }
81 }