]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10078 unit tests for grade category failing on set_as_parent()
authorskodak <skodak>
Sun, 10 Jun 2007 21:17:42 +0000 (21:17 +0000)
committerskodak <skodak>
Sun, 10 Jun 2007 21:17:42 +0000 (21:17 +0000)
lib/grade/grade_category.php
lib/simpletest/grade/simpletest/testgradecategory.php

index 21eba83a877c0a16eb86f5676e06daf37ee8cf05..1694dec0cfbbf786ea5bc5954e05c6ab2be9f146 100644 (file)
@@ -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;
index 7454fa9a6f3e254cf4c375121a62560cbcedef29..647c5b0a1c86091482ea556c6a08e327882c2e18 100755 (executable)
@@ -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)));