MDL-32323 add grade tests
[moodle.git] / lib / grade / tests / fixtures / lib.php
CommitLineData
948d46da
PS
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
17/**
18 * @package core_grades
19 * @category phpunit
20 * @copyright nicolas@moodle.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24defined('MOODLE_INTERNAL') || die();
25
26global $CFG;
27require_once($CFG->libdir . '/adminlib.php');
28require_once($CFG->libdir . '/gradelib.php');
29
30
31/**
32 * Shared code for all grade related tests.
33 *
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 */
38class grade_base_testcase extends advanced_testcase {
39
40 protected $course;
41 protected $activities = array();
42 protected $grade_items = array();
43 protected $grade_categories = array();
44 protected $grade_grades = array();
45 protected $grade_outcomes = array();
46 protected $scale = array();
47 protected $scalemax = array();
48
49 protected $courseid;
50 protected $userid;
51
52 protected function setUp() {
53 global $CFG;
54 parent::setup();
55
56 $this->resetAfterTest(true);
57
58 $CFG->grade_droplow = -1;
59 $CFG->grade_keephigh = -1;
60 $CFG->grade_aggregation = -1;
61 $CFG->grade_aggregateonlygraded = -1;
62 $CFG->grade_aggregateoutcomes = -1;
63 $CFG->grade_aggregatesubcats = -1;
64
65 $this->course = $this->getDataGenerator()->create_course();
66 $this->courseid = $this->course->id;
67
68 $this->user[0] = $this->getDataGenerator()->create_user();
69 $this->user[1] = $this->getDataGenerator()->create_user();
70 $this->user[2] = $this->getDataGenerator()->create_user();
71 $this->user[3] = $this->getDataGenerator()->create_user();
72 $this->userid = $this->user[0]->id;
73
74 $this->load_modules();
75
76 $this->load_scales();
77 $this->load_grade_categories();
78 $this->load_grade_items();
79 $this->load_grade_grades();
80 $this->load_grade_outcomes();
81 }
82
83 public function test_void () {
84 // empty method to keep PHPUnit happy
85 }
86
87 private function load_modules() {
88 $this->activities[0] = $this->getDataGenerator()->create_module('assignment', array('course'=>$this->course->id));
89 $this->course_module[0] = get_coursemodule_from_instance('assignment', $this->activities[0]->id);
90
91 $this->activities[1] = $this->getDataGenerator()->create_module('assignment', array('course'=>$this->course->id));
92 $this->course_module[1] = get_coursemodule_from_instance('assignment', $this->activities[1]->id);
93
94 $this->activities[2] = $this->getDataGenerator()->create_module('forum', array('course'=>$this->course->id));
95 $this->course_module[2] = get_coursemodule_from_instance('forum', $this->activities[2]->id);
96
97 $this->activities[3] = $this->getDataGenerator()->create_module('page', array('course'=>$this->course->id));
98 $this->course_module[3] = get_coursemodule_from_instance('page', $this->activities[3]->id);
99
100 $this->activities[4] = $this->getDataGenerator()->create_module('forum', array('course'=>$this->course->id));
101 $this->course_module[4] = get_coursemodule_from_instance('forum', $this->activities[4]->id);
102
103 $this->activities[5] = $this->getDataGenerator()->create_module('forum', array('course'=>$this->course->id));
104 $this->course_module[5] = get_coursemodule_from_instance('forum', $this->activities[5]->id);
105
106 $this->activities[6] = $this->getDataGenerator()->create_module('forum', array('course'=>$this->course->id));
107 $this->course_module[6] = get_coursemodule_from_instance('forum', $this->activities[6]->id);
108 }
109
110 private function load_scales() {
111 $scale = new stdClass();
112 $scale->name = 'unittestscale1';
113 $scale->courseid = $this->course->id;
114 $scale->userid = $this->user[0]->id;
115 $scale->scale = 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
116 $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.';
117
118 $this->scale[0] = $this->getDataGenerator()->create_scale($scale);
119 $this->scalemax[0] = substr_count($scale->scale, ',');
120
121 $scale = new stdClass();
122 $scale->name = 'unittestscale2';
123 $scale->courseid = $this->course->id;
124 $scale->userid = $this->user[0]->id;
125 $scale->scale = 'Distinction, Very Good, Good, Pass, Fail';
126 $scale->description = 'This scale is used to mark standard assignments.';
127
128 $this->scale[1] = $this->getDataGenerator()->create_scale($scale);
129 $this->scalemax[1] = substr_count($scale->scale, ',');
130
131 $scale = new stdClass();
132 $scale->name = 'unittestscale3';
133 $scale->courseid = $this->course->id;
134 $scale->userid = $this->user[0]->id;
135 $scale->scale = 'Loner, Contentious, Disinterested, Participative, Follower, Leader';
136 $scale->description = 'Describes the level of teamwork of a student.';
137 $temp = explode(',', $scale->scale);
138 $scale->max = count($temp) -1;
139
140 $this->scale[2] = $this->getDataGenerator()->create_scale($scale);
141 $this->scalemax[2] = substr_count($scale->scale, ',');
142
143 $scale = new stdClass();
144 $scale->name = 'unittestscale4';
145 $scale->courseid = $this->course->id;
146 $scale->userid = $this->user[0]->id;
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 $temp = explode(',', $scale->scale);
150 $scale->max = count($temp) -1;
151
152 $this->scale[3] = $this->getDataGenerator()->create_scale($scale);
153 $this->scalemax[3] = substr_count($scale->scale, ',');
154
155 $scale = new stdClass();
156 $scale->name = 'unittestscale5';
157 $scale->courseid = $this->course->id;
158 $scale->userid = $this->user[0]->id;
159 $scale->scale = 'Insufficient, Acceptable, Excellent.';
160 $scale->description = 'Description of skills.';
161
162 $this->scale[4] = $this->getDataGenerator()->create_scale($scale);
163 $this->scalemax[4] = substr_count($scale->scale, ',');
164 }
165
166 /**
167 * Load grade_category data into the database, and adds the corresponding objects to this class' variable.
168 * category structure:
169 course category
170 |
171 +--------+-------------+
172 | |
173 unittestcategory1 level1category
174 |
175 +--------+-------------+
176 | |
177 unittestcategory2 unittestcategory3
178 */
179 private function load_grade_categories() {
180 global $DB;
181
182 $course_category = grade_category::fetch_course_category($this->course->id);
183
184 $grade_category = new stdClass();
185
186 $grade_category->fullname = 'unittestcategory1';
187 $grade_category->courseid = $this->course->id;
188 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
189 $grade_category->aggregateonlygraded = 1;
190 $grade_category->keephigh = 0;
191 $grade_category->droplow = 0;
192 $grade_category->parent = $course_category->id;
193 $grade_category->timecreated = time();
194 $grade_category->timemodified = time();
195 $grade_category->depth = 2;
196
197 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
198 $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
199 $DB->update_record('grade_categories', $grade_category);
200 $this->grade_categories[0] = $grade_category;
201
202 $grade_category = new stdClass();
203
204 $grade_category->fullname = 'unittestcategory2';
205 $grade_category->courseid = $this->course->id;
206 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
207 $grade_category->aggregateonlygraded = 1;
208 $grade_category->keephigh = 0;
209 $grade_category->droplow = 0;
210 $grade_category->parent = $this->grade_categories[0]->id;
211 $grade_category->timecreated = time();
212 $grade_category->timemodified = time();
213 $grade_category->depth = 3;
214
215 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
216 $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
217 $DB->update_record('grade_categories', $grade_category);
218 $this->grade_categories[1] = $grade_category;
219
220 $grade_category = new stdClass();
221
222 $grade_category->fullname = 'unittestcategory3';
223 $grade_category->courseid = $this->course->id;
224 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
225 $grade_category->aggregateonlygraded = 1;
226 $grade_category->keephigh = 0;
227 $grade_category->droplow = 0;
228 $grade_category->parent = $this->grade_categories[0]->id;
229 $grade_category->timecreated = time();
230 $grade_category->timemodified = time();
231 $grade_category->depth = 3;
232
233 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
234 $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
235 $DB->update_record('grade_categories', $grade_category);
236 $this->grade_categories[2] = $grade_category;
237
238 // A category with no parent, but grade_items as children
239
240 $grade_category = new stdClass();
241
242 $grade_category->fullname = 'level1category';
243 $grade_category->courseid = $this->course->id;
244 $grade_category->aggregation = GRADE_AGGREGATE_MEAN;
245 $grade_category->aggregateonlygraded = 1;
246 $grade_category->keephigh = 0;
247 $grade_category->droplow = 0;
248 $grade_category->parent = $course_category->id;
249 $grade_category->timecreated = time();
250 $grade_category->timemodified = time();
251 $grade_category->depth = 2;
252
253 $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
254 $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
255 $DB->update_record('grade_categories', $grade_category);
256 $this->grade_categories[3] = $grade_category;
257 }
258
259 /**
260 * Load grade_item data into the database, and adds the corresponding objects to this class' variable.
261 */
262 protected function load_grade_items() {
263 global $DB;
264
265 $course_category = grade_category::fetch_course_category($this->course->id);
266
267 // id = 0
268 $grade_item = new stdClass();
269
270 $grade_item->courseid = $this->course->id;
271 $grade_item->categoryid = $this->grade_categories[1]->id;
272 $grade_item->itemname = 'unittestgradeitem1';
273 $grade_item->itemtype = 'mod';
274 $grade_item->itemmodule = $this->course_module[0]->modname;
275 $grade_item->iteminstance = $this->course_module[0]->instance;
276 $grade_item->gradetype = GRADE_TYPE_VALUE;
277 $grade_item->grademin = 30;
278 $grade_item->grademax = 110;
279 $grade_item->itemnumber = 1;
280 $grade_item->idnumber = 'item id 0';
281 $grade_item->iteminfo = 'Grade item 0 used for unit testing';
282 $grade_item->timecreated = time();
283 $grade_item->timemodified = time();
284 $grade_item->sortorder = 3;
285
286 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
287 $this->grade_items[0] = $grade_item;
288
289 // id = 1
290 $grade_item = new stdClass();
291
292 $grade_item->courseid = $this->course->id;
293 $grade_item->categoryid = $this->grade_categories[1]->id;
294 $grade_item->itemname = 'unittestgradeitem2';
295 $grade_item->itemtype = 'import';
296 $grade_item->itemmodule = $this->course_module[1]->modname;
297 $grade_item->iteminstance = $this->course_module[1]->instance;
298 $grade_item->calculation = '= ##gi'.$this->grade_items[0]->id.'## + 30 + [[item id 0]] - [[item id 0]]';
299 $grade_item->gradetype = GRADE_TYPE_VALUE;
300 $grade_item->itemnumber = null;
301 $grade_item->grademin = 0;
302 $grade_item->grademax = 100;
303 $grade_item->iteminfo = 'Grade item 1 used for unit testing';
304 $grade_item->timecreated = time();
305 $grade_item->timemodified = time();
306 $grade_item->sortorder = 4;
307
308 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
309 $this->grade_items[1] = $grade_item;
310
311 // id = 2
312 $grade_item = new stdClass();
313
314 $grade_item->courseid = $this->course->id;
315 $grade_item->categoryid = $this->grade_categories[2]->id;
316 $grade_item->itemname = 'unittestgradeitem3';
317 $grade_item->itemtype = 'mod';
318 $grade_item->itemmodule = $this->course_module[2]->modname;
319 $grade_item->iteminstance = $this->course_module[2]->instance;
320 $grade_item->gradetype = GRADE_TYPE_SCALE;
321 $grade_item->scaleid = $this->scale[0]->id;
322 $grade_item->grademin = 0;
323 $grade_item->grademax = $this->scalemax[0];
324 $grade_item->iteminfo = 'Grade item 2 used for unit testing';
325 $grade_item->timecreated = time();
326 $grade_item->timemodified = time();
327 $grade_item->sortorder = 6;
328
329 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
330 $this->grade_items[2] = $grade_item;
331
332 // Load grade_items associated with the 3 categories
333 // id = 3
334 $grade_item = new stdClass();
335
336 $grade_item->courseid = $this->course->id;
337 $grade_item->iteminstance = $this->grade_categories[0]->id;
338 $grade_item->itemname = 'unittestgradeitemcategory1';
339 $grade_item->needsupdate = 0;
340 $grade_item->itemtype = 'category';
341 $grade_item->gradetype = GRADE_TYPE_VALUE;
342 $grade_item->grademin = 0;
343 $grade_item->grademax = 100;
344 $grade_item->iteminfo = 'Grade item 3 used for unit testing';
345 $grade_item->timecreated = time();
346 $grade_item->timemodified = time();
347 $grade_item->sortorder = 1;
348
349 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
350 $this->grade_items[3] = $grade_item;
351
352 // id = 4
353 $grade_item = new stdClass();
354
355 $grade_item->courseid = $this->course->id;
356 $grade_item->iteminstance = $this->grade_categories[1]->id;
357 $grade_item->itemname = 'unittestgradeitemcategory2';
358 $grade_item->itemtype = 'category';
359 $grade_item->gradetype = GRADE_TYPE_VALUE;
360 $grade_item->needsupdate = 0;
361 $grade_item->grademin = 0;
362 $grade_item->grademax = 100;
363 $grade_item->iteminfo = 'Grade item 4 used for unit testing';
364 $grade_item->timecreated = time();
365 $grade_item->timemodified = time();
366 $grade_item->sortorder = 2;
367
368 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
369 $this->grade_items[4] = $grade_item;
370
371 // id = 5
372 $grade_item = new stdClass();
373
374 $grade_item->courseid = $this->course->id;
375 $grade_item->iteminstance = $this->grade_categories[2]->id;
376 $grade_item->itemname = 'unittestgradeitemcategory3';
377 $grade_item->itemtype = 'category';
378 $grade_item->gradetype = GRADE_TYPE_VALUE;
379 $grade_item->needsupdate = true;
380 $grade_item->grademin = 0;
381 $grade_item->grademax = 100;
382 $grade_item->iteminfo = 'Grade item 5 used for unit testing';
383 $grade_item->timecreated = time();
384 $grade_item->timemodified = time();
385 $grade_item->sortorder = 5;
386
387 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
388 $this->grade_items[5] = $grade_item;
389
390 // Orphan grade_item
391 // id = 6
392 $grade_item = new stdClass();
393
394 $grade_item->courseid = $this->course->id;
395 $grade_item->categoryid = $course_category->id;
396 $grade_item->itemname = 'unittestorphangradeitem1';
397 $grade_item->itemtype = 'mod';
398 $grade_item->itemmodule = $this->course_module[4]->modname;
399 $grade_item->iteminstance = $this->course_module[4]->instance;
400 $grade_item->itemnumber = 0;
401 $grade_item->gradetype = GRADE_TYPE_VALUE;
402 $grade_item->grademin = 10;
403 $grade_item->grademax = 120;
404 $grade_item->locked = time();
405 $grade_item->iteminfo = 'Orphan Grade 6 item used for unit testing';
406 $grade_item->timecreated = time();
407 $grade_item->timemodified = time();
408 $grade_item->sortorder = 7;
409
410 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
411 $this->grade_items[6] = $grade_item;
412
413 // 2 grade items under level1category
414 // id = 7
415 $grade_item = new stdClass();
416
417 $grade_item->courseid = $this->course->id;
418 $grade_item->categoryid = $this->grade_categories[3]->id;
419 $grade_item->itemname = 'singleparentitem1';
420 $grade_item->itemtype = 'mod';
421 $grade_item->itemmodule = $this->course_module[5]->modname;
422 $grade_item->iteminstance = $this->course_module[5]->instance;
423 $grade_item->gradetype = GRADE_TYPE_SCALE;
424 $grade_item->scaleid = $this->scale[0]->id;
425 $grade_item->grademin = 0;
426 $grade_item->grademax = $this->scalemax[0];
427 $grade_item->iteminfo = 'Grade item 7 used for unit testing';
428 $grade_item->timecreated = time();
429 $grade_item->timemodified = time();
430 $grade_item->sortorder = 9;
431
432 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
433 $this->grade_items[7] = $grade_item;
434
435 // id = 8
436 $grade_item = new stdClass();
437
438 $grade_item->courseid = $this->course->id;
439 $grade_item->categoryid = $this->grade_categories[3]->id;
440 $grade_item->itemname = 'singleparentitem2';
441 $grade_item->itemtype = 'mod';
442 $grade_item->itemmodule = $this->course_module[6]->modname;
443 $grade_item->iteminstance = $this->course_module[6]->instance;
444 $grade_item->gradetype = GRADE_TYPE_VALUE;
445 $grade_item->grademin = 0;
446 $grade_item->grademax = 100;
447 $grade_item->iteminfo = 'Grade item 8 used for unit testing';
448 $grade_item->timecreated = time();
449 $grade_item->timemodified = time();
450 $grade_item->sortorder = 10;
451
452 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
453 $this->grade_items[8] = $grade_item;
454
455 // Grade_item for level1category
456 // id = 9
457 $grade_item = new stdClass();
458
459 $grade_item->courseid = $this->course->id;
460 $grade_item->itemname = 'grade_item for level1 category';
461 $grade_item->itemtype = 'category';
462 $grade_item->iteminstance = $this->grade_categories[3]->id;
463 $grade_item->needsupdate = true;
464 $grade_item->gradetype = GRADE_TYPE_VALUE;
465 $grade_item->grademin = 0;
466 $grade_item->grademax = 100;
467 $grade_item->iteminfo = 'Orphan Grade item 9 used for unit testing';
468 $grade_item->timecreated = time();
469 $grade_item->timemodified = time();
470 $grade_item->sortorder = 8;
471
472 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
473 $this->grade_items[9] = $grade_item;
474
475 // Manual grade_item
476 // id = 10
477 $grade_item = new stdClass();
478
479 $grade_item->courseid = $this->course->id;
480 $grade_item->categoryid = $course_category->id;
481 $grade_item->itemname = 'manual grade_item';
482 $grade_item->itemtype = 'manual';
483 $grade_item->itemnumber = 0;
484 $grade_item->needsupdate = false;
485 $grade_item->gradetype = GRADE_TYPE_VALUE;
486 $grade_item->grademin = 0;
487 $grade_item->grademax = 100;
488 $grade_item->iteminfo = 'Manual grade item 10 used for unit testing';
489 $grade_item->timecreated = time();
490 $grade_item->timemodified = time();
491
492 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
493 $this->grade_items[10] = $grade_item;
494 }
495
496 /**
497 * Load grade_grades data into the database, and adds the corresponding objects to this class' variable.
498 */
499 private function load_grade_grades() {
500 global $DB;
501
502 //this method is called once for each test method. Avoid adding things to $this->grade_grades multiple times
503 $this->grade_grades = array();
504
505 // Grades for grade_item 1
506 $grade = new stdClass();
507 $grade->itemid = $this->grade_items[0]->id;
508 $grade->userid = $this->user[1]->id;
509 $grade->rawgrade = 15; // too small
510 $grade->finalgrade = 30;
511 $grade->timecreated = time();
512 $grade->timemodified = time();
513 $grade->information = '1 of 17 grade_grades';
514 $grade->informationformat = FORMAT_PLAIN;
515 $grade->feedback = 'Good, but not good enough..';
516 $grade->feedbackformat = FORMAT_PLAIN;
517
518 $grade->id = $DB->insert_record('grade_grades', $grade);
519 $this->grade_grades[0] = $grade;
520
521 $grade = new stdClass();
522 $grade->itemid = $this->grade_items[0]->id;
523 $grade->userid = $this->user[2]->id;
524 $grade->rawgrade = 40;
525 $grade->finalgrade = 40;
526 $grade->timecreated = time();
527 $grade->timemodified = time();
528 $grade->information = '2 of 17 grade_grades';
529
530 $grade->id = $DB->insert_record('grade_grades', $grade);
531 $this->grade_grades[1] = $grade;
532
533 $grade = new stdClass();
534 $grade->itemid = $this->grade_items[0]->id;
535 $grade->userid = $this->user[3]->id;
536 $grade->rawgrade = 170; // too big
537 $grade->finalgrade = 110;
538 $grade->timecreated = time();
539 $grade->timemodified = time();
540 $grade->information = '3 of 17 grade_grades';
541
542 $grade->id = $DB->insert_record('grade_grades', $grade);
543 $this->grade_grades[2] = $grade;
544
545
546 // No raw grades for grade_item 2 - it is calculated
547
548 $grade = new stdClass();
549 $grade->itemid = $this->grade_items[1]->id;
550 $grade->userid = $this->user[1]->id;
551 $grade->finalgrade = 60;
552 $grade->timecreated = time();
553 $grade->timemodified = time();
554 $grade->information = '4 of 17 grade_grades';
555
556 $grade->id = $DB->insert_record('grade_grades', $grade);
557 $this->grade_grades[3] = $grade;
558
559 $grade = new stdClass();
560 $grade->itemid = $this->grade_items[1]->id;
561 $grade->userid = $this->user[2]->id;
562 $grade->finalgrade = 70;
563 $grade->timecreated = time();
564 $grade->timemodified = time();
565 $grade->information = '5 of 17 grade_grades';
566
567 $grade->id = $DB->insert_record('grade_grades', $grade);
568 $this->grade_grades[4] = $grade;
569
570 $grade = new stdClass();
571 $grade->itemid = $this->grade_items[1]->id;
572 $grade->userid = $this->user[3]->id;
573 $grade->finalgrade = 100;
574 $grade->timecreated = time();
575 $grade->timemodified = time();
576 $grade->information = '6 of 17 grade_grades';
577
578 $grade->id = $DB->insert_record('grade_grades', $grade);
579 $this->grade_grades[5] = $grade;
580
581
582 // Grades for grade_item 3
583
584 $grade = new stdClass();
585 $grade->itemid = $this->grade_items[2]->id;
586 $grade->userid = $this->user[1]->id;
587 $grade->rawgrade = 2;
588 $grade->finalgrade = 6;
589 $grade->scaleid = $this->scale[3]->id;
590 $grade->timecreated = time();
591 $grade->timemodified = time();
592 $grade->information = '7 of 17 grade_grades';
593
594 $grade->id = $DB->insert_record('grade_grades', $grade);
595 $this->grade_grades[6] = $grade;
596
597 $grade = new stdClass();
598 $grade->itemid = $this->grade_items[2]->id;
599 $grade->userid = $this->user[2]->id;
600 $grade->rawgrade = 3;
601 $grade->finalgrade = 2;
602 $grade->scaleid = $this->scale[3]->id;
603 $grade->timecreated = time();
604 $grade->timemodified = time();
605 $grade->information = '8 of 17 grade_grades';
606
607 $grade->id = $DB->insert_record('grade_grades', $grade);
608 $this->grade_grades[] = $grade;
609
610 $grade = new stdClass();
611 $grade->itemid = $this->grade_items[2]->id;
612 $grade->userid = $this->user[3]->id;
613 $grade->rawgrade = 1;
614 $grade->finalgrade = 3;
615 $grade->scaleid = $this->scale[3]->id;
616 $grade->timecreated = time();
617 $grade->timemodified = time();
618 $grade->information = '9 of 17 grade_grades';
619
620 $grade->id = $DB->insert_record('grade_grades', $grade);
621 $this->grade_grades[] = $grade;
622
623 // Grades for grade_item 7
624
625 $grade = new stdClass();
626 $grade->itemid = $this->grade_items[6]->id;
627 $grade->userid = $this->user[1]->id;
628 $grade->rawgrade = 97;
629 $grade->finalgrade = 69;
630 $grade->timecreated = time();
631 $grade->timemodified = time();
632 $grade->information = '10 of 17 grade_grades';
633
634 $grade->id = $DB->insert_record('grade_grades', $grade);
635 $this->grade_grades[] = $grade;
636
637 $grade = new stdClass();
638 $grade->itemid = $this->grade_items[6]->id;
639 $grade->userid = $this->user[2]->id;
640 $grade->rawgrade = 49;
641 $grade->finalgrade = 87;
642 $grade->timecreated = time();
643 $grade->timemodified = time();
644 $grade->information = '11 of 17 grade_grades';
645
646 $grade->id = $DB->insert_record('grade_grades', $grade);
647 $this->grade_grades[] = $grade;
648
649 $grade = new stdClass();
650 $grade->itemid = $this->grade_items[6]->id;
651 $grade->userid = $this->user[3]->id;
652 $grade->rawgrade = 67;
653 $grade->finalgrade = 94;
654 $grade->timecreated = time();
655 $grade->timemodified = time();
656 $grade->information = '12 of 17 grade_grades';
657
658 $grade->id = $DB->insert_record('grade_grades', $grade);
659 $this->grade_grades[] = $grade;
660
661 // Grades for grade_item 8
662
663 $grade = new stdClass();
664 $grade->itemid = $this->grade_items[7]->id;
665 $grade->userid = $this->user[2]->id;
666 $grade->rawgrade = 3;
667 $grade->finalgrade = 3;
668 $grade->timecreated = time();
669 $grade->timemodified = time();
670 $grade->information = '13 of 17 grade_grades';
671
672 $grade->id = $DB->insert_record('grade_grades', $grade);
673 $this->grade_grades[] = $grade;
674
675 $grade = new stdClass();
676 $grade->itemid = $this->grade_items[7]->id;
677 $grade->userid = $this->user[3]->id;
678 $grade->rawgrade = 6;
679 $grade->finalgrade = 6;
680 $grade->timecreated = time();
681 $grade->timemodified = time();
682 $grade->information = '14 of 17 grade_grades';
683
684 $grade->id = $DB->insert_record('grade_grades', $grade);
685 $this->grade_grades[] = $grade;
686
687 // Grades for grade_item 9
688
689 $grade = new stdClass();
690 $grade->itemid = $this->grade_items[8]->id;
691 $grade->userid = $this->user[1]->id;
692 $grade->rawgrade = 20;
693 $grade->finalgrade = 20;
694 $grade->timecreated = time();
695 $grade->timemodified = time();
696 $grade->information = '15 of 17 grade_grades';
697
698 $grade->id = $DB->insert_record('grade_grades', $grade);
699 $this->grade_grades[] = $grade;
700
701 $grade = new stdClass();
702 $grade->itemid = $this->grade_items[8]->id;
703 $grade->userid = $this->user[2]->id;
704 $grade->rawgrade = 50;
705 $grade->finalgrade = 50;
706 $grade->timecreated = time();
707 $grade->timemodified = time();
708 $grade->information = '16 of 17 grade_grades';
709
710 $grade->id = $DB->insert_record('grade_grades', $grade);
711 $this->grade_grades[] = $grade;
712
713 $grade = new stdClass();
714 $grade->itemid = $this->grade_items[8]->id;
715 $grade->userid = $this->user[3]->id;
716 $grade->rawgrade = 100;
717 $grade->finalgrade = 100;
718 $grade->timecreated = time();
719 $grade->timemodified = time();
720 $grade->information = '17 of 17 grade_grades';
721
722 $grade->id = $DB->insert_record('grade_grades', $grade);
723 $this->grade_grades[] = $grade;
724 }
725
726 /**
727 * Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
728 */
729 private function load_grade_outcomes() {
730 global $DB;
731
732 //this method is called once for each test method. Avoid adding things to $this->grade_outcomes multiple times
733 $this->grade_outcomes = array();
734
735 // Calculation for grade_item 1
736 $grade_outcome = new stdClass();
737 $grade_outcome->fullname = 'Team work';
738 $grade_outcome->shortname = 'Team work';
739 $grade_outcome->fullname = 'Team work outcome';
740 $grade_outcome->timecreated = time();
741 $grade_outcome->timemodified = time();
742 $grade_outcome->scaleid = $this->scale[2]->id;
743
744 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
745 $this->grade_outcomes[] = $grade_outcome;
746
747 // Calculation for grade_item 2
748 $grade_outcome = new stdClass();
749 $grade_outcome->fullname = 'Complete circuit board';
750 $grade_outcome->shortname = 'Complete circuit board';
751 $grade_outcome->fullname = 'Complete circuit board';
752 $grade_outcome->timecreated = time();
753 $grade_outcome->timemodified = time();
754 $grade_outcome->scaleid = $this->scale[3]->id;
755
756 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
757 $this->grade_outcomes[] = $grade_outcome;
758
759 // Calculation for grade_item 3
760 $grade_outcome = new stdClass();
761 $grade_outcome->fullname = 'Debug Java program';
762 $grade_outcome->shortname = 'Debug Java program';
763 $grade_outcome->fullname = 'Debug Java program';
764 $grade_outcome->timecreated = time();
765 $grade_outcome->timemodified = time();
766 $grade_outcome->scaleid = $this->scale[4]->id;
767
768 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
769 $this->grade_outcomes[] = $grade_outcome;
770 }
771}
772
773