]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Reorganised unit tests a bit, added some stubs and tests for grade_category...
authornicolasconnault <nicolasconnault>
Wed, 16 May 2007 03:17:46 +0000 (03:17 +0000)
committernicolasconnault <nicolasconnault>
Wed, 16 May 2007 03:17:46 +0000 (03:17 +0000)
lib/grade/grade_category.php
lib/simpletest/grade/simpletest/testgradecategory.php

index b85aae526fb7091619f1edfe1a6b21ba7f83448c..ff59c1414e26960c01266d69676cf7c098217fa5 100644 (file)
@@ -650,6 +650,7 @@ class grade_category extends grade_object {
     /**
      * Static method that returns a sorted, nested array of all grade_categories and grade_items for 
      * a given course, or for the entire site if no courseid is given.
+     * @static
      * @param int $courseid
      * @param boolean $fullobjects Whether to instantiate full objects based on the data or not
      * @return array
@@ -780,6 +781,7 @@ class grade_category extends grade_object {
      * Returns a hierarchical array, prefilled with the values needed to populate
      * the tree of grade_items in the cases where a grade_item or grade_category doesn't have a 
      * 2nd level topcategory.
+     * @static
      * @param object $object A grade_item or a grade_category object
      * @param boolean $fullobjects Whether to instantiate full objects or just return stdClass objects
      * @return array
@@ -789,20 +791,27 @@ class grade_category extends grade_object {
 
         // Depending on whether the filler is for a grade_item or a category...
         if (isset($object->itemname)) {
+            if (get_class($object) == 'grade_item') {
+                $finals = $object->load_final();
+            } else {
+                $item_object = new grade_item($object, false);
+                $finals = $object->load_final();
+            }
+
             $filler_array = array('object' => 'filler', 'children' => 
                 array(0 => array('object' => 'filler', 'children' => 
-                    array(0 => array('object' => $object, 'finalgrades' => null))))); 
+                    array(0 => array('object' => $object, 'finalgrades' => $finals))))); 
         } else {
             $subcat_children = $object->get_children(0, 'flat');
             $children_for_tree = array();
             foreach ($subcat_children as $itemid => $item) {
-                if ($fullobjects) {
-                    $final = new grade_grades_final();
-                    $final->itemid = $itemid;
-                    $finals = $final->fetch_all_using_this();
+                if (get_class($item) == 'grade_item') {
+                    $finals = $item->load_final();
                 } else {
-                    $finals = get_records('grade_grades_final', 'itemid', $itemid);
+                    $item_object = new grade_item($item, false);
+                    $finals = $item->load_final();
                 }
+                
                 $children_for_tree[$itemid] = array('object' => $item, 'finalgrades' => $finals); 
             }
 
@@ -821,6 +830,7 @@ class grade_category extends grade_object {
      * @todo Return icons
      * @todo Return totals
      * @todo Return row below headers for grading range
+     * @static
      * @param int $courseid
      * @return string HTML table
      */
index a4ecd93e87531473a72b2fbe00d5b681ee5b28b2..80695e5ea91818f53397f15ff144a7511466c44c 100755 (executable)
@@ -219,12 +219,18 @@ class grade_category_test extends gradelib_test {
     }
 
     function test_grade_category_display_grades() {
-        $result_html = grade_category::display_grades();
+        $result_html = grade_category::display_grades($this->courseid);
         $expected_html = '<table style="text-align: center" border="1"><tr><th colspan="3">unittestcategory1</th><td class="topfiller">&nbsp;</td><td colspan="2" class="topfiller">&nbsp;</td></tr><tr><td colspan="2">unittestcategory2</td><td colspan="1">unittestcategory3</td><td class="subfiller">&nbsp;</td><td colspan="2">level1category</td></tr><tr><td>unittestgradeitem1</td><td>unittestgradeitem2</td><td>unittestgradeitem3</td><td>unittestorphangradeitem1</td><td>singleparentitem1</td><td>singleparentitem2</td></tr></table>';
         $this->assertEqual($expected_html, $result_html);
     }
 
-    function test_grade_category_build_tree() {
+    function test_grade_category_get_tree() {
+        $result_tree = grade_category::get_tree($this->courseid);
+        $result_count = count($result_tree, COUNT_RECURSIVE);
+        $this->assertEqual(58, $result_count);
+    }
+
+    function test_grade_category_get_filler() {
 
     }
 }