-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
3.6.5, 3.7.1, 3.8
-
None
-
MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
While working on MDL-58680, writing some unit tests... I became crazy because the tests, using moodle filtering were returning completely unexpected results.
Tracing down the problem, the reason for those results is that, may filter have static caches (class or local). And they are never reset between unit tests.
Just looked and found quite a lot of those static caches.
$ ag ' static ' | ag -v function
|
censor/filter.php:56: static $words;
|
activitynames/filter.php:35: static $activitylist = null;
|
activitynames/filter.php:36: static $cachedcourseid;
|
activitynames/filter.php:37: static $cacheduserid;
|
geshi/geshi/geshi.php:2081: static $numbers_format = array(
|
geshi/geshi/geshi.php:4313: static $aTransSpecchar = array(
|
geshi/geshi/geshi.php:4734: static $callback_2;
|
geshi/geshinew/docs/CHANGES:170: * Added support for import static in Java5 (BenBE)
|
geshi/geshinew/contrib/langcheck.php:20: static $colors, $end;
|
geshi/geshinew/geshi.php:2081: static $numbers_format = array(
|
geshi/geshinew/geshi.php:4313: static $aTransSpecchar = array(
|
geshi/geshinew/geshi.php:4734: static $callback_2;
|
moodlelinks/filter.php:58: static $cachedcontextid;
|
moodlelinks/filter.php:59: static $linklist;
|
emoticon/tests/filter_test.php:163: // Reset static emoticon caches.
|
emoticon/filter.php:41: protected static $emoticontexts = array();
|
emoticon/filter.php:49: protected static $emoticonimgs = array();
|
mediaplugin/filter.php:54: static $jsinitialised = false;
|
urltolink/filter.php:37: protected static $globalconfig;
|
urltolink/filter.php:87: static $unicoderegexp;
|
data/filter.php:38: static $cachedcourseid = null;
|
data/filter.php:39: static $cacheduserid = null;
|
data/filter.php:40: static $coursecontentlist = array();
|
data/filter.php:41: static $sitecontentlist = array();
|
data/filter.php:43: static $nothingtodo;
|
multilang/filter.php:120: static $parentcache;
|
This issue is about to provide a way to reset all those caches under demand, for immediate use within phpunit reset but potentially in other places, if needed.
The proposal is to create a new method moodle_text_filter->reset_caches(), that will be in charge of cleaning ALL the caches for a given filter (MUC, class static, local static... ALL).
Then reset_text_filters_cache() (or alternatively filter_manager::reset_caches() ) will call to all those methods, guaranteeing that each unit test starts in a predictable, caching-free, status.
For sure it needs to be documented (new API method at all effects) and also this issue needs to be searched in codebase to remove any hack that was being used to workaround the problem.
Ciao