MDL-9506 Corrected a number of small errors in unit tests and classes.

This commit is contained in:
nicolasconnault
2007-05-28 01:26:58 +00:00
parent 3673f6bc3b
commit 526e1a8a25
7 changed files with 94 additions and 78 deletions
+4 -1
View 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;
}
+3
View 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();
+11 -1
View 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;
+2 -2
View 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) {
@@ -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);
}
}
@@ -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));
}
+69 -69
View 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.
*/