Unit tests MDL-24976 Fixed conditionlib unit test (also added thing to ensure that...
authorSam Marshall <s.marshall@open.ac.uk>
Tue, 2 Nov 2010 15:04:21 +0000 (15:04 +0000)
committerSam Marshall <s.marshall@open.ac.uk>
Tue, 2 Nov 2010 15:04:21 +0000 (15:04 +0000)
lib/conditionlib.php
lib/simpletest/testconditionlib.php

index b4fa319..c99029a 100644 (file)
@@ -396,8 +396,8 @@ WHERE
                     $modinfo = get_fast_modinfo($course);
                 }
                 if (empty($modinfo->cms[$cmid])) {
-                    global $PAGE;
-                    if (isset($PAGE) && strpos($PAGE->pagetype, 'course-view-')===0) {
+                    global $PAGE, $UNITTEST;
+                    if (!empty($UNITTEST) || (isset($PAGE) && strpos($PAGE->pagetype, 'course-view-')===0)) {
                         debugging("Warning: activity {$this->cm->id} '{$this->cm->name}' has condition on deleted activity $cmid (to get rid of this message, edit the named activity)");
                     }
                     continue;
index da837f9..61f16c3 100644 (file)
@@ -10,7 +10,7 @@ class conditionlib_test extends UnitTestCaseUsingDatabase {
 
     public $conditionlib_tables = array(
                'lib' => array(
-                   'context', 'capabilities', 'role',
+                   'files','context', 'capabilities', 'role',
                    'role_capabilities', 'role_assignments',
                    'course_categories', 'course',
                    'modules',
@@ -287,11 +287,18 @@ class conditionlib_test extends UnitTestCaseUsingDatabase {
         $oldcm->completion=COMPLETION_TRACKING_MANUAL;
         $DB->update_record('course_modules',$oldcm);
 
+        // Need to reset modinfo after changing the options
+        rebuild_course_cache($courseid);
+        $reset = 'reset';
+        get_fast_modinfo($reset);
+
         $ci=new condition_info((object)array('id'=>$cmid),CONDITION_MISSING_EVERYTHING);
         $ci->add_completion_condition($oldid,COMPLETION_COMPLETE);
+        condition_info::wipe_session_cache();
+
         $this->assertFalse($ci->is_available($text,false));
         $this->assertEqual(get_string('requires_completion_1','condition','xxx'),$text);
-
+        completion_info::wipe_session_cache();
         $completion=new completion_info($DB->get_record('course',array('id'=>$courseid)));
         $completion->update_state($oldcm,COMPLETION_COMPLETE);
         completion_info::wipe_session_cache();