MDL-33774 Reset filters caches between unit tests
authorMarina Glancy <marina@moodle.com>
Thu, 14 Feb 2013 02:17:39 +0000 (13:17 +1100)
committerMarina Glancy <marina@moodle.com>
Thu, 14 Feb 2013 08:46:19 +0000 (19:46 +1100)
lib/filterlib.php
lib/phpunit/classes/util.php

index b8760c0..a01de83 100644 (file)
@@ -90,6 +90,25 @@ class filter_manager {
         return self::$singletoninstance;
     }
 
+    /**
+     * Resets the caches, usually to be called between unit tests
+     */
+    public static function reset_caches() {
+        if (self::$singletoninstance) {
+            self::$singletoninstance->unload_all_filters();
+        }
+        self::$singletoninstance = null;
+    }
+
+    /**
+     * Unloads all filters and other cached information
+     */
+    protected function unload_all_filters() {
+        $this->textfilters = array();
+        $this->stringfilters = array();
+        $this->stringfilternames = array();
+    }
+
     /**
      * Load all the filters required by this context.
      *
@@ -286,6 +305,16 @@ class performance_measuring_filter_manager extends filter_manager {
     protected $textsfiltered = 0;
     protected $stringsfiltered = 0;
 
+    /**
+     * Unloads all filters and other cached information
+     */
+    protected function unload_all_filters() {
+        parent::unload_all_filters();
+        $this->filterscreated = 0;
+        $this->textsfiltered = 0;
+        $this->stringsfiltered = 0;
+    }
+
     /**
      * @param string $filtername
      * @param object $context
index 23a34d9..ba15273 100644 (file)
@@ -171,6 +171,7 @@ class phpunit_util extends testing_util {
         if (class_exists('repository')) {
             repository::reset_caches();
         }
+        filter_manager::reset_caches();
         //TODO MDL-25290: add more resets here and probably refactor them to new core function
 
         // Reset course and module caches.