Fixing unit test failures

This commit is contained in:
nicolasconnault 2007-10-27 10:13:25 +00:00
parent 96aad15ced
commit 1994d890c9
8 changed files with 263 additions and 88 deletions

View file

@ -364,7 +364,7 @@ class grade_category extends grade_object {
/**
* Generates and saves raw_grades in associated category grade item.
* These immediate children must alrady have their own final grades.
* These immediate children must already have their own final grades.
* The category's aggregation method is used to generate raw grades.
*
* Please note that category grade is either calculated or aggregated - not both at the same time.
@ -446,6 +446,13 @@ class grade_category extends grade_object {
/**
* internal function for category grades aggregation
*
* @param int $userid
* @param array $items
* @param array $grade_values
* @param float $oldgrade
* @param bool $excluded
* @return boolean (just plain return;)
*/
function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded) {
global $CFG;

View file

@ -7,7 +7,7 @@
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //

View file

@ -7,7 +7,7 @@
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
@ -1250,7 +1250,7 @@ class grade_item extends grade_object {
}
/**
* Refetch grades from moudles, plugins.
* Refetch grades from modules, plugins.
* @param int $userid optional, one user only
*/
function refresh_grades($userid=0) {
@ -1261,12 +1261,12 @@ class grade_item extends grade_object {
}
if (!$activity = get_record($this->itemmodule, 'id', $this->iteminstance)) {
debugging('Can not find activity');
debugging("Can not find $this->itemmodule activity with id $this->iteminstance");
return;
}
if (! $cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid)) {
debuggin('Can not find course module');
if (!$cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid)) {
debugging('Can not find course module');
return;
}

View file

@ -7,7 +7,7 @@
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
@ -222,15 +222,16 @@ class grade_category_test extends grade_test {
$category->generate_grades();
$grades = get_records('grade_grades', 'itemid', $category->grade_item->id);
$this->assertEqual(3, count($grades));
$rawvalues = array();
// Category grades do not have raw values
$finalvalues = array();
foreach ($grades as $grade) {
$this->assertWithinMargin($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
$rawvalues[] = (int)$grade->rawgrade;
$this->assertWithinMargin($grade->finalgrade, $grade->rawgrademin, $grade->rawgrademax);
$finalvalues[] = (int)$grade->finalgrade;
}
sort($rawvalues);
sort($finalvalues);
// calculated mean results
$this->assertEqual($rawvalues, array(20,50,100));
$this->assertEqual($finalvalues, array(20,50,100));
}
function test_grade_category_aggregate_grades() {

View file

@ -7,7 +7,7 @@
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
@ -122,17 +122,20 @@ class grade_grade_test extends grade_test {
$this->assertTrue(empty($grade_item->locked));
$this->assertTrue(empty($grade->locked));
// Test locking the grade
$this->assertTrue($grade->set_locked(true));
$this->assertFalse(empty($grade->locked));
$this->assertTrue($grade->set_locked(false));
$this->assertTrue(empty($grade->locked));
$this->assertTrue($grade_item->set_locked(true));
// Test locking the grade item with cascading on
$this->assertTrue($grade_item->set_locked(true, true, false));
$grade = new grade_grade($grade_item->get_final(1));
$this->assertFalse(empty($grade->locked));
$this->assertFalse($grade->set_locked(false));
// Grade should already be locked
$this->assertFalse(empty($grade->locked));
$this->assertTrue($grade->set_locked(false));
$this->assertTrue($grade_item->set_locked(false));
$grade = new grade_grade($grade_item->get_final(1));

View file

@ -355,7 +355,7 @@ class grade_item_test extends grade_test {
$this->assertTrue(empty($grade_item->locked));
$this->assertTrue(empty($grade->locked));
$this->assertTrue($grade_item->set_locked(true));
$this->assertTrue($grade_item->set_locked(true, true));
$grade = new grade_grade($grade_item->get_final(1));
$this->assertFalse(empty($grade_item->locked));