MDL-9506 Unit test tables are now created and emptied using XMLDB. raw.gradescale and final.gradescale have been removed in favour of a single gradevalue. Scale value is no longer rounded until moment of display. A number of other changes which you can look at by browsing the diff :-)

This commit is contained in:
nicolasconnault 2007-05-09 07:50:28 +00:00
parent b0b4ffe1ec
commit 6527197b4e
7 changed files with 318 additions and 62 deletions

View File

@ -204,7 +204,11 @@ class grade_category extends grade_object {
$grade_item = new grade_item();
$grade_item->iteminstance = $this->id;
$grade_item->itemtype = 'category';
$result = $result & $grade_item->insert();
if (!$grade_item->insert()) {
return false;
}
$this->grade_item = $grade_item;
}
@ -256,7 +260,7 @@ class grade_category extends grade_object {
$raw_grade->itemid = $this->grade_item->id;
$raw_grade->insert();
}
$this->load_grade_item();
$this->grade_item->generate_final();
}
@ -269,7 +273,7 @@ class grade_category extends grade_object {
* compute and return a single array of grade_raw objects with the aggregated gradevalue. This method
* must also standardise all the scores (which have different mins and maxs) so that their values can
* be meaningfully aggregated (it would make no sense to perform MEAN(239, 5) on a grade_item with a
* gradevalue between 20 and 250 and another grade_item with a gradescale between 0 and 7!). Aggregated
* gradevalue between 20 and 250 and another grade_item with a gradevalue between 0 and 7!). Aggregated
* values will be saved as grade_grades_raw->gradevalue, even when scales are involved.
* @param array $raw_grade_sets
* @return array Raw grade objects
@ -284,14 +288,9 @@ class grade_category extends grade_object {
foreach ($raw_grade_sets as $setkey => $set) {
foreach ($set as $gradekey => $raw_grade) {
$valuetype = 'gradevalue';
if (!empty($raw_grade->gradescale)) {
$valuetype = 'gradescale';
}
$this->load_grade_item();
$value = standardise_score($raw_grade->$valuetype, $raw_grade->grademin, $raw_grade->grademax,
$value = standardise_score($raw_grade->gradevalue, $raw_grade->grademin, $raw_grade->grademax,
$this->grade_item->grademin, $this->grade_item->grademax);
$pooled_grades[$raw_grade->userid][] = $value;
}

View File

@ -56,12 +56,6 @@ class grade_grades_final extends grade_object {
*/
var $gradevalue;
/**
* The scale of this grade.
* @var int $gradescale
*/
var $gradescale;
/**
* Date until which to hide this grade_item. If null, 0 or false, grade_item is not hidden. Hiding prevents viewing.
* @var int $hidden
@ -86,6 +80,12 @@ class grade_grades_final extends grade_object {
*/
var $usermodified;
/**
* The grade_grades_text object linked to this grade through itemid and userid.
* @var object $grade_grades_text
*/
var $grade_grades_text;
/**
* Constructor. Extends the basic functionality defined in grade_object.
* @param array $params Can also be a standard object.
@ -95,6 +95,11 @@ class grade_grades_final extends grade_object {
$this->grade_object($params, $fetch);
}
/**
*
function get_text() {
}
/**
* Finds and returns a grade_grades_final object based on 1-3 field values.

View File

@ -57,12 +57,6 @@ class grade_grades_raw extends grade_object {
*/
var $gradevalue;
/**
* The scale value of this raw grade, if such was provided by the module.
* @var int $gradescale
*/
var $gradescale;
/**
* The maximum allowable grade when this grade was created.
* @var float $grademax

View File

@ -364,7 +364,6 @@ class grade_item extends grade_object {
foreach ($this->grade_grades_raw as $raw_grade) {
$final_grade = new grade_grades_final();
$final_grade->gradevalue = $this->adjust_grade($raw_grade, null, 'gradevalue');
$final_grade->gradescale = $this->adjust_grade($raw_grade, null, 'gradescale');
$final_grade->itemid = $this->id;
$final_grade->userid = $raw_grade->userid;
$success = $success & $final_grade->insert();
@ -571,22 +570,16 @@ class grade_item extends grade_object {
}
foreach ($grade_raw_array as $userid => $raw) {
// the value could be gradevalue or gradescale
$valuetype = "grade$this->gradetype";
if (empty($raw->$valuetype)) {
return 'ERROR! The raw grade has no value for ' . $valuetype . ' (or the grade_item has no gradetype.)';
}
$newgradevalue = $raw->$valuetype;
$newgradevalue = $raw->gradevalue;
if (!empty($this->calculation)) {
$this->upgrade_calculation_to_object();
$newgradevalue = $this->calculation->compute($raw->$valuetype);
$newgradevalue = $this->calculation->compute($raw->gradevalue);
}
$final = $this->grade_grades_final[$userid];
$final->$valuetype = $this->adjust_grade($raw, $newgradevalue);
$final->gradevalue = $this->adjust_grade($raw, $newgradevalue);
if ($final->update()) {
$count++;
@ -613,21 +606,21 @@ class grade_item extends grade_object {
* grade_item variables and returns the result.
* @param object $grade_raw The raw object to compare with this grade_item's rules
* @param mixed $gradevalue The new gradevalue (after calculations are performed).
* If null, the raw_grade's gradevalue or gradescale will be used.
* If null, the raw_grade's gradevalue will be used.
* @return mixed
*/
function adjust_grade($grade_raw, $gradevalue=NULL) {
$raw_offset = 0;
$item_offset = 0;
if ($this->gradetype == 'value') { // Dealing with numerical grade
if ($this->gradetype == GRADE_TYPE_VALUE) { // Dealing with numerical grade
if (empty($gradevalue)) {
$gradevalue = $grade_raw->gradevalue;
}
} elseif($this->gradetype == 'scale') { // Dealing with a scale value
} elseif($this->gradetype == GRADE_TYPE_SCALE) { // Dealing with a scale value
if (empty($gradevalue)) {
$gradevalue = $grade_raw->gradescale;
$gradevalue = $grade_raw->gradevalue;
}
// In case the scale objects haven't been loaded, do it now
@ -644,23 +637,20 @@ class grade_item extends grade_object {
$grade_raw->grademin = 0;
$this->grademin = 0;
} else { // Something's wrong, the raw grade has no value!?
return false;
} elseif ($this->gradetype != GRADE_TYPE_TEXT) { // Something's wrong, the raw grade has no value!?
return "Error: The gradeitem did not have a valid gradetype value, was $this->gradetype instead";
}
// Standardise score to the new grade range
$gradevalue = standardise_score($gradevalue, $grade_raw->grademin,
$grade_raw->grademax, $this->grademin, $this->grademax);
// Apply rounding or factors, depending on whether it's a scale or value
if ($this->gradetype == 'value') {
// Apply factors, depending on whether it's a scale or value
if ($this->gradetype == GRADE_TYPE_VALUE) {
// Apply other grade_item factors
$gradevalue *= $this->multfactor;
$gradevalue += $this->plusfactor;
} elseif ($this->gradetype == 'scale') {
$gradevalue = (int) round($gradevalue);
}
}
return $gradevalue;
}
}

View File

@ -40,6 +40,9 @@ define('GRADE_CHILDTYPE_ITEM', 0);
define('GRADE_CHILDTYPE_CAT', 1);
define('GRADE_ITEM', 0); // Used to compare class names with CHILDTYPE values
define('GRADE_CATEGORY', 1); // Used to compare class names with CHILDTYPE values
define('GRADE_TYPE_VALUE', 0);
define('GRADE_TYPE_SCALE', 1);
define('GRADE_TYPE_TEXT', 2);
require_once($CFG->libdir . '/grade/grade_category.php');
require_once($CFG->libdir . '/grade/grade_item.php');

View File

@ -299,30 +299,32 @@ class grade_item_test extends gradelib_test {
function test_grade_item_adjust_scale_grade() {
// Load grade item and its scale
$grade_item = new grade_item(array('scaleid' => $this->scale[1]->id), false);
$grade_item->gradetype = GRADE_TYPE_SCALE;
$grade_item->insert();
$grade_item->load_scale();
$this->assertEqual('Very Good', $grade_item->scale->scale_items[1]);
// Load raw grade and its scale
$grade_raw = new grade_grades_raw(array('scaleid' => $this->scale[0]->id), false);
$grade_raw->gradescale = 4;
$grade_raw->gradevalue = 4;
$grade_raw->itemid = $grade_item->id;
$grade_raw->userid = 1;
$grade_raw->insert();
$grade_raw->load_scale();
$this->assertEqual('Fairly neutral', $grade_raw->scale->scale_items[2]);
// Test grade_item::adjust_scale
$this->assertEqual(3, $grade_item->adjust_grade($grade_raw, null, 'gradescale'));
$grade_raw->gradescale = 6;
$this->assertEqual(4, $grade_item->adjust_grade($grade_raw, null, 'gradescale'));
$this->assertEqual(3, round($grade_item->adjust_grade($grade_raw, null, 'gradevalue')));
$grade_raw->gradevalue = 6;
$this->assertEqual(4, $grade_item->adjust_grade($grade_raw, null, 'gradevalue'));
// Check that the final grades have the correct values now
$grade_item->load_raw();
$grade_item->update_final_grade();
$this->assertFalse(empty($grade_item->grade_grades_final));
$this->assertEqual($grade_item->id, $grade_item->grade_grades_final[1]->itemid);
$this->assertEqual(3, $grade_item->grade_grades_final[1]->gradescale);
$this->assertEqual(2.66667, $grade_item->grade_grades_final[1]->gradevalue);
$this->assertEqual(1, $grade_item->grade_grades_final[1]->userid);
}

View File

@ -83,15 +83,268 @@ class gradelib_test extends UnitTestCase {
*/
function setUp() {
global $CFG;
global $db;
// $db->debug=true;
$CFG->old_prefix = $CFG->prefix;
$CFG->prefix .= 'unittest_';
if (!$this->create_test_tables()) {
die("Could not create all the test tables!");
}
foreach ($this->tables as $table) {
execute_sql("CREATE TABLE IF NOT EXISTS {$CFG->prefix}$table LIKE {$CFG->old_prefix}$table", false);
$function = "load_$table";
$this->$function();
}
}
}
function create_test_tables() {
$result = true;
/// Define table grade_items to be created
$table = new XMLDBTable('grade_items');
if (!table_exists($table)) {
/// Adding fields to table grade_items
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
$table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
$table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
$table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
$table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table grade_items
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
$table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
$table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
/// Launch create table for grade_items
$result = $result && create_table($table, true, false);
}
/// Define table grade_categories to be created
$table = new XMLDBTable('grade_categories');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_categories
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table grade_categories
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
/// Launch create table for grade_categories
$result = $result && create_table($table, true, false);
}
/// Define table grade_calculations to be created
$table = new XMLDBTable('grade_calculations');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_calculations
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table grade_calculations
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_calculations
$result = $result && create_table($table, true, false);
}
/// Define table grade_grades_text to be created
$table = new XMLDBTable('grade_grades_text');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_grades_text
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('gradesid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
$table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
$table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
/// Adding keys to table grade_grades_text
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('gradesid', XMLDB_KEY_FOREIGN, array('gradesid'), 'grade_grades_raw', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_grades_text
$result = $result && create_table($table, true, false);
}
/// Define table grade_outcomes to be created
$table = new XMLDBTable('grade_outcomes');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_outcomes
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table grade_outcomes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
$table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_outcomes
$result = $result && create_table($table, true, false);
}
/// Define table grade_history to be created
$table = new XMLDBTable('grade_history');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_history
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('oldgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
$table->addFieldInfo('newgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
$table->addFieldInfo('note', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
$table->addFieldInfo('howmodified', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, 'manual');
$table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table grade_history
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
$table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_history
$result = $result && create_table($table, true, false);
}
/// Define table grade_grades_final to be created
$table = new XMLDBTable('grade_grades_final');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_grades_final
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('gradevalue', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
$table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table grade_grades_final
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
$table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_grades_final
$result = $result && create_table($table, true, false);
}
/// Define table grade_grades_raw to be created
$table = new XMLDBTable('grade_grades_raw');
if ($result && !table_exists($table)) {
/// Adding fields to table grade_grades_raw
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('gradevalue', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
$table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
$table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
$table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
/// Adding keys to table grade_grades_raw
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
$table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
$table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
/// Launch create table for grade_grades_raw
$result = $result && create_table($table, true, false);
}
/// Define table scale to be created
$table = new XMLDBTable('scale');
if ($result && !table_exists($table)) {
/// Adding fields to table scale
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('scale', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
/// Adding keys to table scale
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table scale
$table->addIndexInfo('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid'));
/// Launch create table for scale
$result = $result && create_table($table, true, false);
}
return $result;
}
/**
@ -101,14 +354,24 @@ class gradelib_test extends UnitTestCase {
function tearDown() {
global $CFG;
foreach ($this->tables as $table) {
execute_sql("TRUNCATE TABLE {$CFG->prefix}$table", false);
// If data has been entered in DB for any table, unset corresponding array
delete_records($table);
if (count($this->$table) > 0) {
unset ($this->$table);
}
}
$CFG->prefix = $CFG->old_prefix;
}
/**
* In PHP5, this is called to drop the test tables after all the tests have been performed.
* Until we move to PHP5, I know no easy way to accomplish this.
*/
function __destruct() {
foreach ($this->tables as $table) {
$xmldbtable = new XMLDBTable($table);
drop_table($xmldbtable, true, false);
}
}
/**
* Load grade_category data into the database, and adds the corresponding objects to this class' variable.
@ -174,7 +437,7 @@ class gradelib_test extends UnitTestCase {
$grade_item->itemtype = 'mod';
$grade_item->itemmodule = 'quiz';
$grade_item->iteminstance = 1;
$grade_item->gradetype = 'value';
$grade_item->gradetype = GRADE_TYPE_VALUE;
$grade_item->grademin = 30;
$grade_item->grademax = 140;
$grade_item->itemnumber = 1;
@ -193,7 +456,7 @@ class gradelib_test extends UnitTestCase {
$grade_item->itemname = 'unittestgradeitem2';
$grade_item->itemtype = 'import';
$grade_item->itemmodule = 'assignment';
$grade_item->gradetype = 'value';
$grade_item->gradetype = GRADE_TYPE_VALUE;
$grade_item->iteminstance = 2;
$grade_item->itemnumber = null;
$grade_item->grademin = 0;
@ -215,7 +478,7 @@ class gradelib_test extends UnitTestCase {
$grade_item->itemtype = 'mod';
$grade_item->itemmodule = 'forum';
$grade_item->iteminstance = 3;
$grade_item->gradetype = 'scale';
$grade_item->gradetype = GRADE_TYPE_SCALE;
$grade_item->scaleid = 1;
$grade_item->grademin = 0;
$grade_item->grademax = 7;
@ -313,7 +576,7 @@ class gradelib_test extends UnitTestCase {
}
}
/**
/**
* Load scale data into the database, and adds the corresponding objects to this class' variable.
*/
function load_scale() {
@ -457,7 +720,7 @@ class gradelib_test extends UnitTestCase {
$grade_raw = new stdClass();
$grade_raw->itemid = $this->grade_items[2]->id;
$grade_raw->userid = 1;
$grade_raw->gradescale = 2;
$grade_raw->gradevalue = 2;
$grade_raw->scaleid = $this->scale[3]->id;
$grade_raw->timecreated = mktime();
$grade_raw->timemodified = mktime();
@ -469,7 +732,7 @@ class gradelib_test extends UnitTestCase {
$grade_raw = new stdClass();
$grade_raw->itemid = $this->grade_items[2]->id;
$grade_raw->userid = 2;
$grade_raw->gradescale = 3;
$grade_raw->gradevalue = 3;
$grade_raw->scaleid = $this->scale[3]->id;
$grade_raw->timecreated = mktime();
$grade_raw->timemodified = mktime();
@ -481,7 +744,7 @@ class gradelib_test extends UnitTestCase {
$grade_raw = new stdClass();
$grade_raw->itemid = $this->grade_items[2]->id;
$grade_raw->userid = 3;
$grade_raw->gradescale = 1;
$grade_raw->gradevalue = 1;
$grade_raw->scaleid = $this->scale[3]->id;
$grade_raw->timecreated = mktime();
$grade_raw->timemodified = mktime();