]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Corrected a number of small errors in unit tests and classes.
authornicolasconnault <nicolasconnault>
Mon, 28 May 2007 01:26:58 +0000 (01:26 +0000)
committernicolasconnault <nicolasconnault>
Mon, 28 May 2007 01:26:58 +0000 (01:26 +0000)
lib/grade/grade_category.php
lib/grade/grade_grades_final.php
lib/grade/grade_item.php
lib/grade/grade_object.php
lib/simpletest/grade/simpletest/testgradecategory.php
lib/simpletest/grade/simpletest/testgradefinal.php
lib/simpletest/testgradelib.php

index 99f7f0dd092a003c53a096776208e4e9a81eba20..da422fd1390cea58d48a1541c488ec63b19c37b0 100644 (file)
@@ -738,7 +738,10 @@ class grade_category extends grade_object {
                 debugging("Violated constraint: Attempted to set a category as a parent over children of 2 different types.");
                 return false;
             }
-            if (grade_tree::get_element_type($child) == 'topcat') {
+            
+            $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;
             }
index 713113ffd064d42d04b5fa76ab1a178acc96b8d6..7547b1c3356bc5550bb4e99c4339010f9b59ff62 100644 (file)
@@ -159,6 +159,9 @@ class grade_grades_final extends grade_object {
     function insert() {
         $exists = count_records('grade_grades_final', 'userid', $this->userid, 'itemid', $this->itemid);
         if ($exists) {
+            // Retrieve id number from DB
+            $record = get_record('grade_grades_final', 'userid', $this->userid, 'itemid', $this->itemid); 
+            $this->id = $record->id;
             return $this->update();
         } else {
             return parent::insert();
index 55f06296c3e1920d820d8adcd901c210b95dd65c..9358d56a2db3db0e258cbb486733095e476bd0d6 100644 (file)
@@ -221,7 +221,11 @@ class grade_item extends grade_object {
     function load_scale() {
         if (!empty($this->scaleid)) {
             $this->scale = grade_scale::fetch('id', $this->scaleid);
-            $this->scale->load_items();
+            if (method_exists($this->scale, 'load_items')) {
+                $this->scale->load_items();
+            } else { 
+                $this->scale = null;
+            } 
         } 
         return $this->scale;
     }
@@ -355,6 +359,12 @@ class grade_item extends grade_object {
         // Retrieve scale and infer grademax from it
         if (!empty($this->scaleid)) {
             $this->load_scale();
+
+            if (!method_exists($this->scale, 'load_items')) {
+                debugging("The scale referenced by this grade_item ($this->scaleid) does not exist in the database. Grademax cannot be infered from the missing scale.");
+                return false;
+            }
+
             $this->scale->load_items();
             $this->grademax = count ($this->scale->scale_items);
             $this->grademin = 0;
index 5b87aff59554c1523d012e6f449ca96c9d574bda..aa8aea5b86f9a5d08d2f4ef16ff97d4bccbf23b5 100644 (file)
@@ -112,12 +112,12 @@ class grade_object {
         }
 
         $this->timecreated = $this->timemodified = time();
-
+        
         if (empty($this->usermodified)) {
             $this->usermodified = $USER->id;
         }
 
-        $clonethis = clone($this);
+        $clonethis = fullclone($this);
 
         // Unset non-set fields
         foreach ($clonethis as $var => $val) {
index 7e30f213cc0430cbb50219b730629e0efcb7c214..7fb900a87f5a7fe0439f4b6dea40a3c1ab3d8e9e 100755 (executable)
@@ -83,7 +83,7 @@ class grade_category_test extends gradelib_test {
         $grade_category->parent      = $this->grade_categories[0]->id;
 
         $grade_category->insert();
-
+        
         $last_grade_category = end($this->grade_categories);
         
         $this->assertFalse(empty($grade_category->grade_item));
@@ -194,7 +194,7 @@ class grade_category_test extends gradelib_test {
         
         for ($i = 0; $i < 3; $i++) {
             for ($j = 0; $j < 200; $j++) {
-                $grade_sets[$i][] = $this->generate_random_raw_grade($this->grade_items[$i], $j);
+                $grade_sets[$i][] = $this->generate_random_raw_grade(new grade_item($this->grade_items[$i]), $j);
             }
         }
         
index f4a76faa20f437dfafc3096edcdf46c36a78288e..1cc32963d55a212822af3281e02181284564f31f 100644 (file)
@@ -53,14 +53,14 @@ class grade_final_test extends gradelib_test {
         $this->assertTrue(method_exists($grade_grades_final, 'insert'));
         
         $grade_grades_final->itemid = $this->grade_items[0]->id;
-        $grade_grades_final->userid = 1;
+        $grade_grades_final->userid = 4;
         $grade_grades_final->gradevalue = 88;
 
-        $grade_grades_final->insert();
+        $this->assertTrue($grade_grades_final->insert()); 
 
         $last_grade_grades_final = end($this->grade_grades_final);
 
-        $this->assertEqual($grade_grades_final->id, $last_grade_grades_final->id + 1);
+        $this->assertEqual($last_grade_grades_final->id + 1, $grade_grades_final->id);
         $this->assertFalse(empty($grade_grades_final->timecreated));
         $this->assertFalse(empty($grade_grades_final->timemodified));
     }
index 0ad1eb3442253802269004151da9db2c856eb23f..9512fee60912de8054dbbd6be3989a2d25fdc967 100644 (file)
@@ -54,9 +54,9 @@ class gradelib_test extends UnitTestCase {
      * crucial, because of the interrelationships between objects.
      */
     var $tables = array('grade_categories',
+                        'scale',
                         'grade_items',
                         'grade_calculations',
-                        'scale',
                         'grade_grades_raw',
                         'grade_grades_final',
                         'grade_grades_text',
@@ -375,6 +375,72 @@ class gradelib_test extends UnitTestCase {
         }
     }
    
+    /**
+     * Load scale data into the database, and adds the corresponding objects to this class' variable.
+     */
+    function load_scale() {
+        $scale = new stdClass();
+        
+        $scale->name        = 'unittestscale1';
+        $scale->courseid    = $this->courseid;
+        $scale->userid      = $this->userid;
+        $scale->scale       = 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
+        $scale->description = 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
+        $scale->timemodified = mktime();
+        
+        if ($scale->id = insert_record('scale', $scale)) {
+            $this->scale[] = $scale;
+        } 
+
+        $scale = new stdClass();
+        
+        $scale->name        = 'unittestscale2';
+        $scale->courseid    = $this->courseid;
+        $scale->userid      = $this->userid;
+        $scale->scale       = 'Distinction, Very Good, Good, Pass, Fail';
+        $scale->description = 'This scale is used to mark standard assignments.';
+        $scale->timemodified = mktime();
+        
+        if ($scale->id = insert_record('scale', $scale)) {
+            $this->scale[] = $scale;
+        } 
+
+        $scale = new stdClass();
+        
+        $scale->name        = 'unittestscale3';
+        $scale->courseid    = $this->courseid;
+        $scale->userid      = $this->userid;
+        $scale->scale       = 'Loner, Contentious, Disinterested, Participative, Follower, Leader';
+        $scale->description = 'Describes the level of teamwork of a student.';
+        $scale->timemodified = mktime();
+        
+        if ($scale->id = insert_record('scale', $scale)) {
+            $this->scale[] = $scale;
+        } 
+
+        $scale->name        = 'unittestscale4';
+        $scale->courseid    = $this->courseid;
+        $scale->userid      = $this->userid;
+        $scale->scale       = 'Does not understand theory, Understands theory but fails practice, Manages through, Excels';
+        $scale->description = 'Level of expertise at a technical task, with a theoretical framework.';
+        $scale->timemodified = mktime();
+        
+        if ($scale->id = insert_record('scale', $scale)) {
+            $this->scale[] = $scale;
+        }
+
+        $scale->name        = 'unittestscale5';
+        $scale->courseid    = $this->courseid;
+        $scale->userid      = $this->userid;
+        $scale->scale       = 'Insufficient, Acceptable, Excellent.';
+        $scale->description = 'Description of skills.';
+        $scale->timemodified = mktime();
+        
+        if ($scale->id = insert_record('scale', $scale)) {
+            $this->scale[] = $scale;
+        }
+    }
+
     /**
      * Load grade_category data into the database, and adds the corresponding objects to this class' variable.
      */
@@ -507,7 +573,7 @@ class gradelib_test extends UnitTestCase {
         $grade_item->itemmodule = 'forum';
         $grade_item->iteminstance = 3;
         $grade_item->gradetype = GRADE_TYPE_SCALE;
-        $grade_item->scaleid = 1;
+        $grade_item->scaleid = $this->scale[0]->id;
         $grade_item->grademin = 0;
         $grade_item->grademax = 7;
         $grade_item->iteminfo = 'Grade item used for unit testing';
@@ -609,7 +675,7 @@ class gradelib_test extends UnitTestCase {
         $grade_item->itemmodule = 'forum';
         $grade_item->iteminstance = 3;
         $grade_item->gradetype = GRADE_TYPE_SCALE;
-        $grade_item->scaleid = 1;
+        $grade_item->scaleid = $this->scale[0]->id;
         $grade_item->grademin = 0;
         $grade_item->grademax = 7;
         $grade_item->iteminfo = 'Grade item used for unit testing';
@@ -707,72 +773,6 @@ class gradelib_test extends UnitTestCase {
         } 
     }
 
-    /**
-     * Load scale data into the database, and adds the corresponding objects to this class' variable.
-     */
-    function load_scale() {
-        $scale = new stdClass();
-        
-        $scale->name        = 'unittestscale1';
-        $scale->courseid    = $this->courseid;
-        $scale->userid      = $this->userid;
-        $scale->scale       = 'Way off topic, Not very helpful, Fairly neutral, Fairly helpful, Supportive, Some good information, Perfect answer!';
-        $scale->description = 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
-        $scale->timemodified = mktime();
-        
-        if ($scale->id = insert_record('scale', $scale)) {
-            $this->scale[] = $scale;
-        } 
-
-        $scale = new stdClass();
-        
-        $scale->name        = 'unittestscale2';
-        $scale->courseid    = $this->courseid;
-        $scale->userid      = $this->userid;
-        $scale->scale       = 'Distinction, Very Good, Good, Pass, Fail';
-        $scale->description = 'This scale is used to mark standard assignments.';
-        $scale->timemodified = mktime();
-        
-        if ($scale->id = insert_record('scale', $scale)) {
-            $this->scale[] = $scale;
-        } 
-
-        $scale = new stdClass();
-        
-        $scale->name        = 'unittestscale3';
-        $scale->courseid    = $this->courseid;
-        $scale->userid      = $this->userid;
-        $scale->scale       = 'Loner, Contentious, Disinterested, Participative, Follower, Leader';
-        $scale->description = 'Describes the level of teamwork of a student.';
-        $scale->timemodified = mktime();
-        
-        if ($scale->id = insert_record('scale', $scale)) {
-            $this->scale[] = $scale;
-        } 
-
-        $scale->name        = 'unittestscale4';
-        $scale->courseid    = $this->courseid;
-        $scale->userid      = $this->userid;
-        $scale->scale       = 'Does not understand theory, Understands theory but fails practice, Manages through, Excels';
-        $scale->description = 'Level of expertise at a technical task, with a theoretical framework.';
-        $scale->timemodified = mktime();
-        
-        if ($scale->id = insert_record('scale', $scale)) {
-            $this->scale[] = $scale;
-        }
-
-        $scale->name        = 'unittestscale5';
-        $scale->courseid    = $this->courseid;
-        $scale->userid      = $this->userid;
-        $scale->scale       = 'Insufficient, Acceptable, Excellent.';
-        $scale->description = 'Description of skills.';
-        $scale->timemodified = mktime();
-        
-        if ($scale->id = insert_record('scale', $scale)) {
-            $this->scale[] = $scale;
-        }
-    }
-
     /**
      * Load grade_grades_raw data into the database, and adds the corresponding objects to this class' variable.
      */