gradebook MDL-24330 unit tests now function differently so produce different results
[moodle.git] / lib / simpletest / fixtures / gradetest.php
CommitLineData
8926f844 1<?php
02e6a973 2
320bb66e
EL
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * @package moodlecore
20 * @copyright nicolas@moodle.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
02e6a973 23
cdbbd26f 24if (!defined('MOODLE_INTERNAL')) {
25 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
26}
27
b1f93b15 28require_once($CFG->libdir . '/adminlib.php');
02e6a973 29require_once($CFG->libdir . '/gradelib.php');
1f0e4921 30
02e6a973 31/**
320bb66e
EL
32 * Shared code for all grade related tests.
33 *
02e6a973 34 * Here is a brief explanation of the test data set up in these unit tests.
35 * category1 => array(category2 => array(grade_item1, grade_item2), category3 => array(grade_item3))
36 * 3 users for 3 grade_items
37 */
3d90fbc4
EL
38class grade_test extends UnitTestCaseUsingDatabase {
39
40 public $grade_tables = array('lib' => array(
41 'grade_categories', 'grade_categories_history',
42 'scale', 'scale_history',
43 'grade_items', 'grade_items_history',
44 'grade_grades', 'grade_grades_history',
45 'grade_outcomes', 'grade_outcomes_history','grade_outcomes_courses',
46 'files',
47 'modules',
48 'course_modules'),
49 'mod/quiz' => array('quiz')
50 );
c7d306e1 51
da3801e8 52 public $grade_items = array();
53 public $grade_categories = array();
54 public $grade_grades = array();
55 public $grade_outcomes = array();
56 public $scale = array();
02e6a973 57
da3801e8 58 public $activities = array();
59 public $courseid = 1;
60 public $userid = 1;
1f0e4921 61
02e6a973 62 /**
63 * Create temporary test tables and entries in the database for these tests.
772ddfbf 64 * These tests have to work on a brand new site.
02e6a973 65 */
66 function setUp() {
3d90fbc4 67 global $CFG;
da3801e8 68
c7d306e1 69 parent::setup();
e480c18c 70 $CFG->grade_droplow = -1;
71 $CFG->grade_keephigh = -1;
72 $CFG->grade_aggregation = -1;
73 $CFG->grade_aggregateonlygraded = -1;
74 $CFG->grade_aggregateoutcomes = -1;
75 $CFG->grade_aggregatesubcats = -1;
f3ac8eb4 76
3d90fbc4
EL
77 $this->switch_to_test_db(); // All operations until end of test method will happen in test DB
78
79 foreach ($this->grade_tables as $dir => $tables) {
80 $this->create_test_tables($tables, $dir); // Create tables
81 foreach ($tables as $table) { // Fill them if load_xxx method is available
82 $function = "load_$table";
83 if (method_exists($this, $function)) {
84 $this->$function();
85 }
86 }
f3ac8eb4 87 }
3d90fbc4 88
f3ac8eb4 89 }
90
1f0e4921 91 function tearDown() {
3d90fbc4 92 parent::tearDown(); // All the test tables created in setUp will be dropped by this
02e6a973 93 }
94
02e6a973 95 /**
96 * Load scale data into the database, and adds the corresponding objects to this class' variable.
97 */
98 function load_scale() {
da3801e8 99 global $DB;
02e6a973 100 $scale = new stdClass();
772ddfbf 101
02e6a973 102 $scale->name = 'unittestscale1';
103 $scale->courseid = $this->courseid;
104 $scale->userid = $this->userid;
105 $scale->scale = 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
106 $scale->description = 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
107 $scale->timemodified = mktime();
772ddfbf 108
a9637e7d
PS
109 $scale->id = $DB->insert_record('scale', $scale);
110 $this->scale[0] = $scale;
111 $temp = explode(',', $scale->scale);
112 $this->scalemax[0] = count($temp) -1;
02e6a973 113
114 $scale = new stdClass();
772ddfbf 115
02e6a973 116 $scale->name = 'unittestscale2';
117 $scale->courseid = $this->courseid;
118 $scale->userid = $this->userid;
119 $scale->scale = 'Distinction, Very Good, Good, Pass, Fail';
120 $scale->description = 'This scale is used to mark standard assignments.';
121 $scale->timemodified = mktime();
772ddfbf 122
a9637e7d
PS
123 $scale->id = $DB->insert_record('scale', $scale);
124 $this->scale[1] = $scale;
125 $temp = explode(',', $scale->scale);
126 $this->scalemax[1] = count($temp) -1;
02e6a973 127
128 $scale = new stdClass();
772ddfbf 129
02e6a973 130 $scale->name = 'unittestscale3';
131 $scale->courseid = $this->courseid;
132 $scale->userid = $this->userid;
133 $scale->scale = 'Loner, Contentious, Disinterested, Participative, Follower, Leader';
134 $scale->description = 'Describes the level of teamwork of a student.';
135 $scale->timemodified = mktime();
b8ff92b6 136 $temp = explode(',', $scale->scale);
137 $scale->max = count($temp) -1;
772ddfbf 138
a9637e7d
PS
139 $scale->id = $DB->insert_record('scale', $scale);
140 $this->scale[2] = $scale;
141 $temp = explode(',', $scale->scale);
142 $this->scalemax[2] = count($temp) -1;
02e6a973 143
144 $scale->name = 'unittestscale4';
145 $scale->courseid = $this->courseid;
146 $scale->userid = $this->userid;
147 $scale->scale = 'Does not understand theory, Understands theory but fails practice, Manages through, Excels';
148 $scale->description = 'Level of expertise at a technical task, with a theoretical framework.';
149 $scale->timemodified = mktime();
b8ff92b6 150 $temp = explode(',', $scale->scale);
151 $scale->max = count($temp) -1;
772ddfbf 152
a9637e7d
PS
153 $scale->id = $DB->insert_record('scale', $scale);
154 $this->scale[3] = $scale;
155 $temp = explode(',', $scale->scale);
156 $this->scalemax[3] = count($temp) -1;
02e6a973 157
158 $scale->name = 'unittestscale5';
159 $scale->courseid = $this->courseid;
160 $scale->userid = $this->userid;
161 $scale->scale = 'Insufficient, Acceptable, Excellent.';
162 $scale->description = 'Description of skills.';
163 $scale->timemodified = mktime();
b8ff92b6 164 $temp = explode(',', $scale->scale);
165 $scale->max = count($temp) -1;
772ddfbf 166
a9637e7d
PS
167 $scale->id = $DB->insert_record('scale', $scale);
168 $this->scale[4] = $scale;
169 $temp = explode(',', $scale->scale);
170 $this->scalemax[4] = count($temp) -1;
02e6a973 171 }
172
173 /**
174 * Load grade_category data into the database, and adds the corresponding objects to this class' variable.
d84e7b7a
AD
175 * category structure:
176 course category
177 |
178 +--------+-------------+
179 | |
180 unittestcategory1 level1category
181 |
182 +--------+-------------+
183 | |
184 unittestcategory2 unittestcategory3
02e6a973 185 */
186 function load_grade_categories() {
da3801e8 187 global $DB;
f3ac8eb4 188
189 $course_category = grade_category::fetch_course_category($this->courseid);
b3ac6c3e 190
02e6a973 191 $grade_category = new stdClass();
772ddfbf 192
02e6a973 193 $grade_category->fullname = 'unittestcategory1';
194 $grade_category->courseid = $this->courseid;
c2efb501 195 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
196 $grade_category->aggregateonlygraded = 1;
b3ac6c3e 197 $grade_category->keephigh = 0;
02e6a973 198 $grade_category->droplow = 0;
b3ac6c3e 199 $grade_category->parent = $course_category->id;
f3ac8eb4 200 $grade_category->timecreated = mktime();
201 $grade_category->timemodified = mktime();
b3ac6c3e 202 $grade_category->depth = 2;
772ddfbf 203
a9637e7d
PS
204 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
205 $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
206 $DB->update_record('grade_categories', $grade_category);
207 $this->grade_categories[0] = $grade_category;
772ddfbf 208
02e6a973 209 $grade_category = new stdClass();
772ddfbf 210
02e6a973 211 $grade_category->fullname = 'unittestcategory2';
212 $grade_category->courseid = $this->courseid;
c2efb501 213 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
214 $grade_category->aggregateonlygraded = 1;
b3ac6c3e 215 $grade_category->keephigh = 0;
02e6a973 216 $grade_category->droplow = 0;
f3ac8eb4 217 $grade_category->parent = $this->grade_categories[0]->id;
218 $grade_category->timecreated = mktime();
219 $grade_category->timemodified = mktime();
b3ac6c3e 220 $grade_category->depth = 3;
772ddfbf 221
a9637e7d
PS
222 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
223 $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
224 $DB->update_record('grade_categories', $grade_category);
225 $this->grade_categories[1] = $grade_category;
772ddfbf 226
02e6a973 227 $grade_category = new stdClass();
772ddfbf 228
02e6a973 229 $grade_category->fullname = 'unittestcategory3';
230 $grade_category->courseid = $this->courseid;
c2efb501 231 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
232 $grade_category->aggregateonlygraded = 1;
b3ac6c3e 233 $grade_category->keephigh = 0;
02e6a973 234 $grade_category->droplow = 0;
f3ac8eb4 235 $grade_category->parent = $this->grade_categories[0]->id;
236 $grade_category->timecreated = mktime();
237 $grade_category->timemodified = mktime();
b3ac6c3e 238 $grade_category->depth = 3;
772ddfbf 239
a9637e7d
PS
240 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
241 $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
242 $DB->update_record('grade_categories', $grade_category);
243 $this->grade_categories[2] = $grade_category;
772ddfbf 244
02e6a973 245 // A category with no parent, but grade_items as children
246
247 $grade_category = new stdClass();
772ddfbf 248
02e6a973 249 $grade_category->fullname = 'level1category';
250 $grade_category->courseid = $this->courseid;
c2efb501 251 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
252 $grade_category->aggregateonlygraded = 1;
b3ac6c3e 253 $grade_category->keephigh = 0;
02e6a973 254 $grade_category->droplow = 0;
b3ac6c3e 255 $grade_category->parent = $course_category->id;
f3ac8eb4 256 $grade_category->timecreated = mktime();
257 $grade_category->timemodified = mktime();
b3ac6c3e 258 $grade_category->depth = 2;
772ddfbf 259
a9637e7d
PS
260 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
261 $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
262 $DB->update_record('grade_categories', $grade_category);
263 $this->grade_categories[3] = $grade_category;
02e6a973 264 }
265
e480c18c 266 /**
3d90fbc4 267 * Load module entries in modules table
e480c18c 268 */
269 function load_modules() {
da3801e8 270 global $DB;
e480c18c 271 $module = new stdClass();
272 $module->name = 'assignment';
a9637e7d
PS
273 $module->id = $DB->insert_record('modules', $module);
274 $this->modules[0] = $module;
e480c18c 275
276 $module = new stdClass();
277 $module->name = 'quiz';
a9637e7d
PS
278 $module->id = $DB->insert_record('modules', $module);
279 $this->modules[1] = $module;
e480c18c 280
281 $module = new stdClass();
282 $module->name = 'forum';
a9637e7d
PS
283 $module->id = $DB->insert_record('modules', $module);
284 $this->modules[2] = $module;
1994d890 285 }
286
e480c18c 287 /**
288 * Load module instance entries in course_modules table
289 */
290 function load_course_modules() {
da3801e8 291 global $DB;
e480c18c 292 $course_module = new stdClass();
293 $course_module->course = $this->courseid;
f3ac8eb4 294 $quiz->module = 1;
295 $quiz->instance = 2;
a9637e7d
PS
296 $course_module->id = $DB->insert_record('course_modules', $course_module);
297 $this->course_module[0] = $course_module;
e480c18c 298
299 $course_module = new stdClass();
300 $course_module->course = $this->courseid;
f3ac8eb4 301 $quiz->module = 2;
302 $quiz->instance = 1;
a9637e7d
PS
303 $course_module->id = $DB->insert_record('course_modules', $course_module);
304 $this->course_module[0] = $course_module;
e480c18c 305
306 $course_module = new stdClass();
307 $course_module->course = $this->courseid;
f3ac8eb4 308 $quiz->module = 2;
309 $quiz->instance = 5;
a9637e7d
PS
310 $course_module->id = $DB->insert_record('course_modules', $course_module);
311 $this->course_module[0] = $course_module;
e480c18c 312
313 $course_module = new stdClass();
314 $course_module->course = $this->courseid;
f3ac8eb4 315 $quiz->module = 3;
316 $quiz->instance = 3;
a9637e7d
PS
317 $course_module->id = $DB->insert_record('course_modules', $course_module);
318 $this->course_module[0] = $course_module;
e480c18c 319
320 $course_module = new stdClass();
321 $course_module->course = $this->courseid;
f3ac8eb4 322 $quiz->module = 3;
323 $quiz->instance = 7;
a9637e7d
PS
324 $course_module->id = $DB->insert_record('course_modules', $course_module);
325 $this->course_module[0] = $course_module;
e480c18c 326
327 $course_module = new stdClass();
328 $course_module->course = $this->courseid;
f3ac8eb4 329 $quiz->module = 3;
330 $quiz->instance = 9;
a9637e7d
PS
331 $course_module->id = $DB->insert_record('course_modules', $course_module);
332 $this->course_module[0] = $course_module;
f3ac8eb4 333 }
334
335 /**
336 * Load test quiz data into the database
337 */
338 function load_quiz_activities() {
da3801e8 339 global $DB;
f3ac8eb4 340 $quiz = new stdClass();
341 $quiz->course = $this->courseid;
342 $quiz->name = 'test quiz';
343 $quiz->intro = 'let us quiz you!';
344 $quiz->questions = '1,2';
a9637e7d
PS
345 $quiz->id = $DB->insert_record('quiz', $quiz);
346 $this->activities[0] = $quiz;
f3ac8eb4 347
348 $quiz = new stdClass();
349 $quiz->course = $this->courseid;
350 $quiz->name = 'test quiz 2';
351 $quiz->intro = 'let us quiz you again!';
352 $quiz->questions = '1,3';
a9637e7d
PS
353 $quiz->id = $DB->insert_record('quiz', $quiz);
354 $this->activities[1] = $quiz;
e480c18c 355 }
356
02e6a973 357 /**
358 * Load grade_item data into the database, and adds the corresponding objects to this class' variable.
359 */
360 function load_grade_items() {
da3801e8 361 global $DB;
b3ac6c3e 362
f3ac8eb4 363 $course_category = grade_category::fetch_course_category($this->courseid);
364
365 // id = 0
02e6a973 366 $grade_item = new stdClass();
367
368 $grade_item->courseid = $this->courseid;
369 $grade_item->categoryid = $this->grade_categories[1]->id;
370 $grade_item->itemname = 'unittestgradeitem1';
371 $grade_item->itemtype = 'mod';
372 $grade_item->itemmodule = 'quiz';
f3ac8eb4 373 $grade_item->iteminstance = 1;
02e6a973 374 $grade_item->gradetype = GRADE_TYPE_VALUE;
375 $grade_item->grademin = 30;
b8ff92b6 376 $grade_item->grademax = 110;
02e6a973 377 $grade_item->itemnumber = 1;
61c33818 378 $grade_item->idnumber = 'item id 0';
6639ead3 379 $grade_item->iteminfo = 'Grade item 0 used for unit testing';
02e6a973 380 $grade_item->timecreated = mktime();
381 $grade_item->timemodified = mktime();
382 $grade_item->sortorder = 3;
383
a9637e7d
PS
384 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
385 $this->grade_items[0] = $grade_item;
772ddfbf 386
f3ac8eb4 387 // id = 1
02e6a973 388 $grade_item = new stdClass();
389
390 $grade_item->courseid = $this->courseid;
f3ac8eb4 391 $grade_item->categoryid = $this->grade_categories[1]->id;
02e6a973 392 $grade_item->itemname = 'unittestgradeitem2';
393 $grade_item->itemtype = 'import';
394 $grade_item->itemmodule = 'assignment';
9acbd726 395 $grade_item->calculation = '= ##gi'.$this->grade_items[0]->id.'## + 30 + [[item id 0]] - [[item id 0]]';
02e6a973 396 $grade_item->gradetype = GRADE_TYPE_VALUE;
f3ac8eb4 397 $grade_item->iteminstance = 2;
02e6a973 398 $grade_item->itemnumber = null;
399 $grade_item->grademin = 0;
400 $grade_item->grademax = 100;
6639ead3 401 $grade_item->iteminfo = 'Grade item 1 used for unit testing';
02e6a973 402 $grade_item->timecreated = mktime();
403 $grade_item->timemodified = mktime();
404 $grade_item->sortorder = 4;
772ddfbf 405
a9637e7d
PS
406 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
407 $this->grade_items[1] = $grade_item;
02e6a973 408
f3ac8eb4 409 // id = 2
02e6a973 410 $grade_item = new stdClass();
411
412 $grade_item->courseid = $this->courseid;
f3ac8eb4 413 $grade_item->categoryid = $this->grade_categories[2]->id;
02e6a973 414 $grade_item->itemname = 'unittestgradeitem3';
415 $grade_item->itemtype = 'mod';
416 $grade_item->itemmodule = 'forum';
f3ac8eb4 417 $grade_item->iteminstance = 3;
02e6a973 418 $grade_item->gradetype = GRADE_TYPE_SCALE;
419 $grade_item->scaleid = $this->scale[0]->id;
420 $grade_item->grademin = 0;
f92dcad8 421 $grade_item->grademax = $this->scalemax[0];
6639ead3 422 $grade_item->iteminfo = 'Grade item 2 used for unit testing';
02e6a973 423 $grade_item->timecreated = mktime();
424 $grade_item->timemodified = mktime();
425 $grade_item->sortorder = 6;
426
a9637e7d
PS
427 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
428 $this->grade_items[2] = $grade_item;
02e6a973 429
430 // Load grade_items associated with the 3 categories
f3ac8eb4 431 // id = 3
02e6a973 432 $grade_item = new stdClass();
433
434 $grade_item->courseid = $this->courseid;
f3ac8eb4 435 $grade_item->iteminstance = $this->grade_categories[0]->id;
02e6a973 436 $grade_item->itemname = 'unittestgradeitemcategory1';
6639ead3 437 $grade_item->needsupdate = 0;
02e6a973 438 $grade_item->itemtype = 'category';
439 $grade_item->gradetype = GRADE_TYPE_VALUE;
440 $grade_item->grademin = 0;
441 $grade_item->grademax = 100;
6639ead3 442 $grade_item->iteminfo = 'Grade item 3 used for unit testing';
02e6a973 443 $grade_item->timecreated = mktime();
444 $grade_item->timemodified = mktime();
445 $grade_item->sortorder = 1;
446
a9637e7d
PS
447 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
448 $this->grade_items[3] = $grade_item;
772ddfbf 449
f3ac8eb4 450 // id = 4
02e6a973 451 $grade_item = new stdClass();
452
453 $grade_item->courseid = $this->courseid;
f3ac8eb4 454 $grade_item->iteminstance = $this->grade_categories[1]->id;
02e6a973 455 $grade_item->itemname = 'unittestgradeitemcategory2';
456 $grade_item->itemtype = 'category';
457 $grade_item->gradetype = GRADE_TYPE_VALUE;
6639ead3 458 $grade_item->needsupdate = 0;
02e6a973 459 $grade_item->grademin = 0;
460 $grade_item->grademax = 100;
6639ead3 461 $grade_item->iteminfo = 'Grade item 4 used for unit testing';
02e6a973 462 $grade_item->timecreated = mktime();
463 $grade_item->timemodified = mktime();
464 $grade_item->sortorder = 2;
465
a9637e7d
PS
466 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
467 $this->grade_items[4] = $grade_item;
02e6a973 468
f3ac8eb4 469 // id = 5
02e6a973 470 $grade_item = new stdClass();
471
472 $grade_item->courseid = $this->courseid;
f3ac8eb4 473 $grade_item->iteminstance = $this->grade_categories[2]->id;
02e6a973 474 $grade_item->itemname = 'unittestgradeitemcategory3';
475 $grade_item->itemtype = 'category';
476 $grade_item->gradetype = GRADE_TYPE_VALUE;
477 $grade_item->needsupdate = true;
478 $grade_item->grademin = 0;
479 $grade_item->grademax = 100;
6639ead3 480 $grade_item->iteminfo = 'Grade item 5 used for unit testing';
02e6a973 481 $grade_item->timecreated = mktime();
482 $grade_item->timemodified = mktime();
483 $grade_item->sortorder = 5;
484
a9637e7d
PS
485 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
486 $this->grade_items[5] = $grade_item;
02e6a973 487
488 // Orphan grade_item
f3ac8eb4 489 // id = 6
02e6a973 490 $grade_item = new stdClass();
491
492 $grade_item->courseid = $this->courseid;
b3ac6c3e 493 $grade_item->categoryid = $course_category->id;
02e6a973 494 $grade_item->itemname = 'unittestorphangradeitem1';
495 $grade_item->itemtype = 'mod';
496 $grade_item->itemmodule = 'quiz';
f3ac8eb4 497 $grade_item->iteminstance = 5;
2cc4b0f9 498 $grade_item->itemnumber = 0;
02e6a973 499 $grade_item->gradetype = GRADE_TYPE_VALUE;
500 $grade_item->grademin = 10;
501 $grade_item->grademax = 120;
2cc4b0f9 502 $grade_item->locked = time();
6639ead3 503 $grade_item->iteminfo = 'Orphan Grade 6 item used for unit testing';
02e6a973 504 $grade_item->timecreated = mktime();
505 $grade_item->timemodified = mktime();
506 $grade_item->sortorder = 7;
507
a9637e7d
PS
508 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
509 $this->grade_items[6] = $grade_item;
02e6a973 510
511 // 2 grade items under level1category
f3ac8eb4 512 // id = 7
02e6a973 513 $grade_item = new stdClass();
514
515 $grade_item->courseid = $this->courseid;
f3ac8eb4 516 $grade_item->categoryid = $this->grade_categories[3]->id;
02e6a973 517 $grade_item->itemname = 'singleparentitem1';
518 $grade_item->itemtype = 'mod';
519 $grade_item->itemmodule = 'forum';
f3ac8eb4 520 $grade_item->iteminstance = 7;
02e6a973 521 $grade_item->gradetype = GRADE_TYPE_SCALE;
522 $grade_item->scaleid = $this->scale[0]->id;
523 $grade_item->grademin = 0;
f92dcad8 524 $grade_item->grademax = $this->scalemax[0];
6639ead3 525 $grade_item->iteminfo = 'Grade item 7 used for unit testing';
02e6a973 526 $grade_item->timecreated = mktime();
527 $grade_item->timemodified = mktime();
528 $grade_item->sortorder = 9;
529
a9637e7d
PS
530 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
531 $this->grade_items[7] = $grade_item;
772ddfbf 532
f3ac8eb4 533 // id = 8
02e6a973 534 $grade_item = new stdClass();
535
536 $grade_item->courseid = $this->courseid;
f3ac8eb4 537 $grade_item->categoryid = $this->grade_categories[3]->id;
02e6a973 538 $grade_item->itemname = 'singleparentitem2';
539 $grade_item->itemtype = 'mod';
540 $grade_item->itemmodule = 'forum';
f3ac8eb4 541 $grade_item->iteminstance = 9;
02e6a973 542 $grade_item->gradetype = GRADE_TYPE_VALUE;
543 $grade_item->grademin = 0;
544 $grade_item->grademax = 100;
6639ead3 545 $grade_item->iteminfo = 'Grade item 8 used for unit testing';
02e6a973 546 $grade_item->timecreated = mktime();
547 $grade_item->timemodified = mktime();
548 $grade_item->sortorder = 10;
549
a9637e7d
PS
550 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
551 $this->grade_items[8] = $grade_item;
772ddfbf 552
02e6a973 553 // Grade_item for level1category
f3ac8eb4 554 // id = 9
02e6a973 555 $grade_item = new stdClass();
556
557 $grade_item->courseid = $this->courseid;
558 $grade_item->itemname = 'grade_item for level1 category';
559 $grade_item->itemtype = 'category';
560 $grade_item->itemmodule = 'quiz';
f3ac8eb4 561 $grade_item->iteminstance = $this->grade_categories[3]->id;
02e6a973 562 $grade_item->needsupdate = true;
563 $grade_item->gradetype = GRADE_TYPE_VALUE;
b8ff92b6 564 $grade_item->grademin = 0;
565 $grade_item->grademax = 100;
c3146da7 566 $grade_item->iteminfo = 'Orphan Grade item 9 used for unit testing';
02e6a973 567 $grade_item->timecreated = mktime();
568 $grade_item->timemodified = mktime();
569 $grade_item->sortorder = 8;
570
a9637e7d
PS
571 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
572 $this->grade_items[9] = $grade_item;
02e6a973 573
c3146da7 574 // Manual grade_item
f3ac8eb4 575 // id = 10
c3146da7 576 $grade_item = new stdClass();
577
578 $grade_item->courseid = $this->courseid;
579 $grade_item->categoryid = $course_category->id;
580 $grade_item->itemname = 'manual grade_item';
581 $grade_item->itemtype = 'manual';
582 $grade_item->itemnumber = 0;
583 $grade_item->needsupdate = false;
584 $grade_item->gradetype = GRADE_TYPE_VALUE;
585 $grade_item->grademin = 0;
586 $grade_item->grademax = 100;
587 $grade_item->iteminfo = 'Manual grade item 10 used for unit testing';
588 $grade_item->timecreated = mktime();
589 $grade_item->timemodified = mktime();
590
a9637e7d
PS
591 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
592 $this->grade_items[10] = $grade_item;
02e6a973 593 }
02e6a973 594
595 /**
ac9b0805 596 * Load grade_grades data into the database, and adds the corresponding objects to this class' variable.
02e6a973 597 */
ac9b0805 598 function load_grade_grades() {
da3801e8 599 global $DB;
c791bb4d
AD
600
601 //this method is called once for each test method. Avoid adding things to $this->grade_grades multiple times
602 $this->grade_grades = array();
a9637e7d 603
02e6a973 604 // Grades for grade_item 1
ac9b0805 605 $grade = new stdClass();
606 $grade->itemid = $this->grade_items[0]->id;
607 $grade->userid = 1;
608 $grade->rawgrade = 15; // too small
609 $grade->finalgrade = 30;
610 $grade->timecreated = mktime();
611 $grade->timemodified = mktime();
c791bb4d 612 $grade->information = '1 of 17 grade_grades';
3f2b0c8a 613 $grade->informationformat = FORMAT_PLAIN;
614 $grade->feedback = 'Good, but not good enough..';
615 $grade->feedbackformat = FORMAT_PLAIN;
ac9b0805 616
a9637e7d
PS
617 $grade->id = $DB->insert_record('grade_grades', $grade);
618 $this->grade_grades[0] = $grade;
772ddfbf 619
ac9b0805 620 $grade = new stdClass();
621 $grade->itemid = $this->grade_items[0]->id;
622 $grade->userid = 2;
623 $grade->rawgrade = 40;
624 $grade->finalgrade = 40;
625 $grade->timecreated = mktime();
626 $grade->timemodified = mktime();
c791bb4d 627 $grade->information = '2 of 17 grade_grades';
ac9b0805 628
a9637e7d
PS
629 $grade->id = $DB->insert_record('grade_grades', $grade);
630 $this->grade_grades[1] = $grade;
772ddfbf 631
ac9b0805 632 $grade = new stdClass();
633 $grade->itemid = $this->grade_items[0]->id;
634 $grade->userid = 3;
635 $grade->rawgrade = 170; // too big
636 $grade->finalgrade = 110;
637 $grade->timecreated = mktime();
638 $grade->timemodified = mktime();
c791bb4d 639 $grade->information = '3 of 17 grade_grades';
ac9b0805 640
a9637e7d
PS
641 $grade->id = $DB->insert_record('grade_grades', $grade);
642 $this->grade_grades[2] = $grade;
02e6a973 643
ac9b0805 644
b8ff92b6 645 // No raw grades for grade_item 2 - it is calculated
02e6a973 646
ac9b0805 647 $grade = new stdClass();
648 $grade->itemid = $this->grade_items[1]->id;
649 $grade->userid = 1;
8d9db9e5 650 $grade->finalgrade = 72;
ac9b0805 651 $grade->timecreated = mktime();
652 $grade->timemodified = mktime();
c791bb4d 653 $grade->information = '4 of 17 grade_grades';
ac9b0805 654
a9637e7d
PS
655 $grade->id = $DB->insert_record('grade_grades', $grade);
656 $this->grade_grades[3] = $grade;
772ddfbf 657
ac9b0805 658 $grade = new stdClass();
659 $grade->itemid = $this->grade_items[1]->id;
660 $grade->userid = 2;
8d9db9e5 661 $grade->finalgrade = 92;
ac9b0805 662 $grade->timecreated = mktime();
663 $grade->timemodified = mktime();
c791bb4d 664 $grade->information = '5 of 17 grade_grades';
ac9b0805 665
a9637e7d
PS
666 $grade->id = $DB->insert_record('grade_grades', $grade);
667 $this->grade_grades[4] = $grade;
ac9b0805 668
669 $grade = new stdClass();
670 $grade->itemid = $this->grade_items[1]->id;
671 $grade->userid = 3;
672 $grade->finalgrade = 100;
673 $grade->timecreated = mktime();
674 $grade->timemodified = mktime();
c791bb4d 675 $grade->information = '6 of 17 grade_grades';
ac9b0805 676
a9637e7d
PS
677 $grade->id = $DB->insert_record('grade_grades', $grade);
678 $this->grade_grades[5] = $grade;
ac9b0805 679
02e6a973 680
681 // Grades for grade_item 3
682
ac9b0805 683 $grade = new stdClass();
684 $grade->itemid = $this->grade_items[2]->id;
685 $grade->userid = 1;
686 $grade->rawgrade = 2;
687 $grade->finalgrade = 6;
688 $grade->scaleid = $this->scale[3]->id;
689 $grade->timecreated = mktime();
690 $grade->timemodified = mktime();
c791bb4d 691 $grade->information = '7 of 17 grade_grades';
02e6a973 692
a9637e7d
PS
693 $grade->id = $DB->insert_record('grade_grades', $grade);
694 $this->grade_grades[6] = $grade;
772ddfbf 695
ac9b0805 696 $grade = new stdClass();
697 $grade->itemid = $this->grade_items[2]->id;
698 $grade->userid = 2;
699 $grade->rawgrade = 3;
700 $grade->finalgrade = 2;
701 $grade->scaleid = $this->scale[3]->id;
702 $grade->timecreated = mktime();
703 $grade->timemodified = mktime();
c791bb4d 704 $grade->information = '8 of 17 grade_grades';
ac9b0805 705
a9637e7d
PS
706 $grade->id = $DB->insert_record('grade_grades', $grade);
707 $this->grade_grades[] = $grade;
772ddfbf 708
ac9b0805 709 $grade = new stdClass();
710 $grade->itemid = $this->grade_items[2]->id;
711 $grade->userid = 3;
712 $grade->rawgrade = 1;
713 $grade->finalgrade = 3;
714 $grade->scaleid = $this->scale[3]->id;
715 $grade->timecreated = mktime();
716 $grade->timemodified = mktime();
c791bb4d 717 $grade->information = '9 of 17 grade_grades';
ac9b0805 718
a9637e7d
PS
719 $grade->id = $DB->insert_record('grade_grades', $grade);
720 $this->grade_grades[] = $grade;
772ddfbf 721
02e6a973 722 // Grades for grade_item 7
723
ac9b0805 724 $grade = new stdClass();
725 $grade->itemid = $this->grade_items[6]->id;
726 $grade->userid = 1;
727 $grade->rawgrade = 97;
728 $grade->finalgrade = 69;
729 $grade->timecreated = mktime();
730 $grade->timemodified = mktime();
c791bb4d 731 $grade->information = '10 of 17 grade_grades';
02e6a973 732
a9637e7d
PS
733 $grade->id = $DB->insert_record('grade_grades', $grade);
734 $this->grade_grades[] = $grade;
772ddfbf 735
ac9b0805 736 $grade = new stdClass();
737 $grade->itemid = $this->grade_items[6]->id;
738 $grade->userid = 2;
739 $grade->rawgrade = 49;
740 $grade->finalgrade = 87;
741 $grade->timecreated = mktime();
742 $grade->timemodified = mktime();
c791bb4d 743 $grade->information = '11 of 17 grade_grades';
ac9b0805 744
a9637e7d
PS
745 $grade->id = $DB->insert_record('grade_grades', $grade);
746 $this->grade_grades[] = $grade;
772ddfbf 747
ac9b0805 748 $grade = new stdClass();
749 $grade->itemid = $this->grade_items[6]->id;
750 $grade->userid = 3;
751 $grade->rawgrade = 67;
752 $grade->finalgrade = 94;
753 $grade->timecreated = mktime();
754 $grade->timemodified = mktime();
c791bb4d 755 $grade->information = '12 of 17 grade_grades';
ac9b0805 756
a9637e7d
PS
757 $grade->id = $DB->insert_record('grade_grades', $grade);
758 $this->grade_grades[] = $grade;
02e6a973 759
760 // Grades for grade_item 8
761
ac9b0805 762 $grade = new stdClass();
763 $grade->itemid = $this->grade_items[7]->id;
764 $grade->userid = 2;
765 $grade->rawgrade = 3;
766 $grade->finalgrade = 3;
767 $grade->timecreated = mktime();
768 $grade->timemodified = mktime();
c791bb4d 769 $grade->information = '13 of 17 grade_grades';
02e6a973 770
a9637e7d
PS
771 $grade->id = $DB->insert_record('grade_grades', $grade);
772 $this->grade_grades[] = $grade;
772ddfbf 773
ac9b0805 774 $grade = new stdClass();
775 $grade->itemid = $this->grade_items[7]->id;
776 $grade->userid = 3;
777 $grade->rawgrade = 6;
778 $grade->finalgrade = 6;
779 $grade->timecreated = mktime();
780 $grade->timemodified = mktime();
c791bb4d 781 $grade->information = '14 of 17 grade_grades';
ac9b0805 782
a9637e7d
PS
783 $grade->id = $DB->insert_record('grade_grades', $grade);
784 $this->grade_grades[] = $grade;
772ddfbf 785
02e6a973 786 // Grades for grade_item 9
787
ac9b0805 788 $grade = new stdClass();
789 $grade->itemid = $this->grade_items[8]->id;
790 $grade->userid = 1;
791 $grade->rawgrade = 20;
792 $grade->finalgrade = 20;
793 $grade->timecreated = mktime();
794 $grade->timemodified = mktime();
c791bb4d 795 $grade->information = '15 of 17 grade_grades';
02e6a973 796
a9637e7d
PS
797 $grade->id = $DB->insert_record('grade_grades', $grade);
798 $this->grade_grades[] = $grade;
772ddfbf 799
ac9b0805 800 $grade = new stdClass();
801 $grade->itemid = $this->grade_items[8]->id;
802 $grade->userid = 2;
803 $grade->rawgrade = 50;
804 $grade->finalgrade = 50;
805 $grade->timecreated = mktime();
806 $grade->timemodified = mktime();
c791bb4d 807 $grade->information = '16 of 17 grade_grades';
02e6a973 808
a9637e7d
PS
809 $grade->id = $DB->insert_record('grade_grades', $grade);
810 $this->grade_grades[] = $grade;
772ddfbf 811
ac9b0805 812 $grade = new stdClass();
c7d306e1 813 $grade->itemid = $this->grade_items[8]->id;
ac9b0805 814 $grade->userid = 3;
815 $grade->rawgrade = 100;
816 $grade->finalgrade = 100;
817 $grade->timecreated = mktime();
818 $grade->timemodified = mktime();
c791bb4d 819 $grade->information = '17 of 17 grade_grades';
02e6a973 820
a9637e7d
PS
821 $grade->id = $DB->insert_record('grade_grades', $grade);
822 $this->grade_grades[] = $grade;
02e6a973 823 }
772ddfbf 824
02e6a973 825 /**
826 * Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
827 */
828 function load_grade_outcomes() {
da3801e8 829 global $DB;
c791bb4d
AD
830
831 //this method is called once for each test method. Avoid adding things to $this->grade_outcomes multiple times
832 $this->grade_outcomes = array();
833
02e6a973 834 // Calculation for grade_item 1
835 $grade_outcome = new stdClass();
5bbb6fed 836 $grade_outcome->fullname = 'Team work';
02e6a973 837 $grade_outcome->shortname = 'Team work';
27c9bf24 838 $grade_outcome->fullname = 'Team work outcome';
02e6a973 839 $grade_outcome->timecreated = mktime();
840 $grade_outcome->timemodified = mktime();
841 $grade_outcome->scaleid = $this->scale[2]->id;
772ddfbf 842
a9637e7d
PS
843 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
844 $this->grade_outcomes[] = $grade_outcome;
772ddfbf 845
02e6a973 846 // Calculation for grade_item 2
847 $grade_outcome = new stdClass();
5bbb6fed 848 $grade_outcome->fullname = 'Complete circuit board';
02e6a973 849 $grade_outcome->shortname = 'Complete circuit board';
27c9bf24 850 $grade_outcome->fullname = 'Complete circuit board';
02e6a973 851 $grade_outcome->timecreated = mktime();
852 $grade_outcome->timemodified = mktime();
853 $grade_outcome->scaleid = $this->scale[3]->id;
772ddfbf 854
a9637e7d
PS
855 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
856 $this->grade_outcomes[] = $grade_outcome;
772ddfbf 857
02e6a973 858 // Calculation for grade_item 3
859 $grade_outcome = new stdClass();
5bbb6fed 860 $grade_outcome->fullname = 'Debug Java program';
02e6a973 861 $grade_outcome->shortname = 'Debug Java program';
27c9bf24 862 $grade_outcome->fullname = 'Debug Java program';
02e6a973 863 $grade_outcome->timecreated = mktime();
864 $grade_outcome->timemodified = mktime();
865 $grade_outcome->scaleid = $this->scale[4]->id;
772ddfbf 866
a9637e7d
PS
867 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
868 $this->grade_outcomes[] = $grade_outcome;
02e6a973 869 }
870
772ddfbf 871/**
02e6a973 872 * No unit tests here
873 */
874
875}
876
8926f844 877