From: skodak Date: Sun, 10 Jun 2007 21:17:42 +0000 (+0000) Subject: MDL-10078 unit tests for grade category failing on set_as_parent() X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9f9afbdbaba0d13e557ceee56ce38a8dc41cd0a4;p=moodle.git MDL-10078 unit tests for grade category failing on set_as_parent() --- diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 21eba83a87..1694dec0cf 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -750,7 +750,13 @@ class grade_category extends grade_object { // Check type and sortorder of first child $first_child = current($children); $first_child_type = get_class($first_child); - $first_child_courseid = $first_child->courseid; + + // If this->courseid is not set, set it to the first child's courseid + if (empty($this->courseid)) { + $this->courseid = $first_child->courseid; + } + + $grade_tree = new grade_tree(); foreach ($children as $child) { if (get_class($child) != $first_child_type) { @@ -758,14 +764,12 @@ class grade_category extends grade_object { return false; } - $grade_tree = new grade_tree(); - if ($grade_tree->get_element_type($child) == 'topcat') { debugging("Violated constraint: Attempted to set a category over children which are already top categories."); return false; } - if ($first_child_type == 'grade_category') { + if ($first_child_type == 'grade_category' or $first_child_type == 'grade_item') { if (!empty($child->parent)) { debugging("Violated constraint: Attempted to set a category over children that already have a top category."); return false; @@ -775,7 +779,7 @@ class grade_category extends grade_object { return false; } - if ($child->courseid != $first_child_courseid) { + if ($child->courseid != $this->courseid) { debugging("Attempted to set a category over children which do not belong to the same course."); return false; } @@ -795,11 +799,6 @@ class grade_category extends grade_object { $this->load_grade_item(); $this->grade_item->sortorder = $first_child->get_sortorder(); - // If this->courseid is not set, set it to the first child's courseid - if (empty($this->courseid)) { - $this->courseid = $first_child_courseid; - } - if (!$this->update()) { debugging("Could not update this category's sortorder in DB."); return false; diff --git a/lib/simpletest/grade/simpletest/testgradecategory.php b/lib/simpletest/grade/simpletest/testgradecategory.php index 7454fa9a6f..647c5b0a1c 100755 --- a/lib/simpletest/grade/simpletest/testgradecategory.php +++ b/lib/simpletest/grade/simpletest/testgradecategory.php @@ -262,6 +262,8 @@ class grade_category_test extends grade_test { $child2->itemname = 'new grade_item'; $child1->sortorder = 1; $child2->sortorder = 2; + $child1->courseid = $grade_category->courseid; + $child2->courseid = $grade_category->courseid; $child1->insert(); $child2->insert(); $this->assertTrue($grade_category->set_as_parent(array($child1, $child2)));