diff --git a/lib/completionlib.php b/lib/completionlib.php
index f1ffb58..49bed81 100644
--- a/lib/completionlib.php
+++ b/lib/completionlib.php
@@ -471,6 +471,11 @@ class completion_info {
             return;
         }
 
+        // get current user ID if not given
+        if (!$userid) {
+            $userid = $USER->id;
+        }
+
         // Get current value of completion state and do nothing if it's same as
         // the possible result of this change. If the change is to COMPLETE and the
         // current value is one of the COMPLETE_xx subtypes, ignore that as well
@@ -609,7 +614,8 @@ class completion_info {
      * @return void
      */
     public function set_module_viewed($cm, $userid=0) {
-        global $PAGE, $UNITTEST;
+        global $PAGE, $UNITTEST, $USER;
+
         if ($PAGE->headerprinted && empty($UNITTEST->running)) {
             debugging('set_module_viewed must be called before header is printed',
                     DEBUG_DEVELOPER);
@@ -618,6 +624,10 @@ class completion_info {
         if ($cm->completionview == COMPLETION_VIEW_NOT_REQUIRED || !$this->is_enabled($cm)) {
             return;
         }
+        // get current user ID if not given
+        if (!$userid) {
+            $userid = $USER->id;
+        }
         // Get current completion state
         $data = $this->get_data($cm, $userid);
         // If we already viewed it, don't do anything
diff --git a/lib/simpletest/testcompletionlib.php b/lib/simpletest/testcompletionlib.php
index 1496494..6ab71d1 100644
--- a/lib/simpletest/testcompletionlib.php
+++ b/lib/simpletest/testcompletionlib.php
@@ -165,7 +165,7 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
         $c->expectAt(1,'is_enabled',array($cm));
         $c->setReturnValueAt(1,'is_enabled',true);
 
-        $c->expectAt(0,'get_data',array($cm,false,0));
+        $c->expectAt(0,'get_data',array($cm,false,314159));
         $c->setReturnValueAt(0,'get_data',$current);
         $c->update_state($cm,COMPLETION_COMPLETE);
 
@@ -174,7 +174,7 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
         $current->completionstate=COMPLETION_COMPLETE_PASS;
         $c->expectAt(2,'is_enabled',array($cm));
         $c->setReturnValueAt(2,'is_enabled',true);
-        $c->expectAt(1,'get_data',array($cm,false,0));
+        $c->expectAt(1,'get_data',array($cm,false,314159));
         $c->setReturnValueAt(1,'get_data',$current);
         $c->update_state($cm,COMPLETION_COMPLETE);
 
@@ -183,14 +183,14 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
         $current->completionstate=COMPLETION_COMPLETE;
         $c->expectAt(3,'is_enabled',array($cm));
         $c->setReturnValueAt(3,'is_enabled',true);
-        $c->expectAt(2,'get_data',array($cm,false,0));
+        $c->expectAt(2,'get_data',array($cm,false,314159));
         $c->setReturnValueAt(2,'get_data',$current);
         $c->update_state($cm,COMPLETION_COMPLETE);
 
         // Manual, change state (change)
         $c->expectAt(4,'is_enabled',array($cm));
         $c->setReturnValueAt(4,'is_enabled',true);
-        $c->expectAt(3,'get_data',array($cm,false,0));
+        $c->expectAt(3,'get_data',array($cm,false,314159));
         $c->setReturnValueAt(3,'get_data',$current);
         $c->expectAt(0,'internal_set_data',array($cm,
             new TimeModifiedExpectation(array('completionstate'=>COMPLETION_INCOMPLETE))));
@@ -200,9 +200,9 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
         $cm->completion=COMPLETION_TRACKING_AUTOMATIC;
         $c->expectAt(5,'is_enabled',array($cm));
         $c->setReturnValueAt(5,'is_enabled',true);
-        $c->expectAt(4,'get_data',array($cm,false,0));
+        $c->expectAt(4,'get_data',array($cm,false,314159));
         $c->setReturnValueAt(4,'get_data',$current);
-        $c->expectAt(0,'internal_get_state',array($cm,0,$current));
+        $c->expectAt(0,'internal_get_state',array($cm,314159,$current));
         $c->setReturnValueAt(0,'internal_get_state',COMPLETION_COMPLETE_PASS);
         $c->expectAt(1,'internal_set_data',array($cm,
             new TimeModifiedExpectation(array('completionstate'=>COMPLETION_COMPLETE_PASS))));
@@ -265,7 +265,7 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
         // viewed, still do nothing
         $c->expectAt(1,'is_enabled',array($cm));
         $c->setReturnValueAt(1,'is_enabled',true);
-        $c->expectAt(0,'get_data',array($cm,0));
+        $c->expectAt(0,'get_data',array($cm,314159));
         $hasviewed=(object)array('viewed'=>COMPLETION_VIEWED);
         $c->setReturnValueAt(0,'get_data',$hasviewed);
         $c->set_module_viewed($cm);
