* category1 => array(category2 => array(grade_item1, grade_item2), category3 => array(grade_item3))
* 3 users for 3 grade_items
*/
-class grade_test extends FakeDBUnitTestCase {
-
- public $grade_tables = array('grade_categories',
- 'scale',
- 'grade_items',
- 'grade_grades',
- 'grade_outcomes');
-
+class grade_test extends UnitTestCaseUsingDatabase {
+
+ public $grade_tables = array('lib' => array(
+ 'grade_categories', 'grade_categories_history',
+ 'scale', 'scale_history',
+ 'grade_items', 'grade_items_history',
+ 'grade_grades', 'grade_grades_history',
+ 'grade_outcomes', 'grade_outcomes_history','grade_outcomes_courses',
+ 'files',
+ 'modules',
+ 'course_modules'),
+ 'mod/quiz' => array('quiz')
+ );
public $grade_items = array();
public $grade_categories = array();
* These tests have to work on a brand new site.
*/
function setUp() {
- global $CFG, $DB;
+ global $CFG;
parent::setup();
$CFG->grade_droplow = -1;
$CFG->grade_aggregateoutcomes = -1;
$CFG->grade_aggregatesubcats = -1;
- foreach ($this->grade_tables as $table) {
- $function = "load_$table";
- $this->$function();
+ $this->switch_to_test_db(); // All operations until end of test method will happen in test DB
+
+ foreach ($this->grade_tables as $dir => $tables) {
+ $this->create_test_tables($tables, $dir); // Create tables
+ foreach ($tables as $table) { // Fill them if load_xxx method is available
+ $function = "load_$table";
+ if (method_exists($this, $function)) {
+ $this->$function();
+ }
+ }
}
+
}
- /**
- * Drop test tables from DB.
- */
function tearDown() {
- // delete the contents of tables before the test run - the unit test might fail on fatal error and the data would not be deleted!
- foreach ($this->grade_tables as $table) {
- unset($this->$table);
- }
- parent::tearDown();
+ parent::tearDown(); // All the test tables created in setUp will be dropped by this
}
/**
}
/**
- * Load module entries in modules table\
+ * Load module entries in modules table
*/
function load_modules() {
global $DB;