]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14065 Fixed gradebook unit tests, including a bug fix in grade_item class
authornicolasconnault <nicolasconnault>
Thu, 27 Mar 2008 12:08:36 +0000 (12:08 +0000)
committernicolasconnault <nicolasconnault>
Thu, 27 Mar 2008 12:08:36 +0000 (12:08 +0000)
lib/grade/grade_item.php
lib/grade/simpletest/testgradegrades.php
lib/grade/simpletest/testgradeitem.php

index cada10519701d49d48c9a96ad2f08ffd780041ef..3db1376de888d53db381b4e76b443a11f00b0fd6 100644 (file)
@@ -980,7 +980,7 @@ class grade_item extends grade_object {
          */
 
         // first detect if we need to change calculation formula from [[idnumber]] to ##giXXX## (after backup, etc.)
-        if (!$this->calculation_normalized and strpos('[[', $this->calculation) !== false) {
+        if (!$this->calculation_normalized and strpos($this->calculation, '[[') !== false) {
             $this->set_calculation($this->calculation);
         }
 
index 33430579e2aa2bb0f87ba46600d15d4f08509ea2..5975603fbbc701ced9ba988b9a10bba0f05b190a 100755 (executable)
@@ -72,8 +72,11 @@ class grade_grade_test extends grade_test {
         $last_grade_grade = end($this->grade_grades);
 
         $this->assertEqual($grade_grade->id, $last_grade_grade->id + 1);
-        $this->assertFalse(empty($grade_grade->timecreated));
-        $this->assertFalse(empty($grade_grade->timemodified));
+
+        // timecreated will only be set if the grade was submitted by an activity module
+        $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));
     }
 
     function test_grade_grade_update() {
index e679086ec61c353a676bee904427dba80767fac5..771334d1088eca4d739825264d59472e24167e8c 100755 (executable)
@@ -37,10 +37,12 @@ if (!defined('MOODLE_INTERNAL')) {
 
 require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
 
+Mock::generatePartial('grade_item', 'mock_grade_item_for_test_is_calculated', array('set_calculation'));
+
 @set_time_limit(0);
 
 class grade_item_test extends grade_test {
-
+    
     function test_grade_item_construct() {
         $params = new stdClass();
 
@@ -164,9 +166,7 @@ class grade_item_test extends grade_test {
         $this->assertEqual(count($this->grade_items), count($grade_items)-1);
     }
 
-    /**
-     * Retrieve all final scores for a given grade_item.
-     */
+    // Retrieve all final scores for a given grade_item.
     function test_grade_item_get_all_finals() {
         $grade_item = new grade_item($this->grade_items[0]);
         $this->assertTrue(method_exists($grade_item, 'get_final'));
@@ -176,9 +176,7 @@ class grade_item_test extends grade_test {
     }
 
 
-    /**
-     * Retrieve all final scores for a specific userid.
-     */
+    // Retrieve all final scores for a specific userid.
     function test_grade_item_get_final() {
         $grade_item = new grade_item($this->grade_items[0]);
         $this->assertTrue(method_exists($grade_item, 'get_final'));
@@ -271,9 +269,7 @@ class grade_item_test extends grade_test {
         $this->assertEqual($this->grade_categories[0]->fullname, $grade_item->item_category->fullname);
     }
 
-    /**
-     * Test update of all final grades
-     */
+    // Test update of all final grades
     function test_grade_item_regrade_final_grades() {
         $grade_item = new grade_item($this->grade_items[0]);
         $this->assertTrue(method_exists($grade_item, 'regrade_final_grades'));
@@ -281,9 +277,7 @@ class grade_item_test extends grade_test {
         //TODO: add more tests
     }
 
-    /**
-     * Test the adjust_raw_grade method
-     */
+    // Test the adjust_raw_grade method
     function test_grade_item_adjust_raw_grade() {
         $grade_item = new grade_item($this->grade_items[0]);
         $this->assertTrue(method_exists($grade_item, 'adjust_raw_grade'));
@@ -344,9 +338,7 @@ class grade_item_test extends grade_test {
         $this->assertEqual(round(1.6), round($grade_item->adjust_raw_grade($grade_raw->rawgrade, $grade_raw->grademin, $grade_raw->grademax)));
     }
 
-    /**
-     * Test locking of grade items
-     */
+    // Test locking of grade items
     function test_grade_item_set_locked() {
         $grade_item = new grade_item($this->grade_items[0]);
         $this->assertTrue(method_exists($grade_item, 'set_locked'));
@@ -379,9 +371,7 @@ class grade_item_test extends grade_test {
         $this->assertTrue($grade_item->is_locked(1));
     }
 
-    /**
-     * Test hiding of grade items
-     */
+    // Test hiding of grade items
     function test_grade_item_set_hidden() {
         $grade_item = new grade_item($this->grade_items[0]);
         $this->assertTrue(method_exists($grade_item, 'set_hidden'));
@@ -457,15 +447,17 @@ class grade_item_test extends grade_test {
         $res = array($this->grade_items[4]->id, $this->grade_items[5]->id);
         $this->assertEqual($res, $deps);
     }
-
+    
     function test_grade_item_is_calculated() {
-        $grade_item = new grade_item($this->grade_items[1]);
+        $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'));
         $grade_itemsource = new grade_item($this->grade_items[0]);
-        $normalizedformula = str_replace('[['.$grade_itemsource->idnumber.']]', '##gi'.$grade_itemsource->id.'##', $this->grade_items[1]->calculation);
-
+        $normalizedformula = str_replace("[[$grade_itemsource->idnumber]]", "##gi$grade_itemsource->id##", $this->grade_items[1]->calculation);
+        
+        $grade_item->expectOnce('set_calculation', array($grade_item->calculation));
+        $grade_item->setReturnValue('set_calculation', $normalizedformula);
         $this->assertTrue($grade_item->is_calculated());
-        $this->assertEqual($normalizedformula, $grade_item->calculation);
     }
 
     function test_grade_item_set_calculation() {