on-demand release 2.8beta+
[moodle.git] / mod / quiz / tests / generator / lib.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 defined('MOODLE_INTERNAL') || die();
19 /**
20  * Quiz module test data generator class
21  *
22  * @package mod_quiz
23  * @copyright 2012 The Open University
24  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
26 class mod_quiz_generator extends testing_module_generator {
28     public function create_instance($record = null, array $options = null) {
29         global $CFG;
30         require_once($CFG->dirroot.'/mod/quiz/locallib.php');
31         $record = (object)(array)$record;
33         $alwaysvisible = mod_quiz_display_options::DURING | mod_quiz_display_options::IMMEDIATELY_AFTER |
34                 mod_quiz_display_options::LATER_WHILE_OPEN | mod_quiz_display_options::AFTER_CLOSE;
36         $defaultquizsettings = array(
37             'timeopen'               => 0,
38             'timeclose'              => 0,
39             'preferredbehaviour'     => 'deferredfeedback',
40             'attempts'               => 0,
41             'attemptonlast'          => 0,
42             'grademethod'            => QUIZ_GRADEHIGHEST,
43             'decimalpoints'          => 2,
44             'questiondecimalpoints'  => -1,
45             'reviewattempt'          => $alwaysvisible,
46             'reviewcorrectness'      => $alwaysvisible,
47             'reviewmarks'            => $alwaysvisible,
48             'reviewspecificfeedback' => $alwaysvisible,
49             'reviewgeneralfeedback'  => $alwaysvisible,
50             'reviewrightanswer'      => $alwaysvisible,
51             'reviewoverallfeedback'  => $alwaysvisible,
52             'questionsperpage'       => 1,
53             'shufflequestions'       => 0,
54             'shuffleanswers'         => 1,
55             'sumgrades'              => 0,
56             'grade'                  => 0,
57             'timecreated'            => time(),
58             'timemodified'           => time(),
59             'timelimit'              => 0,
60             'overduehandling'        => 'autoabandon',
61             'graceperiod'            => 86400,
62             'quizpassword'           => '',
63             'subnet'                 => '',
64             'browsersecurity'        => '',
65             'delay1'                 => 0,
66             'delay2'                 => 0,
67             'showuserpicture'        => 0,
68             'showblocks'             => 0,
69             'navmethod'              => QUIZ_NAVMETHOD_FREE,
70         );
72         foreach ($defaultquizsettings as $name => $value) {
73             if (!isset($record->{$name})) {
74                 $record->{$name} = $value;
75             }
76         }
78         return parent::create_instance($record, (array)$options);
79     }
80 }