public function test_filter_get_globally_enabled_filters_with_config() { $this->setup_available_in_context_tests(); // Set few filters. filter_set_global_state('one', TEXTFILTER_ON); filter_set_global_state('three', TEXTFILTER_OFF, -1); filter_set_global_state('two', TEXTFILTER_DISABLED); // Set global config. filter_set_local_config('one', $this->syscontext->id, 'test1a', 'In root'); filter_set_local_config('one', $this->syscontext->id, 'test1b', 'In root'); filter_set_local_config('two', $this->syscontext->id, 'test2a', 'In root'); filter_set_local_config('two', $this->syscontext->id, 'test2b', 'In root'); // Set child config. filter_set_local_config('one', $this->childcontext->id, 'test1a', 'In child'); filter_set_local_config('one', $this->childcontext->id, 'test1b', 'In child'); filter_set_local_config('two', $this->childcontext->id, 'test2a', 'In child'); filter_set_local_config('two', $this->childcontext->id, 'test2b', 'In child'); filter_set_local_config('three', $this->childcontext->id, 'test3a', 'In child'); filter_set_local_config('three', $this->childcontext->id, 'test3b', 'In child'); // Check. $actual = filter_get_globally_enabled_filters_with_config(); $this->assertCount(2, $actual); $this->assertEquals(['three', 'one'], array_keys($actual)); // Checks sortorder. $this->assertArrayHasKey('one', $actual); $this->assertArrayNotHasKey('two', $actual); $this->assertArrayHasKey('three', $actual); $this->assertEquals(['test1a' => 'In root', 'test1b' => 'In root'], $actual['one']); $this->assertEquals([], $actual['three']); }
/** * Setup the page for globally available filters. * * This helps setting up the page for filters which may be applied to * the page, even if they do not belong to the current context, or are * not yet visible because the content is lazily added (ajax). This method * always uses to the system context which determines the globally * available filters. * * This should only ever be called once per request. * * @param moodle_page $page The page. * @since Moodle 3.2 */ public function setup_page_for_globally_available_filters($page) { $context = context_system::instance(); $filterdata = filter_get_globally_enabled_filters_with_config(); foreach ($filterdata as $name => $config) { if (isset($this->textfilters[$context->id][$name])) { $filter = $this->textfilters[$context->id][$name]; } else { $filter = $this->make_filter_object($name, $context, $config); if (is_null($filter)) { continue; } } $filter->setup($page, $context); } }