]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17412: Completion system unit tests were broken
authorsam_marshall <sam_marshall>
Wed, 26 Nov 2008 13:59:24 +0000 (13:59 +0000)
committersam_marshall <sam_marshall>
Wed, 26 Nov 2008 13:59:24 +0000 (13:59 +0000)
lib/completionlib.php
lib/simpletest/testcompletionlib.php

index 5e979ef9d21ad7b3210e1ba258c1412a556642d3..dc8a0f2339532e0b384b9933190027a4ca216c95 100644 (file)
@@ -623,7 +623,7 @@ class completion_info {
         $users = $this->internal_get_tracked_users($sortfirstname, $groupid);
         $resultobject->start=$start;
         $resultobject->total=count($users);
-        $users=array_slice($users,$start,$pagesize);
+        $users=array_slice($users,$start,$pagesize==0 ? count($users)-$start : $pagesize);
 
         // Get progress information for these users in groups of 1, 000 (if needed)
         // to avoid making the SQL IN too long
@@ -649,9 +649,6 @@ FROM
 WHERE
     cm.course=? AND cmc.userid $insql
     ", $params);
-            if (!$rs) {
-                $this->internal_systemerror('Failed to obtain completion progress');
-            }
             foreach ($rs as $progress) {
                 $resultobject->users[$progress->userid]->progress[$progress->coursemoduleid]=$progress;
             }
index 227d470a689b51dae074c0f35ee52e43961dd5fe..d3e64e460623d82ff7f2fdb564828f6086885ea1 100644 (file)
@@ -90,7 +90,7 @@ class TimeModifiedExpectation extends SimpleExpectation {
 class completionlib_test extends MoodleUnitTestCase {
     var $realdb,$realcfg,$realsession,$realuser;
 
-    function setUp() {
+    function setUp() {        
         global $DB,$CFG,$SESSION,$USER;
         $this->realdb=$DB;
         $this->realcfg=$CFG;
@@ -327,7 +327,8 @@ WHERE
         $c=new completion_cutdown();
         $c->__construct((object)array('id'=>42));
 
-        $cm=(object)array('id'=>13,'course'=>42);
+        $cm=(object)array('id'=>13,'course'=>42,
+            'completion'=>COMPLETION_TRACKING_AUTOMATIC);
 
         $DB->setReturnValue('get_recordset',new fake_recordset(array(
             (object)array('id'=>1,'userid'=>100),
@@ -525,12 +526,14 @@ WHERE
             $progress1,$progress2
         )));
 
-        $this->assertEqual(array(
-           100 => (object)array('id'=>100,'firstname'=>'Woot','lastname'=>'Plugh',
-               'progress'=>array(13=>$progress1)),
-           201 => (object)array('id'=>201,'firstname'=>'Vroom','lastname'=>'Xyzzy',
-               'progress'=>array(14=>$progress2)),
-       ),$c->get_progress_all(false));
+        $this->assertEqual((object)array(
+            'start'=>0,'total'=>2,
+            'users'=>array(
+                100 => (object)array('id'=>100,'firstname'=>'Woot','lastname'=>'Plugh',
+                    'progress'=>array(13=>$progress1)),
+                201 => (object)array('id'=>201,'firstname'=>'Vroom','lastname'=>'Xyzzy',
+                    'progress'=>array(14=>$progress2)),
+            )),$c->get_progress_all(false));
 
         // 2) With more than 1,000 results
         $c->expectAt(1,'internal_get_tracked_users',array(true,3));
@@ -572,8 +575,8 @@ WHERE
         $result=$c->get_progress_all(true,3);
 
         $resultok=true;
-        $resultok = $resultok && ($ids==array_keys($result));
-        foreach($result as $userid => $data) {
+        $resultok = $resultok && ($ids==array_keys($result->users));
+        foreach($result->users as $userid => $data) {
             $resultok = $resultok && $data->firstname=='frog';
             $resultok = $resultok && $data->lastname==$userid;
             $resultok = $resultok && $data->id==$userid;