Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-33774 Reset filters caches between unit tests

  • Loading branch information...
commit 73a0f3ba76ba2338494e06bb486e67dc43f0592f 1 parent 173115e
Marina Glancy marinaglancy authored

Showing 2 changed files with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. +29 0 lib/filterlib.php
  2. +1 0  lib/phpunit/classes/util.php
29 lib/filterlib.php
@@ -91,6 +91,25 @@ public static function instance() {
91 91 }
92 92
93 93 /**
  94 + * Resets the caches, usually to be called between unit tests
  95 + */
  96 + public static function reset_caches() {
  97 + if (self::$singletoninstance) {
  98 + self::$singletoninstance->unload_all_filters();
  99 + }
  100 + self::$singletoninstance = null;
  101 + }
  102 +
  103 + /**
  104 + * Unloads all filters and other cached information
  105 + */
  106 + protected function unload_all_filters() {
  107 + $this->textfilters = array();
  108 + $this->stringfilters = array();
  109 + $this->stringfilternames = array();
  110 + }
  111 +
  112 + /**
94 113 * Load all the filters required by this context.
95 114 *
96 115 * @param object $context
@@ -287,6 +306,16 @@ class performance_measuring_filter_manager extends filter_manager {
287 306 protected $stringsfiltered = 0;
288 307
289 308 /**
  309 + * Unloads all filters and other cached information
  310 + */
  311 + protected function unload_all_filters() {
  312 + parent::unload_all_filters();
  313 + $this->filterscreated = 0;
  314 + $this->textsfiltered = 0;
  315 + $this->stringsfiltered = 0;
  316 + }
  317 +
  318 + /**
290 319 * @param string $filtername
291 320 * @param object $context
292 321 * @param mixed $localconfig
1  lib/phpunit/classes/util.php
@@ -171,6 +171,7 @@ public static function reset_all_data($logchanges = false) {
171 171 if (class_exists('repository')) {
172 172 repository::reset_caches();
173 173 }
  174 + filter_manager::reset_caches();
174 175 //TODO MDL-25290: add more resets here and probably refactor them to new core function
175 176
176 177 // Reset course and module caches.

0 comments on commit 73a0f3b

Please sign in to comment.
Something went wrong with that request. Please try again.