|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 // // 00005 // NOTICE OF COPYRIGHT // 00006 // // 00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 00008 // http://moodle.org // 00009 // // 00010 // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // 00011 // // 00012 // This program is free software; you can redistribute it and/or modify // 00013 // it under the terms of the GNU General Public License as published by // 00014 // the Free Software Foundation; either version 2 of the License, or // 00015 // (at your option) any later version. // 00016 // // 00017 // This program is distributed in the hope that it will be useful, // 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00020 // GNU General Public License for more details: // 00021 // // 00022 // http://www.gnu.org/copyleft/gpl.html // 00023 // // 00025 00034 if (!defined('MOODLE_INTERNAL')) { 00035 die('Direct access to this script is forbidden.'); 00036 } 00037 00038 require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php'); 00039 00040 class grade_category_test extends grade_test { 00041 00042 public function __construct() { 00043 $this->starttime = time(); 00044 parent::__construct(); 00045 } 00046 00047 public function __destruct() { 00048 $this->endtime = time(); 00049 //var_dump($this->endtime-$this->starttime); 00050 00051 parent::__destruct(); 00052 } 00053 00054 function test_grade_category() { 00055 $this->sub_test_grade_category_construct(); 00056 $this->sub_test_grade_category_build_path(); 00057 $this->sub_test_grade_category_fetch(); 00058 $this->sub_test_grade_category_fetch_all(); 00059 $this->sub_test_grade_category_update(); 00060 $this->sub_test_grade_category_delete(); 00061 $this->sub_test_grade_category_insert(); 00062 $this->sub_test_grade_category_qualifies_for_regrading(); 00063 $this->sub_test_grade_category_force_regrading(); 00064 $this->sub_test_grade_category_aggregate_grades(); 00065 $this->sub_test_grade_category_apply_limit_rules(); 00066 $this->sub_test_grade_category_is_aggregationcoef_used(); 00067 $this->sub_test_grade_category_fetch_course_tree(); 00068 $this->sub_test_grade_category_get_children(); 00069 $this->sub_test_grade_category_load_grade_item(); 00070 $this->sub_test_grade_category_get_grade_item(); 00071 $this->sub_test_grade_category_load_parent_category(); 00072 $this->sub_test_grade_category_get_parent_category(); 00073 $this->sub_test_grade_category_get_name(); 00074 $this->sub_test_grade_category_set_parent(); 00075 $this->sub_test_grade_category_get_final(); 00076 $this->sub_test_grade_category_get_sortorder(); 00077 $this->sub_test_grade_category_set_sortorder(); 00078 $this->sub_test_grade_category_is_editable(); 00079 $this->sub_test_grade_category_move_after_sortorder(); 00080 $this->sub_test_grade_category_is_course_category(); 00081 $this->sub_test_grade_category_fetch_course_category(); 00082 $this->sub_test_grade_category_is_locked(); 00083 $this->sub_test_grade_category_set_locked(); 00084 $this->sub_test_grade_category_is_hidden(); 00085 $this->sub_test_grade_category_set_hidden(); 00086 00087 //this won't work until MDL-11837 is complete 00088 //$this->sub_test_grade_category_generate_grades(); 00089 00090 //do this last as adding a second course category messes up the data 00091 $this->sub_test_grade_category_insert_course_category(); 00092 } 00093 00094 //adds 3 new grade categories at various depths 00095 function sub_test_grade_category_construct() { 00096 $course_category = grade_category::fetch_course_category($this->courseid); 00097 00098 $params = new stdClass(); 00099 00100 $params->courseid = $this->courseid; 00101 $params->fullname = 'unittestcategory4'; 00102 00103 $grade_category = new grade_category($params, false); 00104 $grade_category->insert(); 00105 $this->grade_categories[] = $grade_category; 00106 00107 $this->assertEqual($params->courseid, $grade_category->courseid); 00108 $this->assertEqual($params->fullname, $grade_category->fullname); 00109 $this->assertEqual(2, $grade_category->depth); 00110 $this->assertEqual("/$course_category->id/$grade_category->id/", $grade_category->path); 00111 $parentpath = $grade_category->path; 00112 00113 // Test a child category 00114 $params->parent = $grade_category->id; 00115 $params->fullname = 'unittestcategory5'; 00116 $grade_category = new grade_category($params, false); 00117 $grade_category->insert(); 00118 $this->grade_categories[] = $grade_category; 00119 00120 $this->assertEqual(3, $grade_category->depth); 00121 $this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path); 00122 $parentpath = $grade_category->path; 00123 00124 // Test a third depth category 00125 $params->parent = $grade_category->id; 00126 $params->fullname = 'unittestcategory6'; 00127 $grade_category = new grade_category($params, false); 00128 $grade_category->insert(); 00129 $this->grade_categories[50] = $grade_category;//going to delete this one later hence the special index 00130 00131 $this->assertEqual(4, $grade_category->depth); 00132 $this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path); 00133 } 00134 00135 function sub_test_grade_category_build_path() { 00136 $grade_category = new grade_category($this->grade_categories[1]); 00137 $this->assertTrue(method_exists($grade_category, 'build_path')); 00138 $path = grade_category::build_path($grade_category); 00139 $this->assertEqual($grade_category->path, $path); 00140 } 00141 00142 function sub_test_grade_category_fetch() { 00143 $grade_category = new grade_category(); 00144 $this->assertTrue(method_exists($grade_category, 'fetch')); 00145 00146 $grade_category = grade_category::fetch(array('id'=>$this->grade_categories[0]->id)); 00147 $this->assertEqual($this->grade_categories[0]->id, $grade_category->id); 00148 $this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname); 00149 } 00150 00151 function sub_test_grade_category_fetch_all() { 00152 $grade_category = new grade_category(); 00153 $this->assertTrue(method_exists($grade_category, 'fetch_all')); 00154 00155 $grade_categories = grade_category::fetch_all(array('courseid'=>$this->courseid)); 00156 $this->assertEqual(count($this->grade_categories), count($grade_categories)-1); 00157 } 00158 00159 function sub_test_grade_category_update() { 00160 global $DB; 00161 $grade_category = new grade_category($this->grade_categories[0]); 00162 $this->assertTrue(method_exists($grade_category, 'update')); 00163 00164 $grade_category->fullname = 'Updated info for this unittest grade_category'; 00165 $grade_category->path = null; // path must be recalculated if missing 00166 $grade_category->depth = null; 00167 $grade_category->aggregation = GRADE_AGGREGATE_MAX; // should force regrading 00168 00169 $grade_item = $grade_category->get_grade_item(); 00170 $this->assertEqual(0, $grade_item->needsupdate); 00171 00172 $this->assertTrue($grade_category->update()); 00173 00174 $fullname = $DB->get_field('grade_categories', 'fullname', array('id' => $this->grade_categories[0]->id)); 00175 $this->assertEqual($grade_category->fullname, $fullname); 00176 00177 $path = $DB->get_field('grade_categories', 'path', array('id' => $this->grade_categories[0]->id)); 00178 $this->assertEqual($grade_category->path, $path); 00179 00180 $depth = $DB->get_field('grade_categories', 'depth', array('id' => $this->grade_categories[0]->id)); 00181 $this->assertEqual($grade_category->depth, $depth); 00182 00183 $grade_item = $grade_category->get_grade_item(); 00184 $this->assertEqual(1, $grade_item->needsupdate); 00185 } 00186 00187 function sub_test_grade_category_delete() { 00188 global $DB; 00189 00190 $grade_category = new grade_category($this->grade_categories[50]); 00191 $this->assertTrue(method_exists($grade_category, 'delete')); 00192 00193 $this->assertTrue($grade_category->delete()); 00194 $this->assertFalse($DB->get_record('grade_categories', array('id' => $grade_category->id))); 00195 } 00196 00197 function sub_test_grade_category_insert() { 00198 $course_category = grade_category::fetch_course_category($this->courseid); 00199 00200 $grade_category = new grade_category(); 00201 $this->assertTrue(method_exists($grade_category, 'insert')); 00202 00203 $grade_category->fullname = 'unittestcategory4'; 00204 $grade_category->courseid = $this->courseid; 00205 $grade_category->aggregation = GRADE_AGGREGATE_MEAN; 00206 $grade_category->aggregateonlygraded = 1; 00207 $grade_category->keephigh = 100; 00208 $grade_category->droplow = 10; 00209 $grade_category->hidden = 0; 00210 $grade_category->parent = $this->grade_categories[1]->id; //sub_test_grade_category_delete() removed the category at 0 00211 00212 $grade_category->insert(); 00213 00214 $this->assertEqual('/'.$course_category->id.'/'.$this->grade_categories[1]->parent.'/'.$this->grade_categories[1]->id.'/'.$grade_category->id.'/', $grade_category->path); 00215 $this->assertEqual(4, $grade_category->depth); 00216 00217 $last_grade_category = end($this->grade_categories); 00218 00219 $this->assertFalse(empty($grade_category->grade_item)); 00220 $this->assertEqual($grade_category->id, $grade_category->grade_item->iteminstance); 00221 $this->assertEqual('category', $grade_category->grade_item->itemtype); 00222 00223 $this->assertEqual($grade_category->id, $last_grade_category->id + 1); 00224 $this->assertFalse(empty($grade_category->timecreated)); 00225 $this->assertFalse(empty($grade_category->timemodified)); 00226 } 00227 00228 function sub_test_grade_category_qualifies_for_regrading() { 00229 $grade_category = new grade_category($this->grade_categories[1]); 00230 $this->assertTrue(method_exists($grade_category, 'qualifies_for_regrading')); 00231 $this->assertFalse($grade_category->qualifies_for_regrading()); 00232 00233 $grade_category->aggregation = GRADE_AGGREGATE_MAX; 00234 $this->assertTrue($grade_category->qualifies_for_regrading()); 00235 00236 $grade_category = new grade_category($this->grade_categories[1]); 00237 $grade_category->droplow = 99; 00238 $this->assertTrue($grade_category->qualifies_for_regrading()); 00239 00240 $grade_category = new grade_category($this->grade_categories[1]); 00241 $grade_category->keephigh = 99; 00242 $this->assertTrue($grade_category->qualifies_for_regrading()); 00243 } 00244 00245 function sub_test_grade_category_force_regrading() { 00246 $grade_category = new grade_category($this->grade_categories[1]); 00247 $this->assertTrue(method_exists($grade_category, 'force_regrading')); 00248 00249 $grade_category->load_grade_item(); 00250 $this->assertEqual(0, $grade_category->grade_item->needsupdate); 00251 00252 $grade_category->force_regrading(); 00253 00254 $grade_category->grade_item = null; 00255 $grade_category->load_grade_item(); 00256 00257 $this->assertEqual(1, $grade_category->grade_item->needsupdate); 00258 } 00259 00265 function sub_test_grade_category_generate_grades() { 00266 global $DB; 00267 00268 //inserting some special grade items to make testing the final grade calculation easier 00269 $params->courseid = $this->courseid; 00270 $params->fullname = 'unittestgradecalccategory'; 00271 $params->aggregation = GRADE_AGGREGATE_MEAN; 00272 $params->aggregateonlygraded = 0; 00273 $grade_category = new grade_category($params, false); 00274 $grade_category->insert(); 00275 00276 $this->assertTrue(method_exists($grade_category, 'generate_grades')); 00277 00278 $grade_category->load_grade_item(); 00279 $cgi = $grade_category->get_grade_item(); 00280 $cgi->grademin = 0; 00281 $cgi->grademax = 20;//3 grade items out of 10 but category is out of 20 to force scaling to occur 00282 $cgi->update(); 00283 00284 //3 grade items each with a maximum grade of 10 00285 $grade_items = array(); 00286 for ($i=0; $i<3; $i++) { 00287 $grade_items[$i] = new grade_item(); 00288 $grade_items[$i]->courseid = $this->courseid; 00289 $grade_items[$i]->categoryid = $grade_category->id; 00290 $grade_items[$i]->itemname = 'manual grade_item '.$i; 00291 $grade_items[$i]->itemtype = 'manual'; 00292 $grade_items[$i]->itemnumber = 0; 00293 $grade_items[$i]->needsupdate = false; 00294 $grade_items[$i]->gradetype = GRADE_TYPE_VALUE; 00295 $grade_items[$i]->grademin = 0; 00296 $grade_items[$i]->grademax = 10; 00297 $grade_items[$i]->iteminfo = 'Manual grade item used for unit testing'; 00298 $grade_items[$i]->timecreated = mktime(); 00299 $grade_items[$i]->timemodified = mktime(); 00300 00301 //used as the weight by weighted mean and as extra credit by mean with extra credit 00302 //Will be 0, 1 and 2 00303 $grade_items[$i]->aggregationcoef = $i; 00304 00305 $grade_items[$i]->insert(); 00306 } 00307 00308 //a grade for each grade item 00309 $grade_grades = array(); 00310 for ($i=0; $i<3; $i++) { 00311 $grade_grades[$i] = new grade_grade(); 00312 $grade_grades[$i]->itemid = $grade_items[$i]->id; 00313 $grade_grades[$i]->userid = $this->userid; 00314 $grade_grades[$i]->rawgrade = ($i+1)*2;//produce grade grades of 2, 4 and 6 00315 $grade_grades[$i]->finalgrade = ($i+1)*2; 00316 $grade_grades[$i]->timecreated = mktime(); 00317 $grade_grades[$i]->timemodified = mktime(); 00318 $grade_grades[$i]->information = '1 of 2 grade_grades'; 00319 $grade_grades[$i]->informationformat = FORMAT_PLAIN; 00320 $grade_grades[$i]->feedback = 'Good, but not good enough..'; 00321 $grade_grades[$i]->feedbackformat = FORMAT_PLAIN; 00322 00323 $grade_grades[$i]->insert(); 00324 } 00325 00326 //3 grade items with 1 grade_grade each. 00327 //grade grades have the values 2, 4 and 6 00328 00329 //First correct answer is the aggregate with all 3 grades 00330 //Second correct answer is with the first grade (value 2) hidden 00331 00332 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEDIAN, 'GRADE_AGGREGATE_MEDIAN', 8, 8); 00333 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MAX, 'GRADE_AGGREGATE_MAX', 12, 12); 00334 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MODE, 'GRADE_AGGREGATE_MODE', 12, 12); 00335 00336 //weighted mean. note grade totals are rounded to an int to prevent rounding discrepancies. correct final grade isnt actually exactly 10 00337 //3 items with grades 2, 4 and 6 with weights 0, 1 and 2 and all out of 10. then doubled to be out of 20. 00338 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN, 'GRADE_AGGREGATE_WEIGHTED_MEAN', 10, 10); 00339 00340 //simple weighted mean 00341 //3 items with grades 2, 4 and 6 equally weighted and all out of 10. then doubled to be out of 20. 00342 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN2, 'GRADE_AGGREGATE_WEIGHTED_MEAN2', 8, 10); 00343 00344 //mean of grades with extra credit 00345 //3 items with grades 2, 4 and 6 with extra credit 0, 1 and 2 equally weighted and all out of 10. then doubled to be out of 20. 00346 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_EXTRACREDIT_MEAN, 'GRADE_AGGREGATE_EXTRACREDIT_MEAN', 10, 13); 00347 00348 //aggregation tests the are affected by a hidden grade currently dont work as we dont store the altered grade in the database 00349 //instead an in memory recalculation is done. This should be remedied by MDL-11837 00350 00351 //fails with 1 grade hidden. still reports 8 as being correct 00352 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEAN, 'GRADE_AGGREGATE_MEAN', 8, 10); 00353 00354 //fails with 1 grade hidden. still reports 4 as being correct 00355 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MIN, 'GRADE_AGGREGATE_MIN', 4, 8); 00356 00357 //fails with 1 grade hidden. still reports 12 as being correct 00358 $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_SUM, 'GRADE_AGGREGATE_SUM', 12, 10); 00359 } 00360 00372 function helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, $aggmethod, $aggmethodname, $correct1, $correct2) { 00373 global $DB; 00374 00375 $grade_category->aggregation = $aggmethod; 00376 $grade_category->update(); 00377 00378 //check grade_item isnt hidden from a previous test 00379 $grade_items[0]->set_hidden(0, true); 00380 $this->helper_test_grade_aggregation_result($grade_category, $correct1, 'Testing aggregation method('.$aggmethodname.') with no items hidden %s'); 00381 00382 //hide the grade item with grade of 2 00383 $grade_items[0]->set_hidden(1, true); 00384 $this->helper_test_grade_aggregation_result($grade_category, $correct2, 'Testing aggregation method('.$aggmethodname.') with 1 item hidden %s'); 00385 } 00386 00394 function helper_test_grade_aggregation_result($grade_category, $correctgrade, $msg) { 00395 global $DB; 00396 00397 $category_grade_item = $grade_category->get_grade_item(); 00398 00399 //this creates all the grade_grades we need 00400 grade_regrade_final_grades($this->courseid); 00401 00402 $grade = $DB->get_record('grade_grades', array('itemid'=>$category_grade_item->id, 'userid'=>$this->userid)); 00403 $this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax); 00404 $this->assertEqual(intval($correctgrade), intval($grade->finalgrade), $msg); 00405 00406 /* 00407 * TODO this doesnt work as the grade_grades created by $grade_category->generate_grades(); dont 00408 * observe the category's max grade 00409 //delete the grade_grades for the category itself and check they get recreated correctly 00410 $DB->delete_records('grade_grades', array('itemid'=>$category_grade_item->id)); 00411 $grade_category->generate_grades(); 00412 00413 $grade = $DB->get_record('grade_grades', array('itemid'=>$category_grade_item->id, 'userid'=>$this->userid)); 00414 $this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax); 00415 $this->assertEqual(intval($correctgrade), intval($grade->finalgrade), $msg); 00416 * 00417 */ 00418 } 00419 00420 function sub_test_grade_category_aggregate_grades() { 00421 $category = new grade_category($this->grade_categories[0]); 00422 $this->assertTrue(method_exists($category, 'aggregate_grades')); 00423 // tested more fully via test_grade_category_generate_grades() 00424 } 00425 00426 function sub_test_grade_category_apply_limit_rules() { 00427 $items[$this->grade_items[0]->id] = new grade_item($this->grade_items[0], false); 00428 $items[$this->grade_items[1]->id] = new grade_item($this->grade_items[1], false); 00429 $items[$this->grade_items[2]->id] = new grade_item($this->grade_items[2], false); 00430 $items[$this->grade_items[4]->id] = new grade_item($this->grade_items[4], false); 00431 00432 $category = new grade_category(); 00433 $category->droplow = 2; 00434 $grades = array($this->grade_items[0]->id=>5.374, 00435 $this->grade_items[1]->id=>9.4743, 00436 $this->grade_items[2]->id=>2.5474, 00437 $this->grade_items[4]->id=>7.3754); 00438 $category->apply_limit_rules($grades, $items); 00439 $this->assertEqual(count($grades), 2); 00440 $this->assertEqual($grades[$this->grade_items[1]->id], 9.4743); 00441 $this->assertEqual($grades[$this->grade_items[4]->id], 7.3754); 00442 00443 $category = new grade_category(); 00444 $category->keephigh = 1; 00445 $category->droplow = 0; 00446 $grades = array($this->grade_items[0]->id=>5.374, 00447 $this->grade_items[1]->id=>9.4743, 00448 $this->grade_items[2]->id=>2.5474, 00449 $this->grade_items[4]->id=>7.3754); 00450 $category->apply_limit_rules($grades, $items); 00451 $this->assertEqual(count($grades), 1); 00452 $grade = reset($grades); 00453 $this->assertEqual(9.4743, $grade); 00454 00455 $category = new grade_category(); 00456 $category->droplow = 2; 00457 $category->aggregation = GRADE_AGGREGATE_SUM; 00458 $items[$this->grade_items[2]->id]->aggregationcoef = 1; 00459 $grades = array($this->grade_items[0]->id=>5.374, 00460 $this->grade_items[1]->id=>9.4743, 00461 $this->grade_items[2]->id=>2.5474, 00462 $this->grade_items[4]->id=>7.3754); 00463 00464 $category->apply_limit_rules($grades, $items); 00465 $this->assertEqual(count($grades), 2); 00466 $this->assertEqual($grades[$this->grade_items[1]->id], 9.4743); 00467 $this->assertEqual($grades[$this->grade_items[2]->id], 2.5474); 00468 00469 $category = new grade_category(); 00470 $category->keephigh = 1; 00471 $category->droplow = 0; 00472 $category->aggregation = GRADE_AGGREGATE_SUM; 00473 $items[$this->grade_items[2]->id]->aggregationcoef = 1; 00474 $grades = array($this->grade_items[0]->id=>5.374, 00475 $this->grade_items[1]->id=>9.4743, 00476 $this->grade_items[2]->id=>2.5474, 00477 $this->grade_items[4]->id=>7.3754); 00478 $category->apply_limit_rules($grades, $items); 00479 $this->assertEqual(count($grades), 2); 00480 $this->assertEqual($grades[$this->grade_items[1]->id], 9.4743); 00481 $this->assertEqual($grades[$this->grade_items[2]->id], 2.5474); 00482 } 00483 00487 function sub_test_grade_category_is_aggregationcoef_used() { 00488 00489 } 00490 00491 function sub_test_grade_category_fetch_course_tree() { 00492 $category = new grade_category(); 00493 $this->assertTrue(method_exists($category, 'fetch_course_tree')); 00494 //TODO: add some tests 00495 } 00496 00497 function sub_test_grade_category_get_children() { 00498 $course_category = grade_category::fetch_course_category($this->courseid); 00499 00500 $category = new grade_category($this->grade_categories[0]); 00501 $this->assertTrue(method_exists($category, 'get_children')); 00502 00503 $children_array = $category->get_children(0); 00504 00505 $this->assertTrue(is_array($children_array)); 00506 $this->assertFalse(empty($children_array[2])); 00507 $this->assertFalse(empty($children_array[2]['object'])); 00508 $this->assertFalse(empty($children_array[2]['children'])); 00509 $this->assertEqual($this->grade_categories[1]->id, $children_array[2]['object']->id); 00510 $this->assertEqual($this->grade_categories[2]->id, $children_array[5]['object']->id); 00511 $this->assertEqual($this->grade_items[0]->id, $children_array[2]['children'][3]['object']->id); 00512 $this->assertEqual($this->grade_items[1]->id, $children_array[2]['children'][4]['object']->id); 00513 $this->assertEqual($this->grade_items[2]->id, $children_array[5]['children'][6]['object']->id); 00514 } 00515 00516 function sub_test_grade_category_load_grade_item() { 00517 $category = new grade_category($this->grade_categories[0]); 00518 $this->assertTrue(method_exists($category, 'load_grade_item')); 00519 $this->assertEqual(null, $category->grade_item); 00520 $category->load_grade_item(); 00521 $this->assertEqual($this->grade_items[3]->id, $category->grade_item->id); 00522 } 00523 00524 function sub_test_grade_category_get_grade_item() { 00525 $category = new grade_category($this->grade_categories[0]); 00526 $this->assertTrue(method_exists($category, 'get_grade_item')); 00527 $grade_item = $category->get_grade_item(); 00528 $this->assertEqual($this->grade_items[3]->id, $grade_item->id); 00529 } 00530 00531 function sub_test_grade_category_load_parent_category() { 00532 $category = new grade_category($this->grade_categories[1]); 00533 $this->assertTrue(method_exists($category, 'load_parent_category')); 00534 $this->assertEqual(null, $category->parent_category); 00535 $category->load_parent_category(); 00536 $this->assertEqual($this->grade_categories[0]->id, $category->parent_category->id); 00537 } 00538 00539 function sub_test_grade_category_get_parent_category() { 00540 $category = new grade_category($this->grade_categories[1]); 00541 $this->assertTrue(method_exists($category, 'get_parent_category')); 00542 $parent_category = $category->get_parent_category(); 00543 $this->assertEqual($this->grade_categories[0]->id, $parent_category->id); 00544 } 00545 00546 function sub_test_grade_category_get_name() { 00547 $category = new grade_category($this->grade_categories[0]); 00548 $this->assertTrue(method_exists($category, 'get_name')); 00549 $this->assertEqual($this->grade_categories[0]->fullname, $category->get_name()); 00550 } 00551 00552 function sub_test_grade_category_set_parent() { 00553 $category = new grade_category($this->grade_categories[1]); 00554 $this->assertTrue(method_exists($category, 'set_parent')); 00555 // TODO: implement detailed tests 00556 00557 $course_category = grade_category::fetch_course_category($this->courseid); 00558 $this->assertTrue($category->set_parent($course_category->id)); 00559 $this->assertEqual($course_category->id, $category->parent); 00560 } 00561 00562 function sub_test_grade_category_get_final() { 00563 $category = new grade_category($this->grade_categories[0]); 00564 $this->assertTrue(method_exists($category, 'get_final')); 00565 $category->load_grade_item(); 00566 $this->assertEqual($category->get_final(), $category->grade_item->get_final()); 00567 } 00568 00569 function sub_test_grade_category_get_sortorder() { 00570 $category = new grade_category($this->grade_categories[0]); 00571 $this->assertTrue(method_exists($category, 'get_sortorder')); 00572 $category->load_grade_item(); 00573 $this->assertEqual($category->get_sortorder(), $category->grade_item->get_sortorder()); 00574 } 00575 00576 function sub_test_grade_category_set_sortorder() { 00577 $category = new grade_category($this->grade_categories[0]); 00578 $this->assertTrue(method_exists($category, 'set_sortorder')); 00579 $category->load_grade_item(); 00580 $this->assertEqual($category->set_sortorder(10), $category->grade_item->set_sortorder(10)); 00581 } 00582 00583 function sub_test_grade_category_move_after_sortorder() { 00584 $category = new grade_category($this->grade_categories[0]); 00585 $this->assertTrue(method_exists($category, 'move_after_sortorder')); 00586 $category->load_grade_item(); 00587 $this->assertEqual($category->move_after_sortorder(10), $category->grade_item->move_after_sortorder(10)); 00588 } 00589 00590 function sub_test_grade_category_is_course_category() { 00591 $category = grade_category::fetch_course_category($this->courseid); 00592 $this->assertTrue(method_exists($category, 'is_course_category')); 00593 $this->assertTrue($category->is_course_category()); 00594 } 00595 00596 function sub_test_grade_category_fetch_course_category() { 00597 $category = new grade_category(); 00598 $this->assertTrue(method_exists($category, 'fetch_course_category')); 00599 $category = grade_category::fetch_course_category($this->courseid); 00600 $this->assertTrue(empty($category->parent)); 00601 } 00605 function sub_test_grade_category_is_editable() { 00606 00607 } 00608 00609 function sub_test_grade_category_is_locked() { 00610 $category = new grade_category($this->grade_categories[0]); 00611 $this->assertTrue(method_exists($category, 'is_locked')); 00612 $category->load_grade_item(); 00613 $this->assertEqual($category->is_locked(), $category->grade_item->is_locked()); 00614 } 00615 00616 function sub_test_grade_category_set_locked() { 00617 $category = new grade_category($this->grade_categories[0]); 00618 $this->assertTrue(method_exists($category, 'set_locked')); 00619 00620 //will return false as cannot lock a grade that needs updating 00621 $this->assertFalse($category->set_locked(1)); 00622 grade_regrade_final_grades($this->courseid); 00623 00624 //get the category from the db again 00625 $category = new grade_category($this->grade_categories[0]); 00626 $this->assertTrue($category->set_locked(1)); 00627 } 00628 00629 function sub_test_grade_category_is_hidden() { 00630 $category = new grade_category($this->grade_categories[0]); 00631 $this->assertTrue(method_exists($category, 'is_hidden')); 00632 $category->load_grade_item(); 00633 $this->assertEqual($category->is_hidden(), $category->grade_item->is_hidden()); 00634 } 00635 00636 function sub_test_grade_category_set_hidden() { 00637 $category = new grade_category($this->grade_categories[0]); 00638 $this->assertTrue(method_exists($category, 'set_hidden')); 00639 $category->set_hidden(1); 00640 $category->load_grade_item(); 00641 $this->assertEqual(true, $category->grade_item->is_hidden()); 00642 } 00643 00644 //beware: adding a duplicate course category messes up the data in a way that's hard to recover from 00645 function sub_test_grade_category_insert_course_category() { 00646 $grade_category = new grade_category(); 00647 $this->assertTrue(method_exists($grade_category, 'insert_course_category')); 00648 00649 $id = $grade_category->insert_course_category($this->courseid); 00650 $this->assertNotNull($id); 00651 $this->assertEqual('?', $grade_category->fullname); 00652 $this->assertEqual(GRADE_AGGREGATE_WEIGHTED_MEAN2, $grade_category->aggregation); 00653 $this->assertEqual("/$id/", $grade_category->path); 00654 $this->assertEqual(1, $grade_category->depth); 00655 $this->assertNull($grade_category->parent); 00656 } 00657 00658 function generate_random_raw_grade($item, $userid) { 00659 $grade = new grade_grade(); 00660 $grade->itemid = $item->id; 00661 $grade->userid = $userid; 00662 $grade->grademin = 0; 00663 $grade->grademax = 1; 00664 $valuetype = "grade$item->gradetype"; 00665 $grade->rawgrade = rand(0, 1000) / 1000; 00666 $grade->insert(); 00667 return $grade->rawgrade; 00668 } 00669 }