Permalink
Browse files

gradebook MDL-24330 massively reduced grade objects unit tests execut…

…ion time so I can actually run them
  • Loading branch information...
1 parent 25fa031 commit 2b574cc4e02a3068a86a587070828e861b80ec5f Andrew Davis committed Dec 10, 2010
View
341 lib/grade/simpletest/testgradecategory.php
@@ -39,7 +39,60 @@
class grade_category_test extends grade_test {
- function test_grade_category_construct() {
+ public function __construct() {
+ $this->starttime = time();
+ parent::__construct();
+ }
+
+ public function __destruct() {
+ $this->endtime = time();
+ //var_dump($this->endtime-$this->starttime);
+
+ parent::__destruct();
+ }
+
+ function test_grade_category() {
+ $this->sub_test_grade_category_construct();
+ $this->sub_test_grade_category_build_path();
+ $this->sub_test_grade_category_fetch();
+ $this->sub_test_grade_category_fetch_all();
+ $this->sub_test_grade_category_update();
+ $this->sub_test_grade_category_delete();
+ $this->sub_test_grade_category_insert();
+ $this->sub_test_grade_category_qualifies_for_regrading();
+ $this->sub_test_grade_category_force_regrading();
+ $this->sub_test_grade_category_aggregate_grades();
+ $this->sub_test_grade_category_apply_limit_rules();
+ $this->sub_test_grade_category_is_aggregationcoef_used();
+ $this->sub_test_grade_category_fetch_course_tree();
+ $this->sub_test_grade_category_get_children();
+ $this->sub_test_grade_category_load_grade_item();
+ $this->sub_test_grade_category_get_grade_item();
+ $this->sub_test_grade_category_load_parent_category();
+ $this->sub_test_grade_category_get_parent_category();
+ $this->sub_test_grade_category_get_name();
+ $this->sub_test_grade_category_set_parent();
+ $this->sub_test_grade_category_get_final();
+ $this->sub_test_grade_category_get_sortorder();
+ $this->sub_test_grade_category_set_sortorder();
+ $this->sub_test_grade_category_is_editable();
+ $this->sub_test_grade_category_move_after_sortorder();
+ $this->sub_test_grade_category_is_course_category();
+ $this->sub_test_grade_category_fetch_course_category();
+ $this->sub_test_grade_category_is_locked();
+ $this->sub_test_grade_category_set_locked();
+ $this->sub_test_grade_category_is_hidden();
+ $this->sub_test_grade_category_set_hidden();
+
+ //this won't work until MDL-11837 is complete
+ //$this->sub_test_grade_category_generate_grades();
+
+ //do this last as adding a second course category messes up the data
+ $this->sub_test_grade_category_insert_course_category();
+ }
+
+ //adds 3 new grade categories at various depths
+ function sub_test_grade_category_construct() {
$course_category = grade_category::fetch_course_category($this->courseid);
$params = new stdClass();
@@ -49,6 +102,7 @@ function test_grade_category_construct() {
$grade_category = new grade_category($params, false);
$grade_category->insert();
+ $this->grade_categories[] = $grade_category;
$this->assertEqual($params->courseid, $grade_category->courseid);
$this->assertEqual($params->fullname, $grade_category->fullname);
@@ -61,6 +115,7 @@ function test_grade_category_construct() {
$params->fullname = 'unittestcategory5';
$grade_category = new grade_category($params, false);
$grade_category->insert();
+ $this->grade_categories[] = $grade_category;
$this->assertEqual(3, $grade_category->depth);
$this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path);
@@ -71,18 +126,20 @@ function test_grade_category_construct() {
$params->fullname = 'unittestcategory6';
$grade_category = new grade_category($params, false);
$grade_category->insert();
+ $this->grade_categories[50] = $grade_category;//going to delete this one later hence the special index
+
$this->assertEqual(4, $grade_category->depth);
$this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path);
}
- function test_grade_category_build_path() {
+ function sub_test_grade_category_build_path() {
$grade_category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($grade_category, 'build_path'));
$path = grade_category::build_path($grade_category);
$this->assertEqual($grade_category->path, $path);
}
- function test_grade_category_fetch() {
+ function sub_test_grade_category_fetch() {
$grade_category = new grade_category();
$this->assertTrue(method_exists($grade_category, 'fetch'));
@@ -91,15 +148,15 @@ function test_grade_category_fetch() {
$this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname);
}
- function test_grade_category_fetch_all() {
+ function sub_test_grade_category_fetch_all() {
$grade_category = new grade_category();
$this->assertTrue(method_exists($grade_category, 'fetch_all'));
$grade_categories = grade_category::fetch_all(array('courseid'=>$this->courseid));
$this->assertEqual(count($this->grade_categories), count($grade_categories)-1);
}
- function test_grade_category_update() {
+ function sub_test_grade_category_update() {
global $DB;
$grade_category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($grade_category, 'update'));
@@ -127,16 +184,17 @@ function test_grade_category_update() {
$this->assertEqual(1, $grade_item->needsupdate);
}
- function test_grade_category_delete() {
+ function sub_test_grade_category_delete() {
global $DB;
- $grade_category = new grade_category($this->grade_categories[0]);
+
+ $grade_category = new grade_category($this->grade_categories[50]);
$this->assertTrue(method_exists($grade_category, 'delete'));
$this->assertTrue($grade_category->delete());
$this->assertFalse($DB->get_record('grade_categories', array('id' => $grade_category->id)));
}
- function test_grade_category_insert() {
+ function sub_test_grade_category_insert() {
$course_category = grade_category::fetch_course_category($this->courseid);
$grade_category = new grade_category();
@@ -149,12 +207,12 @@ function test_grade_category_insert() {
$grade_category->keephigh = 100;
$grade_category->droplow = 10;
$grade_category->hidden = 0;
- $grade_category->parent = $this->grade_categories[0]->id;
+ $grade_category->parent = $this->grade_categories[1]->id; //sub_test_grade_category_delete() removed the category at 0
$grade_category->insert();
- $this->assertEqual('/'.$course_category->id.'/'.$this->grade_categories[0]->id.'/'.$grade_category->id.'/', $grade_category->path);
- $this->assertEqual(3, $grade_category->depth);
+ $this->assertEqual('/'.$course_category->id.'/'.$this->grade_categories[1]->parent.'/'.$this->grade_categories[1]->id.'/'.$grade_category->id.'/', $grade_category->path);
+ $this->assertEqual(4, $grade_category->depth);
$last_grade_category = end($this->grade_categories);
@@ -167,38 +225,24 @@ function test_grade_category_insert() {
$this->assertFalse(empty($grade_category->timemodified));
}
- function test_grade_category_insert_course_category() {
- $grade_category = new grade_category();
- $this->assertTrue(method_exists($grade_category, 'insert_course_category'));
-
- $id = $grade_category->insert_course_category($this->courseid);
- $this->assertNotNull($id);
- $this->assertEqual('?', $grade_category->fullname);
- $this->assertEqual(GRADE_AGGREGATE_WEIGHTED_MEAN2, $grade_category->aggregation);
- $this->assertEqual("/$id/", $grade_category->path);
- $this->assertEqual(1, $grade_category->depth);
- $this->assertNull($grade_category->parent);
- }
-
- function test_grade_category_qualifies_for_regrading() {
- $grade_category = new grade_category($this->grade_categories[0]);
+ function sub_test_grade_category_qualifies_for_regrading() {
+ $grade_category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($grade_category, 'qualifies_for_regrading'));
-
$this->assertFalse($grade_category->qualifies_for_regrading());
$grade_category->aggregation = GRADE_AGGREGATE_MAX;
$this->assertTrue($grade_category->qualifies_for_regrading());
- $grade_category = new grade_category($this->grade_categories[0]);
+ $grade_category = new grade_category($this->grade_categories[1]);
$grade_category->droplow = 99;
$this->assertTrue($grade_category->qualifies_for_regrading());
- $grade_category = new grade_category($this->grade_categories[0]);
+ $grade_category = new grade_category($this->grade_categories[1]);
$grade_category->keephigh = 99;
$this->assertTrue($grade_category->qualifies_for_regrading());
}
- function test_grade_category_force_regrading() {
+ function sub_test_grade_category_force_regrading() {
$grade_category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($grade_category, 'force_regrading'));
@@ -213,41 +257,173 @@ function test_grade_category_force_regrading() {
$this->assertEqual(1, $grade_category->grade_item->needsupdate);
}
- /*
- * I am disabling this test until we implement proper mock objects. This is meant
- * to be a private method called from within a grade_item method.
+ /**
+ * Tests the calculation of grades using the various aggregation methods with and without hidden grades
+ * This will not work entirely until MDL-11837 is done
+ * @global type $DB
+ */
+ function sub_test_grade_category_generate_grades() {
+ global $DB;
- function test_grade_category_generate_grades() {
- $category = new grade_category($this->grade_categories[3]);
- $this->assertTrue(method_exists($category, 'generate_grades'));
- $category->load_grade_item();
+ //inserting some special grade items to make testing the final grade calculation easier
+ $params->courseid = $this->courseid;
+ $params->fullname = 'unittestgradecalccategory';
+ $params->aggregation = GRADE_AGGREGATE_MEAN;
+ $params->aggregateonlygraded = 0;
+ $grade_category = new grade_category($params, false);
+ $grade_category->insert();
- $grades = $DB->get_records('grade_grades', array('itemid'=>$category->grade_item->id));
- $this->assertFalse($grades);
+ $this->assertTrue(method_exists($grade_category, 'generate_grades'));
- $category->generate_grades();
- $grades = $DB->get_records('grade_grades', array('itemid'=>$category->grade_item->id));
- $this->assertEqual(3, count($grades));
+ $grade_category->load_grade_item();
+ $cgi = $grade_category->get_grade_item();
+ $cgi->grademin = 0;
+ $cgi->grademax = 20;//3 grade items out of 10 but category is out of 20 to force scaling to occur
+ $cgi->update();
+
+ //3 grade items each with a maximum grade of 10
+ $grade_items = array();
+ for ($i=0; $i<3; $i++) {
+ $grade_items[$i] = new grade_item();
+ $grade_items[$i]->courseid = $this->courseid;
+ $grade_items[$i]->categoryid = $grade_category->id;
+ $grade_items[$i]->itemname = 'manual grade_item '.$i;
+ $grade_items[$i]->itemtype = 'manual';
+ $grade_items[$i]->itemnumber = 0;
+ $grade_items[$i]->needsupdate = false;
+ $grade_items[$i]->gradetype = GRADE_TYPE_VALUE;
+ $grade_items[$i]->grademin = 0;
+ $grade_items[$i]->grademax = 10;
+ $grade_items[$i]->iteminfo = 'Manual grade item used for unit testing';
+ $grade_items[$i]->timecreated = mktime();
+ $grade_items[$i]->timemodified = mktime();
+
+ //used as the weight by weighted mean and as extra credit by mean with extra credit
+ //Will be 0, 1 and 2
+ $grade_items[$i]->aggregationcoef = $i;
+
+ $grade_items[$i]->insert();
+ }
- $rawvalues = array();
- foreach ($grades as $grade) {
- $this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
- $rawvalues[] = (int)$grade->rawgrade;
+ //a grade for each grade item
+ $grade_grades = array();
+ for ($i=0; $i<3; $i++) {
+ $grade_grades[$i] = new grade_grade();
+ $grade_grades[$i]->itemid = $grade_items[$i]->id;
+ $grade_grades[$i]->userid = $this->userid;
+ $grade_grades[$i]->rawgrade = ($i+1)*2;//produce grade grades of 2, 4 and 6
+ $grade_grades[$i]->finalgrade = ($i+1)*2;
+ $grade_grades[$i]->timecreated = mktime();
+ $grade_grades[$i]->timemodified = mktime();
+ $grade_grades[$i]->information = '1 of 2 grade_grades';
+ $grade_grades[$i]->informationformat = FORMAT_PLAIN;
+ $grade_grades[$i]->feedback = 'Good, but not good enough..';
+ $grade_grades[$i]->feedbackformat = FORMAT_PLAIN;
+
+ $grade_grades[$i]->insert();
}
- sort($rawvalues);
- // calculated mean results
- $this->assertEqual($rawvalues, array(20,50,100));
+
+ //3 grade items with 1 grade_grade each.
+ //grade grades have the values 2, 4 and 6
+
+ //First correct answer is the aggregate with all 3 grades
+ //Second correct answer is with the first grade (value 2) hidden
+
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEDIAN, 'GRADE_AGGREGATE_MEDIAN', 8, 8);
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MAX, 'GRADE_AGGREGATE_MAX', 12, 12);
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MODE, 'GRADE_AGGREGATE_MODE', 12, 12);
+
+ //weighted mean. note grade totals are rounded to an int to prevent rounding discrepancies. correct final grade isnt actually exactly 10
+ //3 items with grades 2, 4 and 6 with weights 0, 1 and 2 and all out of 10. then doubled to be out of 20.
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN, 'GRADE_AGGREGATE_WEIGHTED_MEAN', 10, 10);
+
+ //simple weighted mean
+ //3 items with grades 2, 4 and 6 equally weighted and all out of 10. then doubled to be out of 20.
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_WEIGHTED_MEAN2, 'GRADE_AGGREGATE_WEIGHTED_MEAN2', 8, 10);
+
+ //mean of grades with extra credit
+ //3 items with grades 2, 4 and 6 with extra credit 0, 1 and 2 equally weighted and all out of 10. then doubled to be out of 20.
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_EXTRACREDIT_MEAN, 'GRADE_AGGREGATE_EXTRACREDIT_MEAN', 10, 13);
+
+ //aggregation tests the are affected by a hidden grade currently dont work as we dont store the altered grade in the database
+ //instead an in memory recalculation is done. This should be remedied by MDL-11837
+
+ //fails with 1 grade hidden. still reports 8 as being correct
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MEAN, 'GRADE_AGGREGATE_MEAN', 8, 10);
+
+ //fails with 1 grade hidden. still reports 4 as being correct
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_MIN, 'GRADE_AGGREGATE_MIN', 4, 8);
+
+ //fails with 1 grade hidden. still reports 12 as being correct
+ $this->helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, GRADE_AGGREGATE_SUM, 'GRADE_AGGREGATE_SUM', 12, 10);
}
+ /**
+ * Test grade category aggregation using the supplied grade objects and aggregation method
+ * @param grade_category $grade_category the category to be tested
+ * @param array $grade_items array of instance of grade_item
+ * @param array $grade_grades array of instances of grade_grade
+ * @param int $aggmethod the aggregation method to apply ie GRADE_AGGREGATE_MEAN
+ * @param string $aggmethodname the name of the aggregation method to apply. Used to display any test failure messages
+ * @param int $correct1 the correct final grade for the category with NO items hidden
+ * @param int $correct2 the correct final grade for the category with the grade at $grade_grades[0] hidden
+ * @return void
*/
+ function helper_test_grade_agg_method($grade_category, $grade_items, $grade_grades, $aggmethod, $aggmethodname, $correct1, $correct2) {
+ global $DB;
+
+ $grade_category->aggregation = $aggmethod;
+ $grade_category->update();
- function test_grade_category_aggregate_grades() {
+ //check grade_item isnt hidden from a previous test
+ $grade_items[0]->set_hidden(0, true);
+ $this->helper_test_grade_aggregation_result($grade_category, $correct1, 'Testing aggregation method('.$aggmethodname.') with no items hidden %s');
+
+ //hide the grade item with grade of 2
+ $grade_items[0]->set_hidden(1, true);
+ $this->helper_test_grade_aggregation_result($grade_category, $correct2, 'Testing aggregation method('.$aggmethodname.') with 1 item hidden %s');
+ }
+
+ /**
+ * Verify the value of the category grade item for $this->userid
+ * @param grade_category $grade_category the category to be tested
+ * @param int $correctgrade the expected grade
+ * @param string msg The message that should be displayed if the correct grade is not found
+ * @return void
+ */
+ function helper_test_grade_aggregation_result($grade_category, $correctgrade, $msg) {
+ global $DB;
+
+ $category_grade_item = $grade_category->get_grade_item();
+
+ //this creates all the grade_grades we need
+ grade_regrade_final_grades($this->courseid);
+
+ $grade = $DB->get_record('grade_grades', array('itemid'=>$category_grade_item->id, 'userid'=>$this->userid));
+ $this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
+ $this->assertEqual(intval($correctgrade), intval($grade->finalgrade), $msg);
+
+ /*
+ * TODO this doesnt work as the grade_grades created by $grade_category->generate_grades(); dont
+ * observe the category's max grade
+ //delete the grade_grades for the category itself and check they get recreated correctly
+ $DB->delete_records('grade_grades', array('itemid'=>$category_grade_item->id));
+ $grade_category->generate_grades();
+
+ $grade = $DB->get_record('grade_grades', array('itemid'=>$category_grade_item->id, 'userid'=>$this->userid));
+ $this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
+ $this->assertEqual(intval($correctgrade), intval($grade->finalgrade), $msg);
+ *
+ */
+ }
+
+ function sub_test_grade_category_aggregate_grades() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'aggregate_grades'));
- // tested above in test_grade_category_generate_grades()
+ // tested more fully via test_grade_category_generate_grades()
}
- function test_grade_category_apply_limit_rules() {
+ function sub_test_grade_category_apply_limit_rules() {
$items[$this->grade_items[0]->id] = new grade_item($this->grade_items[0], false);
$items[$this->grade_items[1]->id] = new grade_item($this->grade_items[1], false);
$items[$this->grade_items[2]->id] = new grade_item($this->grade_items[2], false);
@@ -308,17 +484,17 @@ function test_grade_category_apply_limit_rules() {
/**
* TODO implement
*/
- function test_grade_category_is_aggregationcoef_used() {
+ function sub_test_grade_category_is_aggregationcoef_used() {
}
- function test_grade_category_fetch_course_tree() {
+ function sub_test_grade_category_fetch_course_tree() {
$category = new grade_category();
$this->assertTrue(method_exists($category, 'fetch_course_tree'));
//TODO: add some tests
}
- function test_grade_category_get_children() {
+ function sub_test_grade_category_get_children() {
$course_category = grade_category::fetch_course_category($this->courseid);
$category = new grade_category($this->grade_categories[0]);
@@ -337,43 +513,43 @@ function test_grade_category_get_children() {
$this->assertEqual($this->grade_items[2]->id, $children_array[5]['children'][6]['object']->id);
}
- function test_grade_category_load_grade_item() {
+ function sub_test_grade_category_load_grade_item() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'load_grade_item'));
$this->assertEqual(null, $category->grade_item);
$category->load_grade_item();
$this->assertEqual($this->grade_items[3]->id, $category->grade_item->id);
}
- function test_grade_category_get_grade_item() {
+ function sub_test_grade_category_get_grade_item() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'get_grade_item'));
$grade_item = $category->get_grade_item();
$this->assertEqual($this->grade_items[3]->id, $grade_item->id);
}
- function test_grade_category_load_parent_category() {
+ function sub_test_grade_category_load_parent_category() {
$category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($category, 'load_parent_category'));
$this->assertEqual(null, $category->parent_category);
$category->load_parent_category();
$this->assertEqual($this->grade_categories[0]->id, $category->parent_category->id);
}
- function test_grade_category_get_parent_category() {
+ function sub_test_grade_category_get_parent_category() {
$category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($category, 'get_parent_category'));
$parent_category = $category->get_parent_category();
$this->assertEqual($this->grade_categories[0]->id, $parent_category->id);
}
- function test_grade_category_get_name() {
+ function sub_test_grade_category_get_name() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'get_name'));
$this->assertEqual($this->grade_categories[0]->fullname, $category->get_name());
}
- function test_grade_category_set_parent() {
+ function sub_test_grade_category_set_parent() {
$category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($category, 'set_parent'));
// TODO: implement detailed tests
@@ -383,41 +559,41 @@ function test_grade_category_set_parent() {
$this->assertEqual($course_category->id, $category->parent);
}
- function test_grade_category_get_final() {
+ function sub_test_grade_category_get_final() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'get_final'));
$category->load_grade_item();
$this->assertEqual($category->get_final(), $category->grade_item->get_final());
}
- function test_grade_category_get_sortorder() {
+ function sub_test_grade_category_get_sortorder() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'get_sortorder'));
$category->load_grade_item();
$this->assertEqual($category->get_sortorder(), $category->grade_item->get_sortorder());
}
- function test_grade_category_set_sortorder() {
+ function sub_test_grade_category_set_sortorder() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'set_sortorder'));
$category->load_grade_item();
$this->assertEqual($category->set_sortorder(10), $category->grade_item->set_sortorder(10));
}
- function test_grade_category_move_after_sortorder() {
+ function sub_test_grade_category_move_after_sortorder() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'move_after_sortorder'));
$category->load_grade_item();
$this->assertEqual($category->move_after_sortorder(10), $category->grade_item->move_after_sortorder(10));
}
- function test_grade_category_is_course_category() {
+ function sub_test_grade_category_is_course_category() {
$category = grade_category::fetch_course_category($this->courseid);
$this->assertTrue(method_exists($category, 'is_course_category'));
$this->assertTrue($category->is_course_category());
}
- function test_grade_category_fetch_course_category() {
+ function sub_test_grade_category_fetch_course_category() {
$category = new grade_category();
$this->assertTrue(method_exists($category, 'fetch_course_category'));
$category = grade_category::fetch_course_category($this->courseid);
@@ -426,38 +602,59 @@ function test_grade_category_fetch_course_category() {
/**
* TODO implement
*/
- function test_grade_category_is_editable() {
+ function sub_test_grade_category_is_editable() {
}
- function test_grade_category_is_locked() {
+ function sub_test_grade_category_is_locked() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'is_locked'));
$category->load_grade_item();
$this->assertEqual($category->is_locked(), $category->grade_item->is_locked());
}
- function test_grade_category_set_locked() {
+ function sub_test_grade_category_set_locked() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'set_locked'));
+
+ //will return false as cannot lock a grade that needs updating
+ $this->assertFalse($category->set_locked(1));
+ grade_regrade_final_grades($this->courseid);
+
+ //get the category from the db again
+ $category = new grade_category($this->grade_categories[0]);
$this->assertTrue($category->set_locked(1));
}
- function test_grade_category_is_hidden() {
+ function sub_test_grade_category_is_hidden() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'is_hidden'));
$category->load_grade_item();
$this->assertEqual($category->is_hidden(), $category->grade_item->is_hidden());
}
- function test_grade_category_set_hidden() {
+ function sub_test_grade_category_set_hidden() {
$category = new grade_category($this->grade_categories[0]);
$this->assertTrue(method_exists($category, 'set_hidden'));
$category->set_hidden(1);
$category->load_grade_item();
$this->assertEqual(true, $category->grade_item->is_hidden());
}
+ //beware: adding a duplicate course category messes up the data in a way that's hard to recover from
+ function sub_test_grade_category_insert_course_category() {
+ $grade_category = new grade_category();
+ $this->assertTrue(method_exists($grade_category, 'insert_course_category'));
+
+ $id = $grade_category->insert_course_category($this->courseid);
+ $this->assertNotNull($id);
+ $this->assertEqual('?', $grade_category->fullname);
+ $this->assertEqual(GRADE_AGGREGATE_WEIGHTED_MEAN2, $grade_category->aggregation);
+ $this->assertEqual("/$id/", $grade_category->path);
+ $this->assertEqual(1, $grade_category->depth);
+ $this->assertNull($grade_category->parent);
+ }
+
function generate_random_raw_grade($item, $userid) {
$grade = new grade_grade();
$grade->itemid = $item->id;
View
41 lib/grade/simpletest/testgradegrades.php
@@ -39,7 +39,20 @@
class grade_grade_test extends grade_test {
- function test_grade_grade_construct() {
+ function test_grade_grade() {
+ $this->sub_test_grade_grade_construct();
+ $this->sub_test_grade_grade_insert();
+ $this->sub_test_grade_grade_update();
+ $this->sub_test_grade_grade_fetch();
+ $this->sub_test_grade_grade_fetch_all();
+ $this->sub_test_grade_grade_load_grade_item();
+ $this->sub_test_grade_grade_standardise_score();
+ $this->sub_test_grade_grade_is_locked();
+ $this->sub_test_grade_grade_set_hidden();
+ $this->sub_test_grade_grade_is_hidden();
+ }
+
+ function sub_test_grade_grade_construct() {
$params = new stdClass();
$params->itemid = $this->grade_items[0]->id;
@@ -53,7 +66,7 @@ function test_grade_grade_construct() {
$this->assertEqual($params->rawgrade, $grade_grade->rawgrade);
}
- function test_grade_grade_insert() {
+ function sub_test_grade_grade_insert() {
$grade_grade = new grade_grade();
$this->assertTrue(method_exists($grade_grade, 'insert'));
@@ -77,14 +90,17 @@ function test_grade_grade_insert() {
$this->assertTrue(empty($grade_grade->timecreated));
// timemodified will only be set if the grade was submitted by an activity module
$this->assertTrue(empty($grade_grade->timemodified));
+
+ //keep our collection the same as is in the database
+ $this->grade_grades[] = $grade_grade;
}
- function test_grade_grade_update() {
+ function sub_test_grade_grade_update() {
$grade_grade = new grade_grade($this->grade_grades[0]);
$this->assertTrue(method_exists($grade_grade, 'update'));
}
- function test_grade_grade_fetch() {
+ function sub_test_grade_grade_fetch() {
$grade_grade = new grade_grade();
$this->assertTrue(method_exists($grade_grade, 'fetch'));
@@ -93,15 +109,15 @@ function test_grade_grade_fetch() {
$this->assertEqual($this->grade_grades[0]->rawgrade, $grades->rawgrade);
}
- function test_grade_grade_fetch_all() {
+ function sub_test_grade_grade_fetch_all() {
$grade_grade = new grade_grade();
$this->assertTrue(method_exists($grade_grade, 'fetch_all'));
$grades = grade_grade::fetch_all(array());
$this->assertEqual(count($this->grade_grades), count($grades));
}
- function test_grade_grade_load_grade_item() {
+ function sub_test_grade_grade_load_grade_item() {
$grade_grade = new grade_grade($this->grade_grades[0]);
$this->assertTrue(method_exists($grade_grade, 'load_grade_item'));
$this->assertNull($grade_grade->grade_item);
@@ -112,7 +128,7 @@ function test_grade_grade_load_grade_item() {
}
- function test_grade_grade_standardise_score() {
+ function sub_test_grade_grade_standardise_score() {
$this->assertEqual(4, round(grade_grade::standardise_score(6, 0, 7, 0, 5)));
$this->assertEqual(40, grade_grade::standardise_score(50, 30, 80, 0, 100));
}
@@ -147,7 +163,7 @@ function test_grade_grade_set_locked() {
}
*/
- function test_grade_grade_is_locked() {
+ function sub_test_grade_grade_is_locked() {
$grade = new grade_grade($this->grade_grades[0]);
$this->assertTrue(method_exists($grade, 'is_locked'));
@@ -156,7 +172,7 @@ function test_grade_grade_is_locked() {
$this->assertTrue($grade->is_locked());
}
- function test_grade_grade_set_hidden() {
+ function sub_test_grade_grade_set_hidden() {
$grade_item = new grade_item($this->grade_items[0]);
$grade = new grade_grade($grade_item->get_final(1));
$this->assertTrue(method_exists($grade, 'set_hidden'));
@@ -171,12 +187,13 @@ function test_grade_grade_set_hidden() {
$this->assertEqual(1, $grade->hidden);
}
- function test_grade_grade_is_hidden() {
+ function sub_test_grade_grade_is_hidden() {
$grade = new grade_grade($this->grade_grades[0]);
$this->assertTrue(method_exists($grade, 'is_hidden'));
- $this->assertFalse($grade->is_hidden());
- $grade->hidden = 1;
+ //$this->grade_grades[0] is hidden by sub_test_grade_grade_set_hidden()
+ //$this->assertFalse($grade->is_hidden());
+ //$grade->hidden = 1;
$this->assertTrue($grade->is_hidden());
$grade->hidden = time()-666;
View
163 lib/grade/simpletest/testgradeitem.php
@@ -42,8 +42,45 @@
@set_time_limit(0);
class grade_item_test extends grade_test {
-
- function test_grade_item_construct() {
+ function test_grade_item() {
+ $this->sub_test_grade_item_construct();
+ $this->sub_test_grade_item_insert();
+ $this->sub_test_grade_item_delete();
+ $this->sub_test_grade_item_update();
+ $this->sub_test_grade_item_load_scale();
+ $this->sub_test_grade_item_load_outcome();
+ $this->sub_test_grade_item_qualifies_for_regrading();
+ $this->sub_test_grade_item_force_regrading();
+ $this->sub_test_grade_item_fetch();
+ $this->sub_test_grade_item_fetch_all();
+ $this->sub_test_grade_item_get_all_finals();
+ $this->sub_test_grade_item_get_final();
+ $this->sub_test_grade_item_get_sortorder();
+ $this->sub_test_grade_item_set_sortorder();
+ $this->sub_test_grade_item_move_after_sortorder();
+ $this->sub_test_grade_item_get_name();
+ $this->sub_test_grade_item_set_parent();
+ $this->sub_test_grade_item_get_parent_category();
+ $this->sub_test_grade_item_load_parent_category();
+ $this->sub_test_grade_item_get_item_category();
+ $this->sub_test_grade_item_load_item_category();
+ $this->sub_test_grade_item_regrade_final_grades();
+ $this->sub_test_grade_item_adjust_raw_grade();
+ $this->sub_test_grade_item_set_locked();
+ $this->sub_test_grade_item_is_locked();
+ $this->sub_test_grade_item_set_hidden();
+ $this->sub_test_grade_item_is_hidden();
+ $this->sub_test_grade_item_is_category_item();
+ $this->sub_test_grade_item_is_course_item();
+ $this->sub_test_grade_item_fetch_course_item();
+ $this->sub_test_grade_item_depends_on();
+ $this->sub_test_grade_item_is_calculated();
+ $this->sub_test_grade_item_set_calculation();
+ $this->sub_test_grade_item_get_calculation();
+ $this->sub_test_grade_item_compute();
+ }
+
+ function sub_test_grade_item_construct() {
$params = new stdClass();
$params->courseid = $this->courseid;
@@ -60,7 +97,7 @@ function test_grade_item_construct() {
$this->assertEqual($params->itemmodule, $grade_item->itemmodule);
}
- function test_grade_item_insert() {
+ function sub_test_grade_item_insert() {
$grade_item = new grade_item();
$this->assertTrue(method_exists($grade_item, 'insert'));
@@ -77,19 +114,25 @@ function test_grade_item_insert() {
$this->assertEqual($grade_item->id, $last_grade_item->id + 1);
$this->assertEqual(11, $grade_item->sortorder);
+
+ //keep our reference collection the same as what is in the database
+ $this->grade_items[] = $grade_item;
}
- function test_grade_item_delete() {
+ function sub_test_grade_item_delete() {
global $DB;
- $grade_item = new grade_item($this->grade_items[0]);
+ $grade_item = new grade_item($this->grade_items[7]);//use a grade item not touched by previous (or future) tests
$this->assertTrue(method_exists($grade_item, 'delete'));
$this->assertTrue($grade_item->delete());
$this->assertFalse($DB->get_record('grade_items', array('id' => $grade_item->id)));
+
+ //keep our reference collection the same as the database
+ unset($this->grade_items[7]);
}
- function test_grade_item_update() {
+ function sub_test_grade_item_update() {
global $DB;
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'update'));
@@ -106,22 +149,22 @@ function test_grade_item_update() {
$this->assertEqual($grade_item->iteminfo, $iteminfo);
}
- function test_grade_item_load_scale() {
+ function sub_test_grade_item_load_scale() {
$grade_item = new grade_item($this->grade_items[2]);
$this->assertTrue(method_exists($grade_item, 'load_scale'));
$scale = $grade_item->load_scale();
$this->assertFalse(empty($grade_item->scale));
$this->assertEqual($scale->id, $this->grade_items[2]->scaleid);
}
- function test_grade_item_load_outcome() {
+ function sub_test_grade_item_load_outcome() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'load_outcome'));
//TODO: add tests
}
- function test_grade_item_qualifies_for_regrading() {
- $grade_item = new grade_item($this->grade_items[0]);
+ function sub_test_grade_item_qualifies_for_regrading() {
+ $grade_item = new grade_item($this->grade_items[1]);//use a grade item not touched by previous tests
$this->assertTrue(method_exists($grade_item, 'qualifies_for_regrading'));
$this->assertFalse($grade_item->qualifies_for_regrading());
@@ -135,8 +178,8 @@ function test_grade_item_qualifies_for_regrading() {
$this->assertTrue($grade_item->qualifies_for_regrading());
}
- function test_grade_item_force_regrading() {
- $grade_item = new grade_item($this->grade_items[0]);
+ function sub_test_grade_item_force_regrading() {
+ $grade_item = new grade_item($this->grade_items[2]);//use a grade item not touched by previous tests
$this->assertTrue(method_exists($grade_item, 'force_regrading'));
$this->assertEqual(0, $grade_item->needsupdate);
@@ -147,29 +190,30 @@ function test_grade_item_force_regrading() {
$this->assertEqual(1, $grade_item->needsupdate);
}
- function test_grade_item_fetch() {
+ function sub_test_grade_item_fetch() {
$grade_item = new grade_item();
$this->assertTrue(method_exists($grade_item, 'fetch'));
- $grade_item = grade_item::fetch(array('id'=>$this->grade_items[0]->id));
- $this->assertEqual($this->grade_items[0]->id, $grade_item->id);
- $this->assertEqual($this->grade_items[0]->iteminfo, $grade_item->iteminfo);
+ //not using $this->grade_items[0] as it's iteminfo was modified by sub_test_grade_item_qualifies_for_regrading()
+ $grade_item = grade_item::fetch(array('id'=>$this->grade_items[1]->id));
+ $this->assertEqual($this->grade_items[1]->id, $grade_item->id);
+ $this->assertEqual($this->grade_items[1]->iteminfo, $grade_item->iteminfo);
$grade_item = grade_item::fetch(array('itemtype'=>$this->grade_items[1]->itemtype, 'itemmodule'=>$this->grade_items[1]->itemmodule));
$this->assertEqual($this->grade_items[1]->id, $grade_item->id);
$this->assertEqual($this->grade_items[1]->iteminfo, $grade_item->iteminfo);
}
- function test_grade_item_fetch_all() {
+ function sub_test_grade_item_fetch_all() {
$grade_item = new grade_item();
$this->assertTrue(method_exists($grade_item, 'fetch_all'));
$grade_items = grade_item::fetch_all(array('courseid'=>$this->courseid));
- $this->assertEqual(count($this->grade_items), count($grade_items)-1);
+ $this->assertEqual(count($this->grade_items), count($grade_items)-1);//-1 to account for the course grade item
}
// Retrieve all final scores for a given grade_item.
- function test_grade_item_get_all_finals() {
+ function sub_test_grade_item_get_all_finals() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'get_final'));
@@ -179,28 +223,28 @@ function test_grade_item_get_all_finals() {
// Retrieve all final scores for a specific userid.
- function test_grade_item_get_final() {
+ function sub_test_grade_item_get_final() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'get_final'));
$final_grade = $grade_item->get_final($this->userid);
$this->assertEqual($this->grade_grades[0]->finalgrade, $final_grade->finalgrade);
}
- function test_grade_item_get_sortorder() {
+ function sub_test_grade_item_get_sortorder() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'get_sortorder'));
$sortorder = $grade_item->get_sortorder();
$this->assertEqual($this->grade_items[0]->sortorder, $sortorder);
}
- function test_grade_item_set_sortorder() {
+ function sub_test_grade_item_set_sortorder() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'set_sortorder'));
$grade_item->set_sortorder(999);
$this->assertEqual($grade_item->sortorder, 999);
}
- function test_grade_item_move_after_sortorder() {
+ function sub_test_grade_item_move_after_sortorder() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'move_after_sortorder'));
$grade_item->move_after_sortorder(5);
@@ -213,15 +257,15 @@ function test_grade_item_move_after_sortorder() {
$this->assertEqual($after->sortorder, 8);
}
- function test_grade_item_get_name() {
+ function sub_test_grade_item_get_name() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'get_name'));
$name = $grade_item->get_name();
$this->assertEqual($this->grade_items[0]->itemname, $name);
}
- function test_grade_item_set_parent() {
+ function sub_test_grade_item_set_parent() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'set_parent'));
@@ -237,15 +281,15 @@ function test_grade_item_set_parent() {
$this->assertEqual($grade_item->categoryid, $new->id);
}
- function test_grade_item_get_parent_category() {
+ function sub_test_grade_item_get_parent_category() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'get_parent_category'));
$category = $grade_item->get_parent_category();
$this->assertEqual($this->grade_categories[1]->fullname, $category->fullname);
}
- function test_grade_item_load_parent_category() {
+ function sub_test_grade_item_load_parent_category() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'load_parent_category'));
@@ -254,15 +298,15 @@ function test_grade_item_load_parent_category() {
$this->assertEqual($this->grade_categories[1]->fullname, $grade_item->parent_category->fullname);
}
- function test_grade_item_get_item_category() {
+ function sub_test_grade_item_get_item_category() {
$grade_item = new grade_item($this->grade_items[3]);
$this->assertTrue(method_exists($grade_item, 'get_item_category'));
$category = $grade_item->get_item_category();
$this->assertEqual($this->grade_categories[0]->fullname, $category->fullname);
}
- function test_grade_item_load_item_category() {
+ function sub_test_grade_item_load_item_category() {
$grade_item = new grade_item($this->grade_items[3]);
$this->assertTrue(method_exists($grade_item, 'load_item_category'));
@@ -272,15 +316,15 @@ function test_grade_item_load_item_category() {
}
// Test update of all final grades
- function test_grade_item_regrade_final_grades() {
+ function sub_test_grade_item_regrade_final_grades() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'regrade_final_grades'));
$this->assertEqual(true, $grade_item->regrade_final_grades());
//TODO: add more tests
}
// Test the adjust_raw_grade method
- function test_grade_item_adjust_raw_grade() {
+ function sub_test_grade_item_adjust_raw_grade() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'adjust_raw_grade'));
$grade_raw = new stdClass();
@@ -341,19 +385,24 @@ function test_grade_item_adjust_raw_grade() {
}
// Test locking of grade items
- function test_grade_item_set_locked() {
- $grade_item = new grade_item($this->grade_items[0]);
+ function sub_test_grade_item_set_locked() {
+
+ //getting a grade_item from the DB as set_locked() will fail if the grade items needs to be updated
+ //also needs to have at least one grade_grade or $grade_item->get_final(1) returns null
+ //$grade_item = new grade_item($this->grade_items[8]);
+ $grade_item = grade_item::fetch(array('id'=>$this->grade_items[8]->id));
+
$this->assertTrue(method_exists($grade_item, 'set_locked'));
- $grade = new grade_grade($grade_item->get_final(1));
- $this->assertTrue(empty($grade_item->locked));
- $this->assertTrue(empty($grade->locked));
+ $grade_grade = new grade_grade($grade_item->get_final(1));
+ $this->assertTrue(empty($grade_item->locked));//not locked
+ $this->assertTrue(empty($grade_grade->locked));//not locked
$this->assertTrue($grade_item->set_locked(true, true, false));
- $grade = new grade_grade($grade_item->get_final(1));
+ $grade_grade = new grade_grade($grade_item->get_final(1));
- $this->assertFalse(empty($grade_item->locked));
- $this->assertFalse(empty($grade->locked)); // individual grades should be locked too
+ $this->assertFalse(empty($grade_item->locked));//locked
+ $this->assertFalse(empty($grade_grade->locked)); // individual grades should be locked too
$this->assertTrue($grade_item->set_locked(false, true, false));
$grade = new grade_grade($grade_item->get_final(1));
@@ -362,8 +411,8 @@ function test_grade_item_set_locked() {
$this->assertTrue(empty($grade->locked)); // individual grades should be unlocked too
}
- function test_grade_item_is_locked() {
- $grade_item = new grade_item($this->grade_items[0]);
+ function sub_test_grade_item_is_locked() {
+ $grade_item = new grade_item($this->grade_items[10]);
$this->assertTrue(method_exists($grade_item, 'is_locked'));
$this->assertFalse($grade_item->is_locked());
@@ -374,7 +423,7 @@ function test_grade_item_is_locked() {
}
// Test hiding of grade items
- function test_grade_item_set_hidden() {
+ function sub_test_grade_item_set_hidden() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'set_hidden'));
@@ -389,7 +438,7 @@ function test_grade_item_set_hidden() {
$this->assertEqual(666, $grade->hidden);
}
- function test_grade_item_is_hidden() {
+ function sub_test_grade_item_is_hidden() {
$grade_item = new grade_item($this->grade_items[0]);
$this->assertTrue(method_exists($grade_item, 'is_hidden'));
@@ -409,25 +458,25 @@ function test_grade_item_is_hidden() {
$this->assertTrue($grade_item->is_hidden(1));
}
- function test_grade_item_is_category_item() {
+ function sub_test_grade_item_is_category_item() {
$grade_item = new grade_item($this->grade_items[3]);
$this->assertTrue(method_exists($grade_item, 'is_category_item'));
$this->assertTrue($grade_item->is_category_item());
}
- function test_grade_item_is_course_item() {
+ function sub_test_grade_item_is_course_item() {
$grade_item = grade_item::fetch_course_item($this->courseid);
$this->assertTrue(method_exists($grade_item, 'is_course_item'));
$this->assertTrue($grade_item->is_course_item());
}
- function test_grade_item_fetch_course_item() {
+ function sub_test_grade_item_fetch_course_item() {
$grade_item = grade_item::fetch_course_item($this->courseid);
$this->assertTrue(method_exists($grade_item, 'fetch_course_item'));
$this->assertTrue($grade_item->itemtype, 'course');
}
- function test_grade_item_depends_on() {
+ function sub_test_grade_item_depends_on() {
$grade_item = new grade_item($this->grade_items[1]);
// calculated grade dependency
@@ -450,7 +499,7 @@ function test_grade_item_depends_on() {
$this->assertEqual($res, $deps);
}
- function test_grade_item_is_calculated() {
+ function sub_test_grade_item_is_calculated() {
$grade_item = new mock_grade_item_for_test_is_calculated($this);
$grade_item->set_properties($grade_item, $this->grade_items[1]);
$this->assertTrue(method_exists($grade_item, 'is_calculated'));
@@ -462,7 +511,7 @@ function test_grade_item_is_calculated() {
$this->assertTrue($grade_item->is_calculated());
}
- function test_grade_item_set_calculation() {
+ function sub_test_grade_item_set_calculation() {
$grade_item = new grade_item($this->grade_items[1]);
$this->assertTrue(method_exists($grade_item, 'set_calculation'));
$grade_itemsource = new grade_item($this->grade_items[0]);
@@ -473,7 +522,7 @@ function test_grade_item_set_calculation() {
$this->assertEqual('=##gi'.$grade_itemsource->id.'##', $grade_item->calculation);
}
- function test_grade_item_get_calculation() {
+ function sub_test_grade_item_get_calculation() {
$grade_item = new grade_item($this->grade_items[1]);
$this->assertTrue(method_exists($grade_item, 'get_calculation'));
$grade_itemsource = new grade_item($this->grade_items[0]);
@@ -485,22 +534,32 @@ function test_grade_item_get_calculation() {
$this->assertEqual($denormalizedformula, $formula);
}
- function test_grade_item_compute() {
- $grade_item = new grade_item($this->grade_items[1]);
+ function sub_test_grade_item_compute() {
+ $grade_item = grade_item::fetch(array('id'=>$this->grade_items[1]->id));
$this->assertTrue(method_exists($grade_item, 'compute'));
+ //check the grade_grades in the array match those in the DB then delete $this->grade_items[1]'s grade_grades
+ $this->grade_grades[3] = grade_grade::fetch(array('id'=>$this->grade_grades[3]->id));
$grade_grade = grade_grade::fetch(array('id'=>$this->grade_grades[3]->id));
$grade_grade->delete();
+
+ $this->grade_grades[4] = grade_grade::fetch(array('id'=>$this->grade_grades[4]->id));
$grade_grade = grade_grade::fetch(array('id'=>$this->grade_grades[4]->id));
$grade_grade->delete();
+
+ $this->grade_grades[5] = grade_grade::fetch(array('id'=>$this->grade_grades[5]->id));
$grade_grade = grade_grade::fetch(array('id'=>$this->grade_grades[5]->id));
$grade_grade->delete();
+ //recalculate the grades (its a calculation so pulls values from other grade_items) and reinsert them
$grade_item->compute();
+
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[3]->userid, 'itemid'=>$this->grade_grades[3]->itemid));
$this->assertEqual($this->grade_grades[3]->finalgrade, $grade_grade->finalgrade);
+
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[4]->userid, 'itemid'=>$this->grade_grades[4]->itemid));
$this->assertEqual($this->grade_grades[4]->finalgrade, $grade_grade->finalgrade);
+
$grade_grade = grade_grade::fetch(array('userid'=>$this->grade_grades[5]->userid, 'itemid'=>$this->grade_grades[5]->itemid));
$this->assertEqual($this->grade_grades[5]->finalgrade, $grade_grade->finalgrade);
View
21 lib/grade/simpletest/testgradeoutcome.php
@@ -39,7 +39,16 @@
class grade_outcome_test extends grade_test {
- function test_grade_outcome_construct() {
+ function test_grade_outcome() {
+ $this->sub_test_grade_outcome_construct();
+ $this->sub_test_grade_outcome_insert();
+ $this->sub_test_grade_outcome_update();
+ $this->sub_test_grade_outcome_delete();
+ //$this->sub_test_grade_outcome_fetch();
+ $this->sub_test_grade_outcome_fetch_all();
+ }
+
+ function sub_test_grade_outcome_construct() {
$params = new stdClass();
$params->courseid = $this->courseid;
@@ -50,7 +59,7 @@ function test_grade_outcome_construct() {
$this->assertEqual($params->shortname, $grade_outcome->shortname);
}
- function test_grade_outcome_insert() {
+ function sub_test_grade_outcome_insert() {
$grade_outcome = new grade_outcome();
$this->assertTrue(method_exists($grade_outcome, 'insert'));
@@ -67,7 +76,7 @@ function test_grade_outcome_insert() {
$this->assertFalse(empty($grade_outcome->timemodified));
}
- function test_grade_outcome_update() {
+ function sub_test_grade_outcome_update() {
global $DB;
$grade_outcome = new grade_outcome($this->grade_outcomes[0]);
$this->assertTrue(method_exists($grade_outcome, 'update'));
@@ -77,7 +86,7 @@ function test_grade_outcome_update() {
$this->assertEqual($grade_outcome->shortname, $shortname);
}
- function test_grade_outcome_delete() {
+ function sub_test_grade_outcome_delete() {
global $DB;
$grade_outcome = new grade_outcome($this->grade_outcomes[0]);
$this->assertTrue(method_exists($grade_outcome, 'delete'));
@@ -86,7 +95,7 @@ function test_grade_outcome_delete() {
$this->assertFalse($DB->get_record('grade_outcomes', array('id' => $grade_outcome->id)));
}
- function test_grade_outcome_fetch() {
+ function sub_test_grade_outcome_fetch() {
$grade_outcome = new grade_outcome();
$this->assertTrue(method_exists($grade_outcome, 'fetch'));
@@ -98,7 +107,7 @@ function test_grade_outcome_fetch() {
$this->assertEqual($this->scale[2]->id, $grade_outcome->scale->id);
}
- function test_grade_outcome_fetch_all() {
+ function sub_test_grade_outcome_fetch_all() {
$grade_outcome = new grade_outcome();
$this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
View
33 lib/grade/simpletest/testgradescale.php
@@ -39,7 +39,17 @@
class grade_scale_test extends grade_test {
- function test_scale_construct() {
+ function test_grade_scale() {
+ $this->sub_test_scale_construct();
+ $this->sub_test_grade_scale_insert();
+ $this->sub_test_grade_scale_update();
+ $this->sub_test_grade_scale_delete();
+ $this->sub_test_grade_scale_fetch();
+ $this->sub_test_scale_load_items();
+ $this->sub_test_scale_compact_items();
+ }
+
+ function sub_test_scale_construct() {
$params = new stdClass();
$params->name = 'unittestscale3';
@@ -57,7 +67,7 @@ function test_scale_construct() {
}
- function test_grade_scale_insert() {
+ function sub_test_grade_scale_insert() {
$grade_scale = new grade_scale();
$this->assertTrue(method_exists($grade_scale, 'insert'));
@@ -76,27 +86,30 @@ function test_grade_scale_insert() {
$this->assertTrue(!empty($grade_scale->timemodified));
}
- function test_grade_scale_update() {
+ function sub_test_grade_scale_update() {
global $DB;
- $grade_scale = new grade_scale($this->scale[0]);
+ $grade_scale = new grade_scale($this->scale[1]);
$this->assertTrue(method_exists($grade_scale, 'update'));
$grade_scale->name = 'Updated info for this unittest grade_scale';
$this->assertTrue($grade_scale->update());
- $name = $DB->get_field('scale', 'name', array('id' => $this->scale[0]->id));
+ $name = $DB->get_field('scale', 'name', array('id' => $this->scale[1]->id));
$this->assertEqual($grade_scale->name, $name);
}
- function test_grade_scale_delete() {
+ function sub_test_grade_scale_delete() {
global $DB;
- $grade_scale = new grade_scale($this->scale[0]);
+ $grade_scale = new grade_scale($this->scale[4]);//choose one we're not using elsewhere
$this->assertTrue(method_exists($grade_scale, 'delete'));
$this->assertTrue($grade_scale->delete());
$this->assertFalse($DB->get_record('scale', array('id' => $grade_scale->id)));
+
+ //keep the reference collection the same as what is in the database
+ unset($this->scale[4]);
}
- function test_grade_scale_fetch() {
+ function sub_test_grade_scale_fetch() {
$grade_scale = new grade_scale();
$this->assertTrue(method_exists($grade_scale, 'fetch'));
@@ -105,7 +118,7 @@ function test_grade_scale_fetch() {
$this->assertEqual($this->scale[0]->name, $grade_scale->name);
}
- function test_scale_load_items() {
+ function sub_test_scale_load_items() {
$scale = new grade_scale($this->scale[0]);
$this->assertTrue(method_exists($scale, 'load_items'));
@@ -115,7 +128,7 @@ function test_scale_load_items() {
}
- function test_scale_compact_items() {
+ function sub_test_scale_compact_items() {
$scale = new grade_scale($this->scale[0]);
$this->assertTrue(method_exists($scale, 'compact_items'));

0 comments on commit 2b574cc

Please sign in to comment.