MDL-33774 Reset filters caches between unit tests

This commit is contained in:
Marina Glancy 2013-02-14 13:17:39 +11:00
parent 173115e14c
commit 73a0f3ba76
2 changed files with 30 additions and 0 deletions

View 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

View 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.