MDL-42664 Fix the filter_manager instantiation
authorDavid Mudrák <david@moodle.com>
Fri, 1 Nov 2013 06:36:24 +0000 (07:36 +0100)
committerDavid Mudrák <david@moodle.com>
Fri, 1 Nov 2013 08:18:10 +0000 (09:18 +0100)
For legacy reasons, the $CFG->perfdebug uses values 7 for disabled and 15 for
enabled. Because of this typo, Moodle has always created instance of the slower
performance_measuring_filter_manager instead of the standard filter_manager,
regardless the perfdebug setting.

lib/filterlib.php
lib/tests/filterlib_test.php

index 5f848ec..0f6072c 100644 (file)
@@ -81,7 +81,7 @@ class filter_manager {
     public static function instance() {
         global $CFG;
         if (is_null(self::$singletoninstance)) {
-            if (!empty($CFG->perfdebug)) {
+            if (!empty($CFG->perfdebug) and $CFG->perfdebug > 7) {
                 self::$singletoninstance = new performance_measuring_filter_manager();
             } else {
                 self::$singletoninstance = new self();
index 2db0568..e769e08 100644 (file)
@@ -660,4 +660,19 @@ class core_filterlib_testcase extends advanced_testcase {
         $this->assertEquals('emailprotect,multilang', $CFG->stringfilters);
         $this->assertEquals(1, $CFG->filterall);
     }
+
+    public function test_filter_manager_instance() {
+
+        set_config('perfdebug', 7);
+        filter_manager::reset_caches();
+        $filterman = filter_manager::instance();
+        $this->assertInstanceOf('filter_manager', $filterman);
+        $this->assertNotInstanceOf('performance_measuring_filter_manager', $filterman);
+
+        set_config('perfdebug', 15);
+        filter_manager::reset_caches();
+        $filterman = filter_manager::instance();
+        $this->assertInstanceOf('filter_manager', $filterman);
+        $this->assertInstanceOf('performance_measuring_filter_manager', $filterman);
+    }
 }