PageRenderTime 46ms CodeModel.GetById 1ms app.highlight 39ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/grade/simpletest/testgradeitem.php

http://github.com/moodle/moodle
PHP | 568 lines | 387 code | 127 blank | 54 comment | 1 complexity | 57b157db3a28a6ca4f94ea8d03ac03cb MD5 | raw file
  1<?php
  2
  3///////////////////////////////////////////////////////////////////////////
  4//                                                                       //
  5// NOTICE OF COPYRIGHT                                                   //
  6//                                                                       //
  7// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
  8//          http://moodle.org                                            //
  9//                                                                       //
 10// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
 11//                                                                       //
 12// This program is free software; you can redistribute it and/or modify  //
 13// it under the terms of the GNU General Public License as published by  //
 14// the Free Software Foundation; either version 2 of the License, or     //
 15// (at your option) any later version.                                   //
 16//                                                                       //
 17// This program is distributed in the hope that it will be useful,       //
 18// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
 19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
 20// GNU General Public License for more details:                          //
 21//                                                                       //
 22//          http://www.gnu.org/copyleft/gpl.html                         //
 23//                                                                       //
 24///////////////////////////////////////////////////////////////////////////
 25
 26/**
 27 * Unit tests for grade_item object.
 28 *
 29 * @author nicolas@moodle.com
 30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 31 * @package moodlecore
 32 */
 33
 34if (!defined('MOODLE_INTERNAL')) {
 35    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
 36}
 37
 38require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
 39
 40Mock::generatePartial('grade_item', 'mock_grade_item_for_test_is_calculated', array('set_calculation'));
 41
 42@set_time_limit(0);
 43
 44class grade_item_test extends grade_test {
 45    function test_grade_item() {
 46        $this->sub_test_grade_item_construct();
 47        $this->sub_test_grade_item_insert();
 48        $this->sub_test_grade_item_delete();
 49        $this->sub_test_grade_item_update();
 50        $this->sub_test_grade_item_load_scale();
 51        $this->sub_test_grade_item_load_outcome();
 52        $this->sub_test_grade_item_qualifies_for_regrading();
 53        $this->sub_test_grade_item_force_regrading();
 54        $this->sub_test_grade_item_fetch();
 55        $this->sub_test_grade_item_fetch_all();
 56        $this->sub_test_grade_item_get_all_finals();
 57        $this->sub_test_grade_item_get_final();
 58        $this->sub_test_grade_item_get_sortorder();
 59        $this->sub_test_grade_item_set_sortorder();
 60        $this->sub_test_grade_item_move_after_sortorder();
 61        $this->sub_test_grade_item_get_name();
 62        $this->sub_test_grade_item_set_parent();
 63        $this->sub_test_grade_item_get_parent_category();
 64        $this->sub_test_grade_item_load_parent_category();
 65        $this->sub_test_grade_item_get_item_category();
 66        $this->sub_test_grade_item_load_item_category();
 67        $this->sub_test_grade_item_regrade_final_grades();
 68        $this->sub_test_grade_item_adjust_raw_grade();
 69        $this->sub_test_grade_item_set_locked();
 70        $this->sub_test_grade_item_is_locked();
 71        $this->sub_test_grade_item_set_hidden();
 72        $this->sub_test_grade_item_is_hidden();
 73        $this->sub_test_grade_item_is_category_item();
 74        $this->sub_test_grade_item_is_course_item();
 75        $this->sub_test_grade_item_fetch_course_item();
 76        $this->sub_test_grade_item_depends_on();
 77        $this->sub_test_grade_item_is_calculated();
 78        $this->sub_test_grade_item_set_calculation();
 79        $this->sub_test_grade_item_get_calculation();
 80        $this->sub_test_grade_item_compute();
 81    }
 82
 83    function sub_test_grade_item_construct() {
 84        $params = new stdClass();
 85
 86        $params->courseid = $this->courseid;
 87        $params->categoryid = $this->grade_categories[1]->id;
 88        $params->itemname = 'unittestgradeitem4';
 89        $params->itemtype = 'mod';
 90        $params->itemmodule = 'database';
 91        $params->iteminfo = 'Grade item used for unit testing';
 92
 93        $grade_item = new grade_item($params, false);
 94
 95        $this->assertEqual($params->courseid, $grade_item->courseid);
 96        $this->assertEqual($params->categoryid, $grade_item->categoryid);
 97        $this->assertEqual($params->itemmodule, $grade_item->itemmodule);
 98    }
 99
100    function sub_test_grade_item_insert() {
101        $grade_item = new grade_item();
102        $this->assertTrue(method_exists($grade_item, 'insert'));
103
104        $grade_item->courseid = $this->courseid;
105        $grade_item->categoryid = $this->grade_categories[1]->id;
106        $grade_item->itemname = 'unittestgradeitem4';
107        $grade_item->itemtype = 'mod';
108        $grade_item->itemmodule = 'quiz';
109        $grade_item->iteminfo = 'Grade item used for unit testing';
110
111        $grade_item->insert();
112
113        $last_grade_item = end($this->grade_items);
114
115        $this->assertEqual($grade_item->id, $last_grade_item->id + 1);
116        $this->assertEqual(11, $grade_item->sortorder);
117
118        //keep our reference collection the same as what is in the database
119        $this->grade_items[] = $grade_item;
120    }
121
122    function sub_test_grade_item_delete() {
123        global $DB;
124        $grade_item = new grade_item($this->grade_items[7]);//use a grade item not touched by previous (or future) tests
125        $this->assertTrue(method_exists($grade_item, 'delete'));
126
127        $this->assertTrue($grade_item->delete());
128
129        $this->assertFalse($DB->get_record('grade_items', array('id' => $grade_item->id)));
130
131        //keep our reference collection the same as the database
132        unset($this->grade_items[7]);
133    }
134
135    function sub_test_grade_item_update() {
136        global $DB;
137        $grade_item = new grade_item($this->grade_items[0]);
138        $this->assertTrue(method_exists($grade_item, 'update'));
139
140        $grade_item->iteminfo = 'Updated info for this unittest grade_item';
141
142        $this->assertTrue($grade_item->update());
143
144        $grade_item->grademin = 14;
145        $this->assertTrue($grade_item->qualifies_for_regrading());
146        $this->assertTrue($grade_item->update());
147
148        $iteminfo = $DB->get_field('grade_items', 'iteminfo', array('id' => $this->grade_items[0]->id));
149        $this->assertEqual($grade_item->iteminfo, $iteminfo);
150    }
151
152    function sub_test_grade_item_load_scale() {
153        $grade_item = new grade_item($this->grade_items[2]);
154        $this->assertTrue(method_exists($grade_item, 'load_scale'));
155        $scale = $grade_item->load_scale();
156        $this->assertFalse(empty($grade_item->scale));
157        $this->assertEqual($scale->id, $this->grade_items[2]->scaleid);
158    }
159
160    function sub_test_grade_item_load_outcome() {
161        $grade_item = new grade_item($this->grade_items[0]);
162        $this->assertTrue(method_exists($grade_item, 'load_outcome'));
163        //TODO: add tests
164    }
165
166    function sub_test_grade_item_qualifies_for_regrading() {
167        $grade_item = new grade_item($this->grade_items[1]);//use a grade item not touched by previous tests
168        $this->assertTrue(method_exists($grade_item, 'qualifies_for_regrading'));
169
170        $this->assertFalse($grade_item->qualifies_for_regrading());
171
172        $grade_item->iteminfo = 'Updated info for this unittest grade_item';
173
174        $this->assertFalse($grade_item->qualifies_for_regrading());
175
176        $grade_item->grademin = 14;
177
178        $this->assertTrue($grade_item->qualifies_for_regrading());
179    }
180
181    function sub_test_grade_item_force_regrading() {
182        $grade_item = new grade_item($this->grade_items[2]);//use a grade item not touched by previous tests
183        $this->assertTrue(method_exists($grade_item, 'force_regrading'));
184
185        $this->assertEqual(0, $grade_item->needsupdate);
186
187        $grade_item->force_regrading();
188        $this->assertEqual(1, $grade_item->needsupdate);
189        $grade_item->update_from_db();
190        $this->assertEqual(1, $grade_item->needsupdate);
191    }
192
193    function sub_test_grade_item_fetch() {
194        $grade_item = new grade_item();
195        $this->assertTrue(method_exists($grade_item, 'fetch'));
196
197        //not using $this->grade_items[0] as it's iteminfo was modified by sub_test_grade_item_qualifies_for_regrading()
198        $grade_item = grade_item::fetch(array('id'=>$this->grade_items[1]->id));
199        $this->assertEqual($this->grade_items[1]->id, $grade_item->id);
200        $this->assertEqual($this->grade_items[1]->iteminfo, $grade_item->iteminfo);
201
202        $grade_item = grade_item::fetch(array('itemtype'=>$this->grade_items[1]->itemtype, 'itemmodule'=>$this->grade_items[1]->itemmodule));
203        $this->assertEqual($this->grade_items[1]->id, $grade_item->id);
204        $this->assertEqual($this->grade_items[1]->iteminfo, $grade_item->iteminfo);
205    }
206
207    function sub_test_grade_item_fetch_all() {
208        $grade_item = new grade_item();
209        $this->assertTrue(method_exists($grade_item, 'fetch_all'));
210
211        $grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid));
212        $this->assertEqual(count($this->grade_items), count($grade_items)-1);//-1 to account for the course grade item
213    }
214
215    // Retrieve all final scores for a given grade_item.
216    function sub_test_grade_item_get_all_finals() {
217        $grade_item = new grade_item($this->grade_items[0]);
218        $this->assertTrue(method_exists($grade_item, 'get_final'));
219
220        $final_grades = $grade_item->get_final();
221        $this->assertEqual(3, count($final_grades));
222    }
223
224
225    // Retrieve all final scores for a specific userid.
226    function sub_test_grade_item_get_final() {
227        $grade_item = new grade_item($this->grade_items[0]);
228        $this->assertTrue(method_exists($grade_item, 'get_final'));
229        $final_grade = $grade_item->get_final($this->userid);
230        $this->assertEqual($this->grade_grades[0]->finalgrade, $final_grade->finalgrade);
231    }
232
233    function sub_test_grade_item_get_sortorder() {
234        $grade_item = new grade_item($this->grade_items[0]);
235        $this->assertTrue(method_exists($grade_item, 'get_sortorder'));
236        $sortorder = $grade_item->get_sortorder();
237        $this->assertEqual($this->grade_items[0]->sortorder, $sortorder);
238    }
239
240    function sub_test_grade_item_set_sortorder() {
241        $grade_item = new grade_item($this->grade_items[0]);
242        $this->assertTrue(method_exists($grade_item, 'set_sortorder'));
243        $grade_item->set_sortorder(999);
244        $this->assertEqual($grade_item->sortorder, 999);
245    }
246
247    function sub_test_grade_item_move_after_sortorder() {
248        $grade_item = new grade_item($this->grade_items[0]);
249        $this->assertTrue(method_exists($grade_item, 'move_after_sortorder'));
250        $grade_item->move_after_sortorder(5);
251        $this->assertEqual($grade_item->sortorder, 6);
252
253        $grade_item = grade_item::fetch(array('id'=>$this->grade_items[0]->id));
254        $this->assertEqual($grade_item->sortorder, 6);
255
256        $after = grade_item::fetch(array('id'=>$this->grade_items[6]->id));
257        $this->assertEqual($after->sortorder, 8);
258    }
259
260    function sub_test_grade_item_get_name() {
261        $grade_item = new grade_item($this->grade_items[0]);
262        $this->assertTrue(method_exists($grade_item, 'get_name'));
263
264        $name = $grade_item->get_name();
265        $this->assertEqual($this->grade_items[0]->itemname, $name);
266    }
267
268    function sub_test_grade_item_set_parent() {
269        $grade_item = new grade_item($this->grade_items[0]);
270        $this->assertTrue(method_exists($grade_item, 'set_parent'));
271
272        $old = $grade_item->get_parent_category();
273        $new = new grade_category($this->grade_categories[3]);
274        $new_item = $new->get_grade_item();
275
276        $this->assertTrue($grade_item->set_parent($new->id));
277
278        $new_item->update_from_db();
279        $grade_item->update_from_db();
280
281        $this->assertEqual($grade_item->categoryid, $new->id);
282    }
283
284    function sub_test_grade_item_get_parent_category() {
285        $grade_item = new grade_item($this->grade_items[0]);
286        $this->assertTrue(method_exists($grade_item, 'get_parent_category'));
287
288        $category = $grade_item->get_parent_category();
289        $this->assertEqual($this->grade_categories[1]->fullname, $category->fullname);
290    }
291
292    function sub_test_grade_item_load_parent_category() {
293        $grade_item = new grade_item($this->grade_items[0]);
294        $this->assertTrue(method_exists($grade_item, 'load_parent_category'));
295
296        $category = $grade_item->load_parent_category();
297        $this->assertEqual($this->grade_categories[1]->fullname, $category->fullname);
298        $this->assertEqual($this->grade_categories[1]->fullname, $grade_item->parent_category->fullname);
299    }
300
301    function sub_test_grade_item_get_item_category() {
302        $grade_item = new grade_item($this->grade_items[3]);
303        $this->assertTrue(method_exists($grade_item, 'get_item_category'));
304
305        $category = $grade_item->get_item_category();
306        $this->assertEqual($this->grade_categories[0]->fullname, $category->fullname);
307    }
308
309    function sub_test_grade_item_load_item_category() {
310        $grade_item = new grade_item($this->grade_items[3]);
311        $this->assertTrue(method_exists($grade_item, 'load_item_category'));
312
313        $category = $grade_item->load_item_category();
314        $this->assertEqual($this->grade_categories[0]->fullname, $category->fullname);
315        $this->assertEqual($this->grade_categories[0]->fullname, $grade_item->item_category->fullname);
316    }
317
318    // Test update of all final grades
319    function sub_test_grade_item_regrade_final_grades() {
320        $grade_item = new grade_item($this->grade_items[0]);
321        $this->assertTrue(method_exists($grade_item, 'regrade_final_grades'));
322        $this->assertEqual(true, $grade_item->regrade_final_grades());
323        //TODO: add more tests
324    }
325
326    // Test the adjust_raw_grade method
327    function sub_test_grade_item_adjust_raw_grade() {
328        $grade_item = new grade_item($this->grade_items[0]);
329        $this->assertTrue(method_exists($grade_item, 'adjust_raw_grade'));
330        $grade_raw = new stdClass();
331
332        $grade_raw->rawgrade = 40;
333        $grade_raw->grademax = 100;
334        $grade_raw->grademin = 0;
335
336        $grade_item->multfactor = 1;
337        $grade_item->plusfactor = 0;
338        $grade_item->grademax = 50;
339        $grade_item->grademin = 0;
340
341        $original_grade_raw  = clone($grade_raw);
342        $original_grade_item = clone($grade_item);
343
344        $this->assertEqual(20, $grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax));
345
346        // Try a larger maximum grade
347        $grade_item->grademax = 150;
348        $grade_item->grademin = 0;
349        $this->assertEqual(60, $grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax));
350
351        // Try larger minimum grade
352        $grade_item->grademin = 50;
353
354        $this->assertEqual(90, $grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax));
355
356        // Rescaling from a small scale (0-50) to a larger scale (0-100)
357        $grade_raw->grademax = 50;
358        $grade_raw->grademin = 0;
359        $grade_item->grademax = 100;
360        $grade_item->grademin = 0;
361
362        $this->assertEqual(80, $grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax));
363
364        // Rescaling from a small scale (0-50) to a larger scale with offset (40-100)
365        $grade_item->grademax = 100;
366        $grade_item->grademin = 40;
367
368        $this->assertEqual(88, $grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax));
369
370        // Try multfactor and plusfactor
371        $grade_raw = clone($original_grade_raw);
372        $grade_item = clone($original_grade_item);
373        $grade_item->multfactor = 1.23;
374        $grade_item->plusfactor = 3;
375
376        $this->assertEqual(27.6, $grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax));
377
378        // Try multfactor below 0 and a negative plusfactor
379        $grade_raw = clone($original_grade_raw);
380        $grade_item = clone($original_grade_item);
381        $grade_item->multfactor = 0.23;
382        $grade_item->plusfactor = -3;
383
384        $this->assertEqual(round(1.6), round($grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax)));
385    }
386
387    // Test locking of grade items
388    function sub_test_grade_item_set_locked() {
389        
390        //getting a grade_item from the DB as set_locked() will fail if the grade items needs to be updated
391        //also needs to have at least one grade_grade or $grade_item->get_final(1) returns null
392        //$grade_item = new grade_item($this->grade_items[8]);
393        $grade_item = grade_item::fetch(array('id'=>$this->grade_items[8]->id));
394
395        $this->assertTrue(method_exists($grade_item, 'set_locked'));
396
397        $grade_grade = new grade_grade($grade_item->get_final(1));
398        $this->assertTrue(empty($grade_item->locked));//not locked
399        $this->assertTrue(empty($grade_grade->locked));//not locked
400
401        $this->assertTrue($grade_item->set_locked(true, true, false));
402        $grade_grade = new grade_grade($grade_item->get_final(1));
403
404        $this->assertFalse(empty($grade_item->locked));//locked
405        $this->assertFalse(empty($grade_grade->locked)); // individual grades should be locked too
406
407        $this->assertTrue($grade_item->set_locked(false, true, false));
408        $grade = new grade_grade($grade_item->get_final(1));
409
410        $this->assertTrue(empty($grade_item->locked));
411        $this->assertTrue(empty($grade->locked)); // individual grades should be unlocked too
412    }
413
414    function sub_test_grade_item_is_locked() {
415        $grade_item = new grade_item($this->grade_items[10]);
416        $this->assertTrue(method_exists($grade_item, 'is_locked'));
417
418        $this->assertFalse($grade_item->is_locked());
419        $this->assertFalse($grade_item->is_locked(1));
420        $this->assertTrue($grade_item->set_locked(true, true, false));
421        $this->assertTrue($grade_item->is_locked());
422        $this->assertTrue($grade_item->is_locked(1));
423    }
424
425    // Test hiding of grade items
426    function sub_test_grade_item_set_hidden() {
427        $grade_item = new grade_item($this->grade_items[0]);
428        $this->assertTrue(method_exists($grade_item, 'set_hidden'));
429
430        $grade = new grade_grade($grade_item->get_final(1));
431        $this->assertEqual(0, $grade_item->hidden);
432        $this->assertEqual(0, $grade->hidden);
433
434        $grade_item->set_hidden(666, true);
435        $grade = new grade_grade($grade_item->get_final(1));
436
437        $this->assertEqual(666, $grade_item->hidden);
438        $this->assertEqual(666, $grade->hidden);
439    }
440
441    function sub_test_grade_item_is_hidden() {
442        $grade_item = new grade_item($this->grade_items[0]);
443        $this->assertTrue(method_exists($grade_item, 'is_hidden'));
444
445        $this->assertFalse($grade_item->is_hidden());
446        $this->assertFalse($grade_item->is_hidden(1));
447
448        $grade_item->set_hidden(1);
449        $this->assertTrue($grade_item->is_hidden());
450        $this->assertTrue($grade_item->is_hidden(1));
451
452        $grade_item->set_hidden(666);
453        $this->assertFalse($grade_item->is_hidden());
454        $this->assertFalse($grade_item->is_hidden(1));
455
456        $grade_item->set_hidden(time()+666);
457        $this->assertTrue($grade_item->is_hidden());
458        $this->assertTrue($grade_item->is_hidden(1));
459    }
460
461    function sub_test_grade_item_is_category_item() {
462        $grade_item = new grade_item($this->grade_items[3]);
463        $this->assertTrue(method_exists($grade_item, 'is_category_item'));
464        $this->assertTrue($grade_item->is_category_item());
465    }
466
467    function sub_test_grade_item_is_course_item() {
468        $grade_item = grade_item::fetch_course_item($this->courseid);
469        $this->assertTrue(method_exists($grade_item, 'is_course_item'));
470        $this->assertTrue($grade_item->is_course_item());
471    }
472
473    function sub_test_grade_item_fetch_course_item() {
474        $grade_item = grade_item::fetch_course_item($this->courseid);
475        $this->assertTrue(method_exists($grade_item, 'fetch_course_item'));
476        $this->assertTrue($grade_item->itemtype, 'course');
477    }
478
479    function sub_test_grade_item_depends_on() {
480        $grade_item = new grade_item($this->grade_items[1]);
481
482        // calculated grade dependency
483        $deps = $grade_item->depends_on();
484        sort($deps, SORT_NUMERIC); // for comparison
485        $this->assertEqual(array($this->grade_items[0]->id), $deps);
486
487        // simulate depends on returns none when locked
488        $grade_item->locked = time();
489        $grade_item->update();
490        $deps = $grade_item->depends_on();
491        sort($deps, SORT_NUMERIC); // for comparison
492        $this->assertEqual(array(), $deps);
493
494        // category dependency
495        $grade_item = new grade_item($this->grade_items[3]);
496        $deps = $grade_item->depends_on();
497        sort($deps, SORT_NUMERIC); // for comparison
498        $res = array($this->grade_items[4]->id, $this->grade_items[5]->id);
499        $this->assertEqual($res, $deps);
500    }
501
502    function sub_test_grade_item_is_calculated() {
503        $grade_item = new mock_grade_item_for_test_is_calculated($this);
504        $grade_item->set_properties($grade_item, $this->grade_items[1]);
505        $this->assertTrue(method_exists($grade_item, 'is_calculated'));
506        $grade_itemsource = new grade_item($this->grade_items[0]);
507        $normalizedformula = str_replace("[[$grade_itemsource->idnumber]]", "##gi$grade_itemsource->id##", $this->grade_items[1]->calculation);
508
509        $grade_item->expectOnce('set_calculation', array($grade_item->calculation));
510        $grade_item->setReturnValue('set_calculation', $normalizedformula);
511        $this->assertTrue($grade_item->is_calculated());
512    }
513
514    function sub_test_grade_item_set_calculation() {
515        $grade_item = new grade_item($this->grade_items[1]);
516        $this->assertTrue(method_exists($grade_item, 'set_calculation'));
517        $grade_itemsource = new grade_item($this->grade_items[0]);
518
519        $grade_item->set_calculation('=[['.$grade_itemsource->idnumber.']]');
520
521        $this->assertTrue(!empty($grade_item->needsupdate));
522        $this->assertEqual('=##gi'.$grade_itemsource->id.'##', $grade_item->calculation);
523    }
524
525    function sub_test_grade_item_get_calculation() {
526        $grade_item = new grade_item($this->grade_items[1]);
527        $this->assertTrue(method_exists($grade_item, 'get_calculation'));
528        $grade_itemsource = new grade_item($this->grade_items[0]);
529
530        $denormalizedformula = str_replace('##gi'.$grade_itemsource->id.'##', '[['.$grade_itemsource->idnumber.']]', $this->grade_items[1]->calculation);
531
532        $formula = $grade_item->get_calculation();
533        $this->assertTrue(!empty($grade_item->needsupdate));
534        $this->assertEqual($denormalizedformula, $formula);
535    }
536
537    function sub_test_grade_item_compute() {
538        $grade_item = grade_item::fetch(array('id'=>$this->grade_items[1]->id));
539        $this->assertTrue(method_exists($grade_item, 'compute'));
540
541        //check the grade_grades in the array match those in the DB then delete $this->grade_items[1]'s grade_grades
542        $this->grade_grades[3] = grade_grade::fetch(array('id'=>$this->grade_grades[3]->id));
543        $grade_grade = grade_grade::fetch(array('id'=>$this->grade_grades[3]->id));
544        $grade_grade->delete();
545        
546        $this->grade_grades[4] = grade_grade::fetch(array('id'=>$this->grade_grades[4]->id));
547        $grade_grade = grade_grade::fetch(array('id'=>$this->grade_grades[4]->id));
548        $grade_grade->delete();
549        
550        $this->grade_grades[5] = grade_grade::fetch(array('id'=>$this->grade_grades[5]->id));
551        $grade_grade = grade_grade::fetch(array('id'=>$this->grade_grades[5]->id));
552        $grade_grade->delete();
553
554        //recalculate the grades (its a calculation so pulls values from other grade_items) and reinsert them
555        $grade_item->compute();
556        
557        $grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[3]->userid, 'itemid'=>$this->grade_grades[3]->itemid));
558        $this->assertEqual($this->grade_grades[3]->finalgrade, $grade_grade->finalgrade);
559        
560        $grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[4]->userid, 'itemid'=>$this->grade_grades[4]->itemid));
561        $this->assertEqual($this->grade_grades[4]->finalgrade, $grade_grade->finalgrade);
562        
563        $grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[5]->userid, 'itemid'=>$this->grade_grades[5]->itemid));
564        $this->assertEqual($this->grade_grades[5]->finalgrade, $grade_grade->finalgrade);
565
566    }
567
568}