MDL-47673 quiz generator: default grade 100 & fix review options
[moodle.git] / mod / quiz / tests / generator / lib.php
CommitLineData
2cf5ab10
TH
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/>.
16
17defined('MOODLE_INTERNAL') || die();
18
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 */
5c3c2c81 26class mod_quiz_generator extends testing_module_generator {
2cf5ab10 27
2cf5ab10
TH
28 public function create_instance($record = null, array $options = null) {
29 global $CFG;
0233e2a9 30
7fbe33fc 31 require_once($CFG->dirroot.'/mod/quiz/locallib.php');
2cf5ab10 32 $record = (object)(array)$record;
2cf5ab10 33
2cf5ab10 34 $defaultquizsettings = array(
2cf5ab10
TH
35 'timeopen' => 0,
36 'timeclose' => 0,
37 'preferredbehaviour' => 'deferredfeedback',
38 'attempts' => 0,
39 'attemptonlast' => 0,
40 'grademethod' => QUIZ_GRADEHIGHEST,
41 'decimalpoints' => 2,
42 'questiondecimalpoints' => -1,
0233e2a9
TH
43 'attemptduring' => 1,
44 'correctnessduring' => 1,
45 'marksduring' => 1,
46 'specificfeedbackduring' => 1,
47 'generalfeedbackduring' => 1,
48 'rightanswerduring' => 1,
49 'overallfeedbackduring' => 0,
50 'attemptimmediately' => 1,
51 'correctnessimmediately' => 1,
52 'marksimmediately' => 1,
53 'specificfeedbackimmediately' => 1,
54 'generalfeedbackimmediately' => 1,
55 'rightanswerimmediately' => 1,
56 'overallfeedbackimmediately' => 1,
57 'attemptopen' => 1,
58 'correctnessopen' => 1,
59 'marksopen' => 1,
60 'specificfeedbackopen' => 1,
61 'generalfeedbackopen' => 1,
62 'rightansweropen' => 1,
63 'overallfeedbackopen' => 1,
64 'attemptclosed' => 1,
65 'correctnessclosed' => 1,
66 'marksclosed' => 1,
67 'specificfeedbackclosed' => 1,
68 'generalfeedbackclosed' => 1,
69 'rightanswerclosed' => 1,
70 'overallfeedbackclosed' => 1,
2cf5ab10
TH
71 'questionsperpage' => 1,
72 'shufflequestions' => 0,
73 'shuffleanswers' => 1,
2cf5ab10 74 'sumgrades' => 0,
0233e2a9 75 'grade' => 100,
2cf5ab10
TH
76 'timecreated' => time(),
77 'timemodified' => time(),
78 'timelimit' => 0,
79 'overduehandling' => 'autoabandon',
80 'graceperiod' => 86400,
81 'quizpassword' => '',
82 'subnet' => '',
83 'browsersecurity' => '',
84 'delay1' => 0,
85 'delay2' => 0,
86 'showuserpicture' => 0,
87 'showblocks' => 0,
88 'navmethod' => QUIZ_NAVMETHOD_FREE,
89 );
90
91 foreach ($defaultquizsettings as $name => $value) {
92 if (!isset($record->{$name})) {
93 $record->{$name} = $value;
94 }
95 }
96
7fbe33fc 97 return parent::create_instance($record, (array)$options);
2cf5ab10
TH
98 }
99}