diff --git a/lib/filterlib.php b/lib/filterlib.php index b8760c099f8..a01de832c01 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -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 diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 23a34d929fa..ba15273c028 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -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.