Skip to content

Commit

Permalink
MDL-12182 merging from MOODLE_19_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Mar 6, 2008
1 parent 43ea3f3 commit 4a88e24
Showing 1 changed file with 13 additions and 52 deletions.
65 changes: 13 additions & 52 deletions lib/grade/simpletest/testgradescale.php
Expand Up @@ -39,15 +39,6 @@

class grade_scale_test extends grade_test {

function setUp() {
parent::setUp();
$this->load_scale();
}

function tearDown() {
parent::tearDown();
}

function test_scale_construct() {
$params = new stdClass();

Expand All @@ -67,7 +58,6 @@ function test_scale_construct() {
}

function test_grade_scale_insert() {
global $db;
$grade_scale = new grade_scale();
$this->assertTrue(method_exists($grade_scale, 'insert'));

Expand All @@ -77,91 +67,62 @@ function test_grade_scale_insert() {
$grade_scale->scale = 'Distinction, Very Good, Good, Pass, Fail';
$grade_scale->description = 'This scale is used to mark standard assignments.';

// Mock insert of data in history table
$this->rs->setReturnValue('RecordCount', 1);
$this->rs->fields = array(1);

// Mock insert of outcome object
$db->setReturnValue('GetInsertSQL', true);
$db->setReturnValue('Insert_ID', 1);

$grade_scale->insert();

$this->assertEqual($grade_scale->id, 1);
$this->assertFalse(empty($grade_scale->timecreated));
$this->assertFalse(empty($grade_scale->timemodified));
$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));
}

function test_grade_scale_update() {
global $db;
$grade_scale = new grade_scale($this->scale[0], false);
$grade_scale = new grade_scale($this->scale[0]);
$this->assertTrue(method_exists($grade_scale, 'update'));

$grade_scale->timecreated = time() - 200000;
$grade_scale->timemodified = $grade_scale->timecreated;
$timemodified = $grade_scale->timemodified;
$timecreated = $grade_scale->timecreated;

// Mock update: MetaColumns is first returned to compare existing data with new
$column = new stdClass();
$column->name = 'name';
$db->setReturnValue('MetaColumns', array($column));

$grade_scale->name = 'Updated info for this unittest grade_scale';
$this->assertTrue($grade_scale->update());

// We expect timecreated to be unchanged, and timemodified to be updated
$this->assertTrue($grade_scale->timemodified > $timemodified);
$this->assertTrue($grade_scale->timemodified > $grade_scale->timecreated);
$this->assertTrue($grade_scale->timecreated == $timecreated);
$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], false);
$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() {
global $db;

$grade_scale = new grade_scale();
$this->assertTrue(method_exists($grade_scale, 'fetch'));

// Mock fetch
$column = new stdClass();
$column->name = 'id';
$this->rs->setReturnValue('FetchField', $column); // Fetching the name of the first column
$this->rs->setReturnValue('GetAssoc', array($this->scale[0]->id => (array) $this->scale[0]));

$grade_scale = grade_scale::fetch(array('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], false);
$scale = new grade_scale($this->scale[0]);
$this->assertTrue(method_exists($scale, 'load_items'));

$scale->load_items();
$this->assertEqual(7, count($scale->scale_items));
$this->assertEqual('Fairly neutral', $scale->scale_items[2]);

$newscale = 'Item1, Item2, Item3, Item4';
$this->assertEqual(4, count($scale->load_items($newscale)));
}

function test_scale_compact_items() {
$scale = new grade_scale($this->scale[0], false);
$scale = new grade_scale($this->scale[0]);
$this->assertTrue(method_exists($scale, 'compact_items'));

$scale->load_items();
$scale->scale = null;
$scale->compact_items();

// The original string and the new string may have differences in whitespace around the delimiter, and that's OK
$this->assertEqual(preg_replace('/\s*,\s*' . '/', ',', $this->scale[0]->scale), $scale->scale);
$this->assertEqual(preg_replace('/\s*,\s*/', ',', $this->scale[0]->scale), $scale->scale);
}
}
?>

0 comments on commit 4a88e24

Please sign in to comment.