From c78b0cc59a6d99b5f2d11e3a47ff4e9080fbc0ba Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 16 May 2007 03:17:46 +0000 Subject: [PATCH] MDL-9506 Reorganised unit tests a bit, added some stubs and tests for grade_category, and corrected missing grade_finals for orphan grade_items and categories. --- lib/grade/grade_category.php | 22 ++++++++++++++----- .../grade/simpletest/testgradecategory.php | 10 +++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index b85aae526f..ff59c1414e 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -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 */ diff --git a/lib/simpletest/grade/simpletest/testgradecategory.php b/lib/simpletest/grade/simpletest/testgradecategory.php index a4ecd93e87..80695e5ea9 100755 --- a/lib/simpletest/grade/simpletest/testgradecategory.php +++ b/lib/simpletest/grade/simpletest/testgradecategory.php @@ -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 = '
unittestcategory1  
unittestcategory2unittestcategory3 level1category
unittestgradeitem1unittestgradeitem2unittestgradeitem3unittestorphangradeitem1singleparentitem1singleparentitem2
'; $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() { } } -- 2.39.5