Permalink
Browse files

MDL-33774 Reset filters caches between unit tests

  • Loading branch information...
1 parent 173115e commit 73a0f3ba76ba2338494e06bb486e67dc43f0592f @marinaglancy marinaglancy committed Feb 14, 2013
Showing with 30 additions and 0 deletions.
  1. +29 −0 lib/filterlib.php
  2. +1 −0 lib/phpunit/classes/util.php
View
29 lib/filterlib.php
@@ -91,6 +91,25 @@ public static function instance() {
}
/**
+ * 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.
*
* @param object $context
@@ -287,6 +306,16 @@ class performance_measuring_filter_manager extends filter_manager {
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
* @param mixed $localconfig
View
1 lib/phpunit/classes/util.php
@@ -171,6 +171,7 @@ public static function reset_all_data($logchanges = false) {
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.

0 comments on commit 73a0f3b

Please sign in to comment.