MDL-37952 make helper descendants abstract
[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 */
1a3487fc 38abstract class grade_base_testcase extends advanced_testcase {
948d46da
PS
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
6b04fdc0
PS
265 // purge all items created by module generators
266 $DB->delete_records('grade_items', array('itemtype'=>'mod'));
267
948d46da
PS
268 $course_category = grade_category::fetch_course_category($this->course->id);
269
270 // id = 0
271 $grade_item = new stdClass();
272
273 $grade_item->courseid = $this->course->id;
274 $grade_item->categoryid = $this->grade_categories[1]->id;
275 $grade_item->itemname = 'unittestgradeitem1';
276 $grade_item->itemtype = 'mod';
277 $grade_item->itemmodule = $this->course_module[0]->modname;
278 $grade_item->iteminstance = $this->course_module[0]->instance;
279 $grade_item->gradetype = GRADE_TYPE_VALUE;
280 $grade_item->grademin = 30;
281 $grade_item->grademax = 110;
282 $grade_item->itemnumber = 1;
283 $grade_item->idnumber = 'item id 0';
284 $grade_item->iteminfo = 'Grade item 0 used for unit testing';
285 $grade_item->timecreated = time();
286 $grade_item->timemodified = time();
287 $grade_item->sortorder = 3;
288
289 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
290 $this->grade_items[0] = $grade_item;
291
292 // id = 1
293 $grade_item = new stdClass();
294
295 $grade_item->courseid = $this->course->id;
296 $grade_item->categoryid = $this->grade_categories[1]->id;
297 $grade_item->itemname = 'unittestgradeitem2';
298 $grade_item->itemtype = 'import';
299 $grade_item->itemmodule = $this->course_module[1]->modname;
300 $grade_item->iteminstance = $this->course_module[1]->instance;
301 $grade_item->calculation = '= ##gi'.$this->grade_items[0]->id.'## + 30 + [[item id 0]] - [[item id 0]]';
302 $grade_item->gradetype = GRADE_TYPE_VALUE;
303 $grade_item->itemnumber = null;
304 $grade_item->grademin = 0;
305 $grade_item->grademax = 100;
306 $grade_item->iteminfo = 'Grade item 1 used for unit testing';
307 $grade_item->timecreated = time();
308 $grade_item->timemodified = time();
309 $grade_item->sortorder = 4;
310
311 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
312 $this->grade_items[1] = $grade_item;
313
314 // id = 2
315 $grade_item = new stdClass();
316
317 $grade_item->courseid = $this->course->id;
318 $grade_item->categoryid = $this->grade_categories[2]->id;
319 $grade_item->itemname = 'unittestgradeitem3';
320 $grade_item->itemtype = 'mod';
321 $grade_item->itemmodule = $this->course_module[2]->modname;
322 $grade_item->iteminstance = $this->course_module[2]->instance;
323 $grade_item->gradetype = GRADE_TYPE_SCALE;
324 $grade_item->scaleid = $this->scale[0]->id;
325 $grade_item->grademin = 0;
326 $grade_item->grademax = $this->scalemax[0];
327 $grade_item->iteminfo = 'Grade item 2 used for unit testing';
328 $grade_item->timecreated = time();
329 $grade_item->timemodified = time();
330 $grade_item->sortorder = 6;
331
332 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
333 $this->grade_items[2] = $grade_item;
334
335 // Load grade_items associated with the 3 categories
336 // id = 3
337 $grade_item = new stdClass();
338
339 $grade_item->courseid = $this->course->id;
340 $grade_item->iteminstance = $this->grade_categories[0]->id;
341 $grade_item->itemname = 'unittestgradeitemcategory1';
342 $grade_item->needsupdate = 0;
343 $grade_item->itemtype = 'category';
344 $grade_item->gradetype = GRADE_TYPE_VALUE;
345 $grade_item->grademin = 0;
346 $grade_item->grademax = 100;
347 $grade_item->iteminfo = 'Grade item 3 used for unit testing';
348 $grade_item->timecreated = time();
349 $grade_item->timemodified = time();
350 $grade_item->sortorder = 1;
351
352 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
353 $this->grade_items[3] = $grade_item;
354
355 // id = 4
356 $grade_item = new stdClass();
357
358 $grade_item->courseid = $this->course->id;
359 $grade_item->iteminstance = $this->grade_categories[1]->id;
360 $grade_item->itemname = 'unittestgradeitemcategory2';
361 $grade_item->itemtype = 'category';
362 $grade_item->gradetype = GRADE_TYPE_VALUE;
363 $grade_item->needsupdate = 0;
364 $grade_item->grademin = 0;
365 $grade_item->grademax = 100;
366 $grade_item->iteminfo = 'Grade item 4 used for unit testing';
367 $grade_item->timecreated = time();
368 $grade_item->timemodified = time();
369 $grade_item->sortorder = 2;
370
371 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
372 $this->grade_items[4] = $grade_item;
373
374 // id = 5
375 $grade_item = new stdClass();
376
377 $grade_item->courseid = $this->course->id;
378 $grade_item->iteminstance = $this->grade_categories[2]->id;
379 $grade_item->itemname = 'unittestgradeitemcategory3';
380 $grade_item->itemtype = 'category';
381 $grade_item->gradetype = GRADE_TYPE_VALUE;
382 $grade_item->needsupdate = true;
383 $grade_item->grademin = 0;
384 $grade_item->grademax = 100;
385 $grade_item->iteminfo = 'Grade item 5 used for unit testing';
386 $grade_item->timecreated = time();
387 $grade_item->timemodified = time();
388 $grade_item->sortorder = 5;
389
390 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
391 $this->grade_items[5] = $grade_item;
392
393 // Orphan grade_item
394 // id = 6
395 $grade_item = new stdClass();
396
397 $grade_item->courseid = $this->course->id;
398 $grade_item->categoryid = $course_category->id;
399 $grade_item->itemname = 'unittestorphangradeitem1';
400 $grade_item->itemtype = 'mod';
401 $grade_item->itemmodule = $this->course_module[4]->modname;
402 $grade_item->iteminstance = $this->course_module[4]->instance;
403 $grade_item->itemnumber = 0;
404 $grade_item->gradetype = GRADE_TYPE_VALUE;
405 $grade_item->grademin = 10;
406 $grade_item->grademax = 120;
407 $grade_item->locked = time();
408 $grade_item->iteminfo = 'Orphan Grade 6 item used for unit testing';
409 $grade_item->timecreated = time();
410 $grade_item->timemodified = time();
411 $grade_item->sortorder = 7;
412
413 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
414 $this->grade_items[6] = $grade_item;
415
416 // 2 grade items under level1category
417 // id = 7
418 $grade_item = new stdClass();
419
420 $grade_item->courseid = $this->course->id;
421 $grade_item->categoryid = $this->grade_categories[3]->id;
422 $grade_item->itemname = 'singleparentitem1';
423 $grade_item->itemtype = 'mod';
424 $grade_item->itemmodule = $this->course_module[5]->modname;
425 $grade_item->iteminstance = $this->course_module[5]->instance;
426 $grade_item->gradetype = GRADE_TYPE_SCALE;
427 $grade_item->scaleid = $this->scale[0]->id;
428 $grade_item->grademin = 0;
429 $grade_item->grademax = $this->scalemax[0];
430 $grade_item->iteminfo = 'Grade item 7 used for unit testing';
431 $grade_item->timecreated = time();
432 $grade_item->timemodified = time();
433 $grade_item->sortorder = 9;
434
435 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
436 $this->grade_items[7] = $grade_item;
437
438 // id = 8
439 $grade_item = new stdClass();
440
441 $grade_item->courseid = $this->course->id;
442 $grade_item->categoryid = $this->grade_categories[3]->id;
443 $grade_item->itemname = 'singleparentitem2';
444 $grade_item->itemtype = 'mod';
445 $grade_item->itemmodule = $this->course_module[6]->modname;
446 $grade_item->iteminstance = $this->course_module[6]->instance;
447 $grade_item->gradetype = GRADE_TYPE_VALUE;
448 $grade_item->grademin = 0;
449 $grade_item->grademax = 100;
450 $grade_item->iteminfo = 'Grade item 8 used for unit testing';
451 $grade_item->timecreated = time();
452 $grade_item->timemodified = time();
453 $grade_item->sortorder = 10;
454
455 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
456 $this->grade_items[8] = $grade_item;
457
458 // Grade_item for level1category
459 // id = 9
460 $grade_item = new stdClass();
461
462 $grade_item->courseid = $this->course->id;
463 $grade_item->itemname = 'grade_item for level1 category';
464 $grade_item->itemtype = 'category';
465 $grade_item->iteminstance = $this->grade_categories[3]->id;
466 $grade_item->needsupdate = true;
467 $grade_item->gradetype = GRADE_TYPE_VALUE;
468 $grade_item->grademin = 0;
469 $grade_item->grademax = 100;
470 $grade_item->iteminfo = 'Orphan Grade item 9 used for unit testing';
471 $grade_item->timecreated = time();
472 $grade_item->timemodified = time();
473 $grade_item->sortorder = 8;
474
475 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
476 $this->grade_items[9] = $grade_item;
477
478 // Manual grade_item
479 // id = 10
480 $grade_item = new stdClass();
481
482 $grade_item->courseid = $this->course->id;
483 $grade_item->categoryid = $course_category->id;
484 $grade_item->itemname = 'manual grade_item';
485 $grade_item->itemtype = 'manual';
486 $grade_item->itemnumber = 0;
487 $grade_item->needsupdate = false;
488 $grade_item->gradetype = GRADE_TYPE_VALUE;
489 $grade_item->grademin = 0;
490 $grade_item->grademax = 100;
491 $grade_item->iteminfo = 'Manual grade item 10 used for unit testing';
492 $grade_item->timecreated = time();
493 $grade_item->timemodified = time();
494
495 $grade_item->id = $DB->insert_record('grade_items', $grade_item);
496 $this->grade_items[10] = $grade_item;
497 }
498
499 /**
500 * Load grade_grades data into the database, and adds the corresponding objects to this class' variable.
501 */
502 private function load_grade_grades() {
503 global $DB;
504
505 //this method is called once for each test method. Avoid adding things to $this->grade_grades multiple times
506 $this->grade_grades = array();
507
508 // Grades for grade_item 1
509 $grade = new stdClass();
510 $grade->itemid = $this->grade_items[0]->id;
511 $grade->userid = $this->user[1]->id;
512 $grade->rawgrade = 15; // too small
513 $grade->finalgrade = 30;
514 $grade->timecreated = time();
515 $grade->timemodified = time();
516 $grade->information = '1 of 17 grade_grades';
517 $grade->informationformat = FORMAT_PLAIN;
518 $grade->feedback = 'Good, but not good enough..';
519 $grade->feedbackformat = FORMAT_PLAIN;
520
521 $grade->id = $DB->insert_record('grade_grades', $grade);
522 $this->grade_grades[0] = $grade;
523
524 $grade = new stdClass();
525 $grade->itemid = $this->grade_items[0]->id;
526 $grade->userid = $this->user[2]->id;
527 $grade->rawgrade = 40;
528 $grade->finalgrade = 40;
529 $grade->timecreated = time();
530 $grade->timemodified = time();
531 $grade->information = '2 of 17 grade_grades';
532
533 $grade->id = $DB->insert_record('grade_grades', $grade);
534 $this->grade_grades[1] = $grade;
535
536 $grade = new stdClass();
537 $grade->itemid = $this->grade_items[0]->id;
538 $grade->userid = $this->user[3]->id;
539 $grade->rawgrade = 170; // too big
540 $grade->finalgrade = 110;
541 $grade->timecreated = time();
542 $grade->timemodified = time();
543 $grade->information = '3 of 17 grade_grades';
544
545 $grade->id = $DB->insert_record('grade_grades', $grade);
546 $this->grade_grades[2] = $grade;
547
548
549 // No raw grades for grade_item 2 - it is calculated
550
551 $grade = new stdClass();
552 $grade->itemid = $this->grade_items[1]->id;
553 $grade->userid = $this->user[1]->id;
554 $grade->finalgrade = 60;
555 $grade->timecreated = time();
556 $grade->timemodified = time();
557 $grade->information = '4 of 17 grade_grades';
558
559 $grade->id = $DB->insert_record('grade_grades', $grade);
560 $this->grade_grades[3] = $grade;
561
562 $grade = new stdClass();
563 $grade->itemid = $this->grade_items[1]->id;
564 $grade->userid = $this->user[2]->id;
565 $grade->finalgrade = 70;
566 $grade->timecreated = time();
567 $grade->timemodified = time();
568 $grade->information = '5 of 17 grade_grades';
569
570 $grade->id = $DB->insert_record('grade_grades', $grade);
571 $this->grade_grades[4] = $grade;
572
573 $grade = new stdClass();
574 $grade->itemid = $this->grade_items[1]->id;
575 $grade->userid = $this->user[3]->id;
576 $grade->finalgrade = 100;
577 $grade->timecreated = time();
578 $grade->timemodified = time();
579 $grade->information = '6 of 17 grade_grades';
580
581 $grade->id = $DB->insert_record('grade_grades', $grade);
582 $this->grade_grades[5] = $grade;
583
584
585 // Grades for grade_item 3
586
587 $grade = new stdClass();
588 $grade->itemid = $this->grade_items[2]->id;
589 $grade->userid = $this->user[1]->id;
590 $grade->rawgrade = 2;
591 $grade->finalgrade = 6;
592 $grade->scaleid = $this->scale[3]->id;
593 $grade->timecreated = time();
594 $grade->timemodified = time();
595 $grade->information = '7 of 17 grade_grades';
596
597 $grade->id = $DB->insert_record('grade_grades', $grade);
598 $this->grade_grades[6] = $grade;
599
600 $grade = new stdClass();
601 $grade->itemid = $this->grade_items[2]->id;
602 $grade->userid = $this->user[2]->id;
603 $grade->rawgrade = 3;
604 $grade->finalgrade = 2;
605 $grade->scaleid = $this->scale[3]->id;
606 $grade->timecreated = time();
607 $grade->timemodified = time();
608 $grade->information = '8 of 17 grade_grades';
609
610 $grade->id = $DB->insert_record('grade_grades', $grade);
611 $this->grade_grades[] = $grade;
612
613 $grade = new stdClass();
614 $grade->itemid = $this->grade_items[2]->id;
615 $grade->userid = $this->user[3]->id;
616 $grade->rawgrade = 1;
617 $grade->finalgrade = 3;
618 $grade->scaleid = $this->scale[3]->id;
619 $grade->timecreated = time();
620 $grade->timemodified = time();
621 $grade->information = '9 of 17 grade_grades';
622
623 $grade->id = $DB->insert_record('grade_grades', $grade);
624 $this->grade_grades[] = $grade;
625
626 // Grades for grade_item 7
627
628 $grade = new stdClass();
629 $grade->itemid = $this->grade_items[6]->id;
630 $grade->userid = $this->user[1]->id;
631 $grade->rawgrade = 97;
632 $grade->finalgrade = 69;
633 $grade->timecreated = time();
634 $grade->timemodified = time();
635 $grade->information = '10 of 17 grade_grades';
636
637 $grade->id = $DB->insert_record('grade_grades', $grade);
638 $this->grade_grades[] = $grade;
639
640 $grade = new stdClass();
641 $grade->itemid = $this->grade_items[6]->id;
642 $grade->userid = $this->user[2]->id;
643 $grade->rawgrade = 49;
644 $grade->finalgrade = 87;
645 $grade->timecreated = time();
646 $grade->timemodified = time();
647 $grade->information = '11 of 17 grade_grades';
648
649 $grade->id = $DB->insert_record('grade_grades', $grade);
650 $this->grade_grades[] = $grade;
651
652 $grade = new stdClass();
653 $grade->itemid = $this->grade_items[6]->id;
654 $grade->userid = $this->user[3]->id;
655 $grade->rawgrade = 67;
656 $grade->finalgrade = 94;
657 $grade->timecreated = time();
658 $grade->timemodified = time();
659 $grade->information = '12 of 17 grade_grades';
660
661 $grade->id = $DB->insert_record('grade_grades', $grade);
662 $this->grade_grades[] = $grade;
663
664 // Grades for grade_item 8
665
666 $grade = new stdClass();
667 $grade->itemid = $this->grade_items[7]->id;
668 $grade->userid = $this->user[2]->id;
669 $grade->rawgrade = 3;
670 $grade->finalgrade = 3;
671 $grade->timecreated = time();
672 $grade->timemodified = time();
673 $grade->information = '13 of 17 grade_grades';
674
675 $grade->id = $DB->insert_record('grade_grades', $grade);
676 $this->grade_grades[] = $grade;
677
678 $grade = new stdClass();
679 $grade->itemid = $this->grade_items[7]->id;
680 $grade->userid = $this->user[3]->id;
681 $grade->rawgrade = 6;
682 $grade->finalgrade = 6;
683 $grade->timecreated = time();
684 $grade->timemodified = time();
685 $grade->information = '14 of 17 grade_grades';
686
687 $grade->id = $DB->insert_record('grade_grades', $grade);
688 $this->grade_grades[] = $grade;
689
690 // Grades for grade_item 9
691
692 $grade = new stdClass();
693 $grade->itemid = $this->grade_items[8]->id;
694 $grade->userid = $this->user[1]->id;
695 $grade->rawgrade = 20;
696 $grade->finalgrade = 20;
697 $grade->timecreated = time();
698 $grade->timemodified = time();
699 $grade->information = '15 of 17 grade_grades';
700
701 $grade->id = $DB->insert_record('grade_grades', $grade);
702 $this->grade_grades[] = $grade;
703
704 $grade = new stdClass();
705 $grade->itemid = $this->grade_items[8]->id;
706 $grade->userid = $this->user[2]->id;
707 $grade->rawgrade = 50;
708 $grade->finalgrade = 50;
709 $grade->timecreated = time();
710 $grade->timemodified = time();
711 $grade->information = '16 of 17 grade_grades';
712
713 $grade->id = $DB->insert_record('grade_grades', $grade);
714 $this->grade_grades[] = $grade;
715
716 $grade = new stdClass();
717 $grade->itemid = $this->grade_items[8]->id;
718 $grade->userid = $this->user[3]->id;
719 $grade->rawgrade = 100;
720 $grade->finalgrade = 100;
721 $grade->timecreated = time();
722 $grade->timemodified = time();
723 $grade->information = '17 of 17 grade_grades';
724
725 $grade->id = $DB->insert_record('grade_grades', $grade);
726 $this->grade_grades[] = $grade;
727 }
728
729 /**
730 * Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
731 */
732 private function load_grade_outcomes() {
733 global $DB;
734
735 //this method is called once for each test method. Avoid adding things to $this->grade_outcomes multiple times
736 $this->grade_outcomes = array();
737
738 // Calculation for grade_item 1
739 $grade_outcome = new stdClass();
740 $grade_outcome->fullname = 'Team work';
741 $grade_outcome->shortname = 'Team work';
742 $grade_outcome->fullname = 'Team work outcome';
743 $grade_outcome->timecreated = time();
744 $grade_outcome->timemodified = time();
745 $grade_outcome->scaleid = $this->scale[2]->id;
746
747 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
748 $this->grade_outcomes[] = $grade_outcome;
749
750 // Calculation for grade_item 2
751 $grade_outcome = new stdClass();
752 $grade_outcome->fullname = 'Complete circuit board';
753 $grade_outcome->shortname = 'Complete circuit board';
754 $grade_outcome->fullname = 'Complete circuit board';
755 $grade_outcome->timecreated = time();
756 $grade_outcome->timemodified = time();
757 $grade_outcome->scaleid = $this->scale[3]->id;
758
759 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
760 $this->grade_outcomes[] = $grade_outcome;
761
762 // Calculation for grade_item 3
763 $grade_outcome = new stdClass();
764 $grade_outcome->fullname = 'Debug Java program';
765 $grade_outcome->shortname = 'Debug Java program';
766 $grade_outcome->fullname = 'Debug Java program';
767 $grade_outcome->timecreated = time();
768 $grade_outcome->timemodified = time();
769 $grade_outcome->scaleid = $this->scale[4]->id;
770
771 $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
772 $this->grade_outcomes[] = $grade_outcome;
773 }
774}
775
776