]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9506 Moved unit tests in a simpletest subfolder so they can be automatically...
authornicolasconnault <nicolasconnault>
Fri, 4 May 2007 07:40:51 +0000 (07:40 +0000)
committernicolasconnault <nicolasconnault>
Fri, 4 May 2007 07:40:51 +0000 (07:40 +0000)
15 files changed:
lib/grade/grade_grades_raw.php
lib/grade/grade_grades_text.php [new file with mode: 0644]
lib/grade/grade_history.php [new file with mode: 0644]
lib/grade/grade_object.php
lib/grade/grade_outcome.php
lib/grade/grade_scale.php
lib/gradelib.php
lib/simpletest/grade/simpletest/testgradecalculation.php [new file with mode: 0644]
lib/simpletest/grade/simpletest/testgradefinal.php [new file with mode: 0644]
lib/simpletest/grade/simpletest/testgradehistory.php [new file with mode: 0644]
lib/simpletest/grade/simpletest/testgradeoutcome.php [new file with mode: 0644]
lib/simpletest/grade/simpletest/testgraderaw.php
lib/simpletest/grade/simpletest/testgradescale.php
lib/simpletest/grade/simpletest/testgradetext.php [new file with mode: 0755]
lib/simpletest/testgradelib.php

index f79a07b46fa23be76f4de90287d6c8c751d5c098..64d5e20a2839b02ef744b45fb12a79c61629c24b 100644 (file)
@@ -93,6 +93,14 @@ class grade_grades_raw extends grade_object {
      */
     var $usermodified;
 
+    /**
+     * Additional textual information about this grade. It can be automatically generated 
+     * from the module or entered manually by the teacher. This is kept in its own table
+     * for efficiency reasons, so it is encapsulated in its own object, and included in this raw grade object.
+     * @var object $text
+     */
+    var $text;
+
     /**
      * Constructor. Extends the basic functionality defined in grade_object.
      * @param array $params Can also be a standard object.
@@ -104,8 +112,20 @@ class grade_grades_raw extends grade_object {
             $this->scale = new grade_scale(array('id' => $this->scaleid));
             $this->scale->load_items();
         }
-    }
 
+        // Load text object
+        $this->load_text();
+    }
+    
+    /**
+     * Loads the grade_grades_text object linked to this raw grade, into the $this->text variable, if 
+     * such record exists. Otherwise returns null.
+     */
+    function load_text() {
+        if (!empty($this->id)) {
+            $this->text = grade_grades_text::fetch('gradesid', $this->id);
+        }
+    }
 
     /**
      * Finds and returns a grade_grades_raw object based on 1-3 field values.
@@ -125,15 +145,50 @@ class grade_grades_raw extends grade_object {
                 foreach ($object as $param => $value) {
                     $this->$param = $value;
                 }
+                
+                $this->load_text();
                 return $this;
             } else {
                 $object = new grade_grades_raw($object);
+
+                $object->load_text();
                 return $object;
             }
         } else {
             return false;
         }
     } 
+    
+    /**
+     * Updates this grade with the given textual information. This will create a new grade_grades_text entry
+     * if none was previously in DB for this raw grade, or will update the existing one.
+     * @param string $information Further info like forum rating distribution 4/5/7/0/1
+     * @param int $informationformat Text format for information
+     * @param string $feedback Manual feedback from the teacher. Could be a code like 'mi'.
+     * @param int $feedbackformat Text format for the feedback
+     * @return boolean Success or Failure
+     */
+    function annotate($information, $informationformat=FORMAT_PLAIN, $feedback=NULL, $feedbackformat=FORMAT_PLAIN) {
+        $grade_text = new grade_grades_text();
+
+        $grade_text->gradesid          = $this->id;
+        $grade_text->information       = $information;
+        $grade_text->informationformat = $informationformat;
+        $grade_text->feedback          = $feedback;
+        $grade_text->feedbackformat    = $feedbackformat;
+
+        $result = true;
+
+        if (empty($this->text)) {
+            $result = $grade_text->insert();
+        } else {
+            $result = $grade_text->update();
+        }
+
+        $this->text = $grade_text;
+
+        return $result;
+    }
 
     /**
      * In addition to the normal updating set up in grade_object, this object also records
@@ -155,19 +210,18 @@ class grade_grades_raw extends grade_object {
         }
 
         $result = parent::update();
-        
+       
+        // Update grade_grades_text if changed
+        if (!empty($this->text)) {
+            $grade_text = grade_grades_text::fetch('gradesid', $this->id);
+            if ($this->text != $grade_text && $this->text->id == $grade_text->id) {
+                $result = $result & $this->text->update();
+            }
+        }
+
         if ($result) {
-            $logentry = new stdClass();
-            $logentry->itemid = $this->itemid;
-            $logentry->userid = $this->userid;
-            $logentry->oldgrade = $oldgrade;
-            $logentry->newgrade = $this->gradevalue;
-            $logentry->note = $note;
-            $logentry->howmodified = $howmodified;
-            $logentry->timemodified = mktime();
-            $logentry->usermodified = $USER->id;
-
-            insert_record('grade_history', $logentry);
+            // TODO Handle history recording error, such as displaying a notice, but still return true
+            grade_history::insert_change($this, $oldgrade, $howmodified, $note);
             return true;
         } else {
             return false;
diff --git a/lib/grade/grade_grades_text.php b/lib/grade/grade_grades_text.php
new file mode 100644 (file)
index 0000000..f2e7a9d
--- /dev/null
@@ -0,0 +1,111 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 2001-2003  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once('grade_object.php');
+
+/**
+ * A text string used to compute the value displayed by a grade_item.
+ * There can be only one grade_text per grade_item (one-to-one).
+ */
+class grade_grades_text extends grade_object {
+    /**
+     * DB Table (used by grade_object).
+     * @var string $table
+     */
+    var $table = 'grade_grades_text';
+
+    /**
+     * Array of class variables that are not part of the DB table fields
+     * @var array $nonfields
+     */
+    var $nonfields = array('table', 'nonfields');
+    
+    /**
+     * A reference to the grade_grades_raw object this text belongs to.
+     * @var int $gradesid
+     */
+    var $gradesid;
+
+    /**
+     * Further information like forum rating distribution 4/5/7/0/1
+     * @var string $information
+     */
+    var $information;
+
+    /**
+     * Text format for information (FORMAT_PLAIN, FORMAT_HTML etc...).
+     * @var int $informationformat
+     */
+    var $informationformat;
+
+    /**
+     * Manual feedback from the teacher. This could be a code like 'mi'.
+     * @var string $feedback
+     */
+    var $feedback;
+
+    /**
+     * Text format for feedback (FORMAT_PLAIN, FORMAT_HTML etc...).
+     * @var int $feedbackformat
+     */
+    var $feedbackformat;
+
+    /**
+     * The userid of the person who last modified this text.
+     * @var int $usermodified
+     */
+    var $usermodified;
+    
+    /**
+     * Finds and returns a grade_text object based on 1-3 field values.
+     *
+     * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
+     * @param string $field1
+     * @param string $value1
+     * @param string $field2
+     * @param string $value2
+     * @param string $field3
+     * @param string $value3
+     * @param string $fields
+     * @return object grade_text object or false if none found.
+     */
+    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { 
+        if ($grade_text = get_record('grade_grades_text', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
+            if (isset($this) && get_class($this) == 'grade_grades_text') {
+                print_object($this);
+                foreach ($grade_text as $param => $value) {
+                    $this->$param = $value;
+                }
+                return $this;
+            } else {
+                $grade_text = new grade_grades_text($grade_text);
+                return $grade_text;
+            }
+        } else {
+            return false;
+        }
+    }
+}
+?>
diff --git a/lib/grade/grade_history.php b/lib/grade/grade_history.php
new file mode 100644 (file)
index 0000000..2ee1a36
--- /dev/null
@@ -0,0 +1,134 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.com                                            //
+//                                                                       //
+// Copyright (C) 2001-2003  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+require_once('grade_object.php');
+
+/**
+ * Class representing a grade history. It is responsible for handling its DB representation,
+ * modifying and returning its metadata.
+ */
+class grade_history extends grade_object {
+    /**
+     * DB Table (used by grade_object).
+     * @var string $table
+     */
+    var $table = 'grade_history';
+    
+    /**
+     * Array of class variables that are not part of the DB table fields
+     * @var array $nonfields
+     */
+    var $nonfields = array('table', 'nonfields');
+  
+    /**
+     * The grade_item whose raw grade is being changed.
+     * @var int $itemid
+     */
+    var $itemid;
+    
+    /**
+     * The user whose raw grade is being changed.
+     * @var int $userid
+     */
+    var $userid;
+    
+    /**
+     * The value of the grade before the change.
+     * @var float $oldgrade
+     */
+    var $oldgrade;
+
+    /**
+     * The value of the grade after the change.
+     * @var float $newgrade
+     */
+    var $newgrade;
+
+    /**
+     * An optional annotation to explain the change.
+     * @var string $note
+     */
+    var $note;
+    
+    /**
+     * How the grade was modified ('manual', 'module', 'import' etc...).
+     * @var string $howmodified
+     */
+    var $howmodified;
+    
+    /**
+     * Finds and returns a grade_history object based on 1-3 field values.
+     *
+     * @param string $field1
+     * @param string $value1
+     * @param string $field2
+     * @param string $value2
+     * @param string $field3
+     * @param string $value3
+     * @param string $fields
+     * @return object grade_history object or false if none found.
+     */
+    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { 
+        if ($grade_history = get_record('grade_history', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
+            if (isset($this) && get_class($this) == 'grade_history') {
+                foreach ($grade_history as $param => $value) {
+                    $this->$param = $value;
+                }
+                return $this;
+            } else {
+                $grade_history = new grade_history($grade_history);
+                return $grade_history;
+            }
+        } else {
+            return false;
+        }
+    } 
+
+    /**
+     * Given a grade_grades_raw object and some other parameters, records the 
+     * change of grade value for this object, and associated data.
+     * @static
+     * @param object $grade_raw
+     * @param float $oldgrade
+     * @param string $note
+     * @param string $howmodified
+     * @return boolean Success or Failure
+     */
+    function insert_change($grade_raw, $oldgrade, $howmodified='manual', $note=NULL) {
+        global $USER;
+        $history = new grade_history();
+        $history->itemid = $grade_raw->itemid;
+        $history->userid = $grade_raw->userid;
+        $history->oldgrade = $oldgrade;
+        $history->newgrade = $grade_raw->gradevalue;
+        $history->note = $note;
+        $history->howmodified = $howmodified;
+        $history->timemodified = mktime();
+        $history->usermodified = $USER->id;
+
+        return $history->insert();
+    } 
+}
+?>
index 02ed32cd8cf37111efbd3afea3ecf9f7c97a6b45..8ef6e192dffce7a99020d9c23e2ddfbba04976af 100644 (file)
@@ -82,10 +82,14 @@ class grade_object {
      * @return boolean
      */
     function update() {
-        $result = update_record($this->table, $this);
-        if ($result) {
-            $this->timemodified = mktime();
+        $this->timemodified = mktime();
+        
+        if (!empty($this->usermodified)) {
+            global $USER;
+            $this->usermodified = $USER->id;
         }
+
+        $result = update_record($this->table, $this);
         return $result;
     }
 
@@ -110,6 +114,9 @@ class grade_object {
                 unset($clone->$var);
             }
         }
+        
+        global $USER;
+        $this->usermodified = $USER->id;
 
         $this->id = insert_record($this->table, $clone, true);
         return $this->id;
index 9567c614bb74a1ae07e3152bfbecc4fea219012f..707351935f0fbe45c44a2abc6de4f4624e7a0baa 100644 (file)
@@ -83,12 +83,42 @@ class grade_outcome extends grade_object {
      * @param array $params Can also be a standard object.
      * @param boolean $fetch Wether or not to fetch the corresponding row from the DB.
      */
-    function grade_grades_raw($params=NULL, $fetch=true) {
+    function grade_outcome($params=NULL, $fetch=true) {
         $this->grade_object($params, $fetch);
         if (!empty($this->scaleid)) {
             $this->scale = new grade_scale(array('id' => $this->scaleid));
             $this->scale->load_items();
         }
     }
+    
+    /**
+     * Finds and returns a grade_outcome object based on 1-3 field values.
+     *
+     * @param boolean $static Unless set to true, this method will also set $this object with the returned values.
+     * @param string $field1
+     * @param string $value1
+     * @param string $field2
+     * @param string $value2
+     * @param string $field3
+     * @param string $value3
+     * @param string $fields
+     * @return object grade_outcome object or false if none found.
+     */
+    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { 
+        if ($grade_outcome = get_record('grade_outcomes', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
+            if (isset($this) && get_class($this) == 'grade_outcome') {
+                print_object($this);
+                foreach ($grade_outcome as $param => $value) {
+                    $this->$param = $value;
+                }
+                return $this;
+            } else {
+                $grade_outcome = new grade_outcome($grade_outcome);
+                return $grade_outcome;
+            }
+        } else {
+            return false;
+        }
+    }
 }
 ?>
index f5f56b3dbc4dbe364c4aa585c73ffdf740d10864..38264bc492cb6cf8f82d2647cfe03bd476efe3b6 100644 (file)
@@ -72,6 +72,34 @@ class grade_scale extends grade_object {
      */
     var $description;
     
+    /**
+     * Finds and returns a grade_scale object based on 1-3 field values.
+     *
+     * @param string $field1
+     * @param string $value1
+     * @param string $field2
+     * @param string $value2
+     * @param string $field3
+     * @param string $value3
+     * @param string $fields
+     * @return object grade_scale object or false if none found.
+     */
+    function fetch($field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields="*") { 
+        if ($grade_scale = get_record('scale', $field1, $value1, $field2, $value2, $field3, $value3, $fields)) {
+            if (isset($this) && get_class($this) == 'grade_scale') {
+                foreach ($grade_scale as $param => $value) {
+                    $this->$param = $value;
+                }
+                return $this;
+            } else {
+                $grade_scale = new grade_scale($grade_scale);
+                return $grade_scale;
+            }
+        } else {
+            return false;
+        }
+    }
+    
     /**
      * Loads the scale's items into the $scale_items array. 
      * There are three ways to achieve this:
index fb9a627c59502d206d739f63961be1c1dd358622..259da1153a19a9104f3ac91c67f4e4ae96cfc483 100644 (file)
@@ -48,6 +48,8 @@ require_once($CFG->libdir . '/grade/grade_grades_raw.php');
 require_once($CFG->libdir . '/grade/grade_grades_final.php');
 require_once($CFG->libdir . '/grade/grade_scale.php');
 require_once($CFG->libdir . '/grade/grade_outcome.php');
+require_once($CFG->libdir . '/grade/grade_history.php');
+require_once($CFG->libdir . '/grade/grade_grades_text.php');
 
 /**
 * Extracts from the gradebook all the grade items attached to the calling object. 
diff --git a/lib/simpletest/grade/simpletest/testgradecalculation.php b/lib/simpletest/grade/simpletest/testgradecalculation.php
new file mode 100644 (file)
index 0000000..b92a0ad
--- /dev/null
@@ -0,0 +1,95 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.org                                            //
+//                                                                       //
+// Copyright (C) 1999-2004  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Unit tests for grade_calculation object.
+ *
+ * @author nicolas@moodle.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package moodlecore
+ */
+require_once(dirname(__FILE__) . '/../../../../config.php');
+global $CFG;
+require_once($CFG->libdir . '/simpletest/testgradelib.php');
+
+class grade_calculation_test extends gradelib_test {
+
+    function test_grade_calculation_construct() {
+        $params = new stdClass();
+
+        $params->itemid = $this->grade_items[0]->id;
+        $params->calculation = 'MEAN(1, 2)';
+
+        $grade_calculation = new grade_calculation($params, false);
+        $this->assertEqual($params->itemid, $grade_calculation->itemid);
+        $this->assertEqual($params->calculation, $grade_calculation->calculation);
+    }
+
+    function test_grade_calculation_insert() {
+        $grade_calculation = new grade_calculation();
+        $this->assertTrue(method_exists($grade_calculation, 'insert'));
+        
+        $grade_calculation->itemid = $this->grade_items[0]->id;
+        $grade_calculation->calculation = 'MEAN(1, 2)';
+
+        $grade_calculation->insert();
+
+        $last_grade_calculation = end($this->grade_calculations);
+
+        $this->assertEqual($grade_calculation->id, $last_grade_calculation->id + 1);
+        $this->assertFalse(empty($grade_calculation->timecreated));
+        $this->assertFalse(empty($grade_calculation->timemodified));
+        $this->grade_calculations[] = $grade_calculation; 
+
+    }
+
+    function test_grade_calculation_update() {
+        $grade_calculation = new grade_calculation($this->grade_calculations[0]);
+        $this->assertTrue(method_exists($grade_calculation, 'update'));
+        $grade_calculation->calculation = 'MEAN(1, 2)';        
+        $this->assertTrue($grade_calculation->update());
+        $calculation = get_field('grade_calculations', 'calculation', 'id', $this->grade_calculations[0]->id);
+        $this->assertEqual($grade_calculation->calculation, $calculation); 
+    }
+
+    function test_grade_calculation_delete() {
+        $grade_calculation = new grade_calculation($this->grade_calculations[0]);
+        $this->assertTrue(method_exists($grade_calculation, 'delete'));
+        
+        $this->assertTrue($grade_calculation->delete());
+        $this->assertFalse(get_record('grade_calculations', 'id', $grade_calculation->id)); 
+    }
+
+    function test_grade_calculation_fetch() {
+        $grade_calculation = new grade_calculation(); 
+        $this->assertTrue(method_exists($grade_calculation, 'fetch'));
+
+        $grade_calculation = grade_calculation::fetch('id', $this->grade_calculations[0]->id);
+        $this->assertEqual($this->grade_calculations[0]->id, $grade_calculation->id);
+        $this->assertEqual($this->grade_calculations[0]->calculation, $grade_calculation->calculation); 
+    } 
+
+} 
+?>
diff --git a/lib/simpletest/grade/simpletest/testgradefinal.php b/lib/simpletest/grade/simpletest/testgradefinal.php
new file mode 100644 (file)
index 0000000..e822bf6
--- /dev/null
@@ -0,0 +1,97 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.org                                            //
+//                                                                       //
+// Copyright (C) 1999-2004  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Unit tests for grade_final object.
+ *
+ * @author nicolas@moodle.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package moodlecore
+ */
+require_once(dirname(__FILE__) . '/../../../../config.php');
+global $CFG;
+require_once($CFG->libdir . '/simpletest/testgradelib.php');
+
+class grade_final_test extends gradelib_test {
+
+    function test_grade_grades_final_construct() {
+        $params = new stdClass();
+
+        $params->itemid = $this->grade_items[0]->id;
+        $params->userid = 1;
+        $params->gradevalue = 88;
+
+        $grade_grades_final = new grade_grades_final($params, false);
+        $this->assertEqual($params->itemid, $grade_grades_final->itemid);
+        $this->assertEqual($params->gradevalue, $grade_grades_final->gradevalue);
+    }
+
+    function test_grade_grades_final_insert() {
+        $grade_grades_final = new grade_grades_final();
+        $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->gradevalue = 88;
+
+        $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->assertFalse(empty($grade_grades_final->timecreated));
+        $this->assertFalse(empty($grade_grades_final->timemodified));
+        $this->grade_grades_final[] = $grade_grades_final; 
+
+    }
+
+    function test_grade_grades_final_update() {
+        $grade_grades_final = new grade_grades_final($this->grade_grades_final[0]);
+        $this->assertTrue(method_exists($grade_grades_final, 'update'));
+        $grade_grades_final->gradevalue = 89;        
+        $this->assertTrue($grade_grades_final->update());
+        $gradevalue = get_field('grade_grades_final', 'gradevalue', 'id', $this->grade_grades_final[0]->id);
+        $this->assertEqual($grade_grades_final->gradevalue, $gradevalue); 
+    }
+
+    function test_grade_grades_final_delete() {
+        $grade_grades_final = new grade_grades_final($this->grade_grades_final[0]);
+        $this->assertTrue(method_exists($grade_grades_final, 'delete'));
+        
+        $this->assertTrue($grade_grades_final->delete());
+        $this->assertFalse(get_record('grade_grades_final', 'id', $grade_grades_final->id)); 
+    }
+
+    function test_grade_grades_final_fetch() {
+        $grade_grades_final = new grade_grades_final(); 
+        $this->assertTrue(method_exists($grade_grades_final, 'fetch'));
+
+        $grade_grades_final = grade_grades_final::fetch('id', $this->grade_grades_final[0]->id);
+        $this->assertEqual($this->grade_grades_final[0]->id, $grade_grades_final->id);
+        $this->assertEqual($this->grade_grades_final[0]->gradevalue, $grade_grades_final->gradevalue); 
+    } 
+
+} 
+?>
diff --git a/lib/simpletest/grade/simpletest/testgradehistory.php b/lib/simpletest/grade/simpletest/testgradehistory.php
new file mode 100644 (file)
index 0000000..2943da1
--- /dev/null
@@ -0,0 +1,102 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.org                                            //
+//                                                                       //
+// Copyright (C) 1999-2004  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Unit tests for grade_history object.
+ *
+ * @author nicolas@moodle.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package moodlecore
+ */
+require_once(dirname(__FILE__) . '/../../../../config.php');
+global $CFG;
+require_once($CFG->libdir . '/simpletest/testgradelib.php');
+
+class grade_history_test extends gradelib_test {
+
+    function test_grade_history_construct() {
+        $params = new stdClass();
+
+        $params->itemid = $this->grade_items[0]->id;
+        $params->userid = 1;
+        $params->oldgrade = 88;
+        $params->newgrade = 90;
+        $params->note = 'Modified manually in testgradehistory.php';
+        $params->howmodified = 'manual';
+
+        $grade_history = new grade_history($params, false);
+        $this->assertEqual($params->itemid, $grade_history->itemid);
+        $this->assertEqual($params->note, $grade_history->note);
+    }
+    
+    function test_grade_history_insert() {
+        $grade_history = new grade_history();
+        $this->assertTrue(method_exists($grade_history, 'insert'));
+        
+        $grade_history->itemid = $this->grade_items[0]->id;
+        $grade_history->userid = 1;
+        $grade_history->oldgrade = 88;
+        $grade_history->newgrade = 90;
+        $grade_history->note = 'Modified manually in testgradehistory.php';
+        $grade_history->howmodified = 'manual';
+        
+        $grade_history->insert();
+
+        $last_grade_history = end($this->grade_history);
+
+        $this->assertEqual($grade_history->id, $last_grade_history->id + 1);
+        $this->assertFalse(empty($grade_history->timecreated));
+        $this->assertFalse(empty($grade_history->timemodified));
+        $this->grade_history[] = $grade_history; 
+
+    }
+
+    function test_grade_history_update() {
+        $grade_history = new grade_history($this->grade_history[0]);
+        $this->assertTrue(method_exists($grade_history, 'update'));
+        $grade_history->note = 'Modified manually in testgradehistory.php';        
+        $this->assertTrue($grade_history->update());
+        $note = get_field('grade_history', 'note', 'id', $this->grade_history[0]->id);
+        $this->assertEqual($grade_history->note, $note); 
+    }
+
+    function test_grade_history_delete() {
+        $grade_history = new grade_history($this->grade_history[0]);
+        $this->assertTrue(method_exists($grade_history, 'delete'));
+        
+        $this->assertTrue($grade_history->delete());
+        $this->assertFalse(get_record('grade_history', 'id', $grade_history->id)); 
+    }
+
+    function test_grade_history_fetch() {
+        $grade_history = new grade_history(); 
+        $this->assertTrue(method_exists($grade_history, 'fetch'));
+
+        $grade_history = grade_history::fetch('id', $this->grade_history[0]->id);
+        $this->assertEqual($this->grade_history[0]->id, $grade_history->id);
+        $this->assertEqual($this->grade_history[0]->note, $grade_history->note); 
+    } 
+} 
+?>
diff --git a/lib/simpletest/grade/simpletest/testgradeoutcome.php b/lib/simpletest/grade/simpletest/testgradeoutcome.php
new file mode 100644 (file)
index 0000000..af75394
--- /dev/null
@@ -0,0 +1,94 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.org                                            //
+//                                                                       //
+// Copyright (C) 1999-2004  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Unit tests for grade_outcome object.
+ *
+ * @author nicolas@moodle.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package moodlecore
+ */
+require_once(dirname(__FILE__) . '/../../../../config.php');
+global $CFG;
+require_once($CFG->libdir . '/simpletest/testgradelib.php');
+
+class grade_outcome_test extends gradelib_test {
+
+    function test_grade_outcome_construct() {
+        $params = new stdClass();
+
+        $params->courseid = $this->courseid;
+        $params->shortname = 'Team work';
+
+        $grade_outcome = new grade_outcome($params, false);
+        $this->assertEqual($params->courseid, $grade_outcome->courseid);
+        $this->assertEqual($params->shortname, $grade_outcome->shortname);
+    }
+
+    function test_grade_outcome_insert() {
+        $grade_outcome = new grade_outcome();
+        $this->assertTrue(method_exists($grade_outcome, 'insert'));
+        
+        $grade_outcome->courseid = $this->courseid;
+        $grade_outcome->shortname = 'Team work';
+
+        $grade_outcome->insert();
+
+        $last_grade_outcome = end($this->grade_outcomes);
+
+        $this->assertEqual($grade_outcome->id, $last_grade_outcome->id + 1);
+        $this->assertFalse(empty($grade_outcome->timecreated));
+        $this->assertFalse(empty($grade_outcome->timemodified));
+        $this->grade_outcomes[] = $grade_outcome; 
+
+    }
+
+    function test_grade_outcome_update() {
+        $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
+        $this->assertTrue(method_exists($grade_outcome, 'update'));
+        $grade_outcome->shortname = 'Team work';        
+        $this->assertTrue($grade_outcome->update());
+        $shortname = get_field('grade_outcomes', 'shortname', 'id', $this->grade_outcomes[0]->id);
+        $this->assertEqual($grade_outcome->shortname, $shortname); 
+    }
+
+    function test_grade_outcome_delete() {
+        $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
+        $this->assertTrue(method_exists($grade_outcome, 'delete'));
+        
+        $this->assertTrue($grade_outcome->delete());
+        $this->assertFalse(get_record('grade_outcomes', 'id', $grade_outcome->id)); 
+    }
+
+    function test_grade_outcome_fetch() {
+        $grade_outcome = new grade_outcome(); 
+        $this->assertTrue(method_exists($grade_outcome, 'fetch'));
+
+        $grade_outcome = grade_outcome::fetch('id', $this->grade_outcomes[0]->id);
+        $this->assertEqual($this->grade_outcomes[0]->id, $grade_outcome->id);
+        $this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname); 
+    } 
+} 
+?>
index e1e828ba8db05134cab6d84e926a8894a9b99ebf..d67490605a75aa25c09aa2d671e5a39c3a265fb2 100755 (executable)
@@ -35,11 +35,68 @@ global $CFG;
 require_once($CFG->libdir . '/simpletest/testgradelib.php');
 
 class grade_raw_test extends gradelib_test {
-    
-    function test_grade_raw_construct() {
+
+    function test_grade_grades_raw_construct() {
+        $params = new stdClass();
+
+        $params->itemid = $this->grade_items[0]->id;
+        $params->userid = 1;
+        $params->gradevalue = 88;
+        $params->grademax = 110;
+        $params->grademin = 18;
+
+        $grade_grades_raw = new grade_grades_raw($params, false);
+        $this->assertEqual($params->itemid, $grade_grades_raw->itemid);
+        $this->assertEqual($params->gradevalue, $grade_grades_raw->gradevalue);
+    }
+
+    function test_grade_grades_raw_insert() {
+        $grade_grades_raw = new grade_grades_raw();
+        $this->assertTrue(method_exists($grade_grades_raw, 'insert'));
         
+        $grade_grades_raw->itemid = $this->grade_items[0]->id;
+        $grade_grades_raw->userid = 1;
+        $grade_grades_raw->gradevalue = 88;
+        $grade_grades_raw->grademax = 110;
+        $grade_grades_raw->grademin = 18;
+
+        $grade_grades_raw->insert();
+
+        $last_grade_grades_raw = end($this->grade_grades_raw);
+
+        $this->assertEqual($grade_grades_raw->id, $last_grade_grades_raw->id + 1);
+        $this->assertFalse(empty($grade_grades_raw->timecreated));
+        $this->assertFalse(empty($grade_grades_raw->timemodified));
+        $this->grade_grades_raw[] = $grade_grades_raw; 
+
     }
 
+    function test_grade_grades_raw_update() {
+        $grade_grades_raw = new grade_grades_raw($this->grade_grades_raw[0]);
+        $this->assertTrue(method_exists($grade_grades_raw, 'update'));
+        
+        $this->assertTrue($grade_grades_raw->update(89));
+        $gradevalue = get_field('grade_grades_raw', 'gradevalue', 'id', $this->grade_grades_raw[0]->id);
+        $this->assertEqual($grade_grades_raw->gradevalue, $gradevalue); 
+    }
+
+    function test_grade_grades_raw_delete() {
+        $grade_grades_raw = new grade_grades_raw($this->grade_grades_raw[0]);
+        $this->assertTrue(method_exists($grade_grades_raw, 'delete'));
+        
+        $this->assertTrue($grade_grades_raw->delete());
+        $this->assertFalse(get_record('grade_grades_raw', 'id', $grade_grades_raw->id)); 
+    }
+
+    function test_grade_grades_raw_fetch() {
+        $grade_grades_raw = new grade_grades_raw(); 
+        $this->assertTrue(method_exists($grade_grades_raw, 'fetch'));
+
+        $grade_grades_raw = grade_grades_raw::fetch('id', $this->grade_grades_raw[0]->id);
+        $this->assertEqual($this->grade_grades_raw[0]->id, $grade_grades_raw->id);
+        $this->assertEqual($this->grade_grades_raw[0]->gradevalue, $grade_grades_raw->gradevalue); 
+    } 
+    
     /**
      * Make sure that an update of a grade_raw object also updates the history table.
      */
@@ -60,6 +117,13 @@ class grade_raw_test extends gradelib_test {
         $this->assertEqual($howmodified, $history_log->howmodified);
         $this->assertEqual($note, $history_log->note);
     }
+    
+    function test_grade_raw_annotate() {
+
+    }
 
+    function test_grade_raw_load_text() {
+
+    }
 } 
 ?>
index e1f2ad06bc23c44b5b3080b4b2b4326829e883da..e4e75a67ca51e02f587ac2621a60f71c878f5c0d 100755 (executable)
@@ -36,7 +36,7 @@ require_once($CFG->libdir . '/simpletest/testgradelib.php');
 
 class grade_scale_test extends gradelib_test {
 
-    function test_scale_constructor() {
+    function test_scale_construct() {
         $params = new stdClass();
         
         $params->name        = 'unittestscale3';
@@ -53,7 +53,55 @@ class grade_scale_test extends gradelib_test {
         $this->assertEqual($params->description, $scale->description);
 
     }
+    
+    function test_grade_scale_insert() {
+        $grade_scale = new grade_scale();
+        $this->assertTrue(method_exists($grade_scale, 'insert'));
+        
+        $grade_scale->name        = 'unittestscale3';
+        $grade_scale->courseid    = $this->courseid;
+        $grade_scale->userid      = $this->userid;
+        $grade_scale->scale       = 'Distinction, Very Good, Good, Pass, Fail';
+        $grade_scale->description = 'This scale is used to mark standard assignments.';
+
+        $grade_scale->insert();
+
+        $last_grade_scale = end($this->scale);
+
+        $this->assertEqual($grade_scale->id, $last_grade_scale->id + 1);
+        $this->assertTrue(!empty($grade_scale->timecreated));
+        $this->assertTrue(!empty($grade_scale->timemodified));
+        $this->scale[] = $grade_scale; 
+
+    }
+
+    function test_grade_scale_update() {
+        $grade_scale = new grade_scale($this->scale[0]);
+        $this->assertTrue(method_exists($grade_scale, 'update'));
+        
+        $grade_scale->name = 'Updated info for this unittest grade_scale';
+        $this->assertTrue($grade_scale->update());
+        $name = get_field('scale', 'name', 'id', $this->scale[0]->id);
+        $this->assertEqual($grade_scale->name, $name); 
+    }
+
+    function test_grade_scale_delete() {
+        $grade_scale = new grade_scale($this->scale[0]);
+        $this->assertTrue(method_exists($grade_scale, 'delete'));
+        
+        $this->assertTrue($grade_scale->delete());
+        $this->assertFalse(get_record('scale', 'id', $grade_scale->id)); 
+    }
+
+    function test_grade_scale_fetch() {
+        $grade_scale = new grade_scale(); 
+        $this->assertTrue(method_exists($grade_scale, 'fetch'));
 
+        $grade_scale = grade_scale::fetch('id', $this->scale[0]->id);
+        $this->assertEqual($this->scale[0]->id, $grade_scale->id);
+        $this->assertEqual($this->scale[0]->name, $grade_scale->name); 
+    } 
+    
     function test_scale_load_items() {
         $scale = new grade_scale($this->scale[0]);
         $this->assertTrue(method_exists($scale, 'load_items'));
diff --git a/lib/simpletest/grade/simpletest/testgradetext.php b/lib/simpletest/grade/simpletest/testgradetext.php
new file mode 100755 (executable)
index 0000000..fa29636
--- /dev/null
@@ -0,0 +1,106 @@
+<?php // $Id$
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+// NOTICE OF COPYRIGHT                                                   //
+//                                                                       //
+// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
+//          http://moodle.org                                            //
+//                                                                       //
+// Copyright (C) 1999-2004  Martin Dougiamas  http://dougiamas.com       //
+//                                                                       //
+// This program is free software; you can redistribute it and/or modify  //
+// it under the terms of the GNU General Public License as published by  //
+// the Free Software Foundation; either version 2 of the License, or     //
+// (at your option) any later version.                                   //
+//                                                                       //
+// This program is distributed in the hope that it will be useful,       //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
+// GNU General Public License for more details:                          //
+//                                                                       //
+//          http://www.gnu.org/copyleft/gpl.html                         //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+/**
+ * Unit tests for grade_text object.
+ *
+ * @author nicolas@moodle.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ * @package moodlecore
+ */
+require_once(dirname(__FILE__) . '/../../../../config.php');
+global $CFG;
+require_once($CFG->libdir . '/simpletest/testgradelib.php');
+
+class grade_text_test extends gradelib_test {
+
+    function test_grade_grades_text_construct() {
+        $params = new stdClass();
+
+        $params->gradesid = $this->grade_grades_raw[0]->id;
+        $params->information = 'Thumbs down';
+        $params->informationformat = FORMAT_PLAIN;
+        $params->feedback = 'Good, but not good enough..';
+        $params->feedbackformat = FORMAT_PLAIN;
+
+        $grade_grades_text = new grade_grades_text($params, false);
+        $this->assertEqual($params->gradesid, $grade_grades_text->gradesid);
+        $this->assertEqual($params->information, $grade_grades_text->information);
+        $this->assertEqual($params->informationformat, $grade_grades_text->informationformat);
+        $this->assertEqual($params->feedback, $grade_grades_text->feedback);
+        $this->assertEqual($params->feedbackformat, $grade_grades_text->feedbackformat);
+    }
+
+    function test_grade_grades_text_insert() {
+        $grade_grades_text = new grade_grades_text();
+        $this->assertTrue(method_exists($grade_grades_text, 'insert'));
+        
+        $grade_grades_text->gradesid = $this->grade_grades_raw[0]->id;
+        $grade_grades_text->information = 'Thumbs down';
+        $grade_grades_text->informationformat = FORMAT_PLAIN;
+        $grade_grades_text->feedback = 'Good, but not good enough..';
+        $grade_grades_text->feedbackformat = FORMAT_PLAIN;
+
+        $grade_grades_text->insert();
+
+        $last_grade_grades_text = end($this->grade_grades_text);
+
+        global $USER;
+        
+        $this->assertEqual($grade_grades_text->id, $last_grade_grades_text->id + 1);
+        $this->assertFalse(empty($grade_grades_text->timecreated));
+        $this->assertFalse(empty($grade_grades_text->timemodified));
+        $this->assertEqual($USER->id, $grade_grades_text->usermodified);
+        $this->grade_grades_text[] = $grade_grades_text; 
+
+    }
+
+    function test_grade_grades_text_update() {
+        $grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
+        $this->assertTrue(method_exists($grade_grades_text, 'update'));
+        
+        $this->assertTrue($grade_grades_text->update(89));
+        $information = get_field('grade_grades_text', 'information', 'id', $this->grade_grades_text[0]->id);
+        $this->assertEqual($grade_grades_text->information, $information); 
+    }
+
+    function test_grade_grades_text_delete() {
+        $grade_grades_text = new grade_grades_text($this->grade_grades_text[0]);
+        $this->assertTrue(method_exists($grade_grades_text, 'delete'));
+        
+        $this->assertTrue($grade_grades_text->delete());
+        $this->assertFalse(get_record('grade_grades_text', 'id', $grade_grades_text->id)); 
+    }
+
+    function test_grade_grades_text_fetch() {
+        $grade_grades_text = new grade_grades_text(); 
+        $this->assertTrue(method_exists($grade_grades_text, 'fetch'));
+
+        $grade_grades_text = grade_grades_text::fetch('id', $this->grade_grades_text[0]->id);
+        $this->assertEqual($this->grade_grades_text[0]->id, $grade_grades_text->id);
+        $this->assertEqual($this->grade_grades_text[0]->information, $grade_grades_text->information); 
+    } 
+} 
+?>
index 1675ca2de839d9ef10143b3cd69d01497c0136d7..139291c80ecd0666c77f49c6750f51e8d546e4e2 100644 (file)
@@ -66,12 +66,12 @@ class gradelib_test extends UnitTestCase {
     var $tables = array('grade_categories',
                         'grade_items',
                         'grade_calculations',
+                        'scale',
                         'grade_grades_raw',
                         'grade_grades_final',
                         'grade_grades_text',
                         'grade_outcomes',
-                        'grade_history',
-                        'scale');
+                        'grade_history');
 
     var $grade_items = array();
     var $grade_categories = array();
@@ -266,12 +266,77 @@ 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.
      */
     function load_grade_grades_raw() {
         // Grades for grade_item 1
-
         $grade_raw = new stdClass();
         $grade_raw->itemid = $this->grade_items[0]->id;
         $grade_raw->userid = 1;
@@ -345,7 +410,8 @@ class gradelib_test extends UnitTestCase {
         $grade_raw = new stdClass();
         $grade_raw->itemid = $this->grade_items[2]->id;
         $grade_raw->userid = 1;
-        $grade_raw->gradevalue = 61;
+        $grade_raw->gradescale = 2;
+        $grade_raw->scaleid = $this->scale[3]->id;
         $grade_raw->timecreated = mktime();
         $grade_raw->timemodified = mktime();
 
@@ -356,7 +422,8 @@ class gradelib_test extends UnitTestCase {
         $grade_raw = new stdClass();
         $grade_raw->itemid = $this->grade_items[2]->id;
         $grade_raw->userid = 2;
-        $grade_raw->gradevalue = 81;
+        $grade_raw->gradescale = 3;
+        $grade_raw->scaleid = $this->scale[3]->id;
         $grade_raw->timecreated = mktime();
         $grade_raw->timemodified = mktime();
 
@@ -367,7 +434,8 @@ class gradelib_test extends UnitTestCase {
         $grade_raw = new stdClass();
         $grade_raw->itemid = $this->grade_items[2]->id;
         $grade_raw->userid = 3;
-        $grade_raw->gradevalue = 49;
+        $grade_raw->gradescale = 1;
+        $grade_raw->scaleid = $this->scale[3]->id;
         $grade_raw->timecreated = mktime();
         $grade_raw->timemodified = mktime();
 
@@ -498,51 +566,75 @@ class gradelib_test extends UnitTestCase {
      * Load grade_grades_text data into the database, and adds the corresponding objects to this class' variable.
      */
     function load_grade_grades_text() {
+        $grade_grades_text = new stdClass();
+
+        $grade_grades_text->gradesid = $this->grade_grades_raw[0]->id;
+        $grade_grades_text->information = 'Thumbs down';
+        $grade_grades_text->informationformat = FORMAT_PLAIN;
+        $grade_grades_text->feedback = 'Good, but not good enough..';
+        $grade_grades_text->feedbackformat = FORMAT_PLAIN;
         
+        if ($grade_grades_text->id = insert_record('grade_grades_text', $grade_grades_text)) {
+            $this->grade_grades_text[] = $grade_grades_text;
+        } 
     }
     
     /**
      * Load grade_outcome data into the database, and adds the corresponding objects to this class' variable.
      */
     function load_grade_outcomes() {
-
+        // Calculation for grade_item 1
+        $grade_outcome = new stdClass();
+        $grade_outcome->itemid = $this->grade_items[0]->id;
+        $grade_outcome->shortname = 'Team work';
+        $grade_outcome->timecreated = mktime();
+        $grade_outcome->timemodified = mktime();
+        $grade_outcome->scaleid = $this->scale[2]->id;
+        
+        if ($grade_outcome->id = insert_record('grade_outcomes', $grade_outcome)) {
+            $this->grade_outcomes[] = $grade_outcome;
+        } 
+        
+        // Calculation for grade_item 2
+        $grade_outcome = new stdClass();
+        $grade_outcome->itemid = $this->grade_items[1]->id;
+        $grade_outcome->shortname = 'Complete circuit board';
+        $grade_outcome->timecreated = mktime();
+        $grade_outcome->timemodified = mktime();
+        $grade_outcome->scaleid = $this->scale[3]->id;
+        
+        if ($grade_outcome->id = insert_record('grade_outcomes', $grade_outcome)) {
+            $this->grade_outcomes[] = $grade_outcome;
+        } 
+        
+        // Calculation for grade_item 3
+        $grade_outcome = new stdClass();
+        $grade_outcome->itemid = $this->grade_items[2]->id;
+        $grade_outcome->shortname = 'Debug Java program';
+        $grade_outcome->timecreated = mktime();
+        $grade_outcome->timemodified = mktime();
+        $grade_outcome->scaleid = $this->scale[4]->id;
+        
+        if ($grade_outcome->id = insert_record('grade_outcomes', $grade_outcome)) {
+            $this->grade_outcomes[] = $grade_outcome;
+        } 
     }
 
     /**
      * Load grade_history data into the database, and adds the corresponding objects to this class' variable.
      */
     function load_grade_history() {
-
-    }
-
-    /**
-     * Load scale data into the database, and adds the corresponding objects to this class' variable.
-     */
-    function load_scale() {
-        $scale = new stdClass();
+        $grade_history = 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;
+        $grade_history->itemid = $this->grade_items[0]->id;
+        $grade_history->userid = 1;
+        $grade_history->oldgrade = 88;
+        $grade_history->newgrade = 90;
+        $grade_history->note = 'Modified manually in testgradehistory.php';
+        $grade_history->howmodified = 'manual';
+
+        if ($grade_history->id = insert_record('grade_history', $grade_history)) {
+            $this->grade_history[] = $grade_history;
         } 
     }
 /**