From 4413ca209f3c501f71c534b1bec50edbf2d582ca Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Thu, 13 Aug 2020 12:23:33 +0200 Subject: [PATCH] MDL-69464 core_output: allow to avoid formatting in page->set_heading --- lib/pagelib.php | 5 +++-- lib/tests/moodle_page_test.php | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/pagelib.php b/lib/pagelib.php index 99366fc3872..8378da823d4 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1241,9 +1241,10 @@ class moodle_page { * This is normally used as the main heading at the top of the content. * * @param string $heading the main heading that should be displayed at the top of the . + * @param bool $applyformatting apply format_string() - by default true. */ - public function set_heading($heading) { - $this->_heading = format_string($heading); + public function set_heading($heading, bool $applyformatting = true) { + $this->_heading = $applyformatting ? format_string($heading) : clean_text($heading); } /** diff --git a/lib/tests/moodle_page_test.php b/lib/tests/moodle_page_test.php index a801a623c99..8fa2d661c52 100644 --- a/lib/tests/moodle_page_test.php +++ b/lib/tests/moodle_page_test.php @@ -311,6 +311,14 @@ class core_moodle_page_testcase extends advanced_testcase { $this->testpage->set_heading('a heading'); // Validated. $this->assertSame('a heading', $this->testpage->heading); + + // By default formatting is applied and tags are removed. + $this->testpage->set_heading('a heading edit

'); + $this->assertSame('a heading edit', $this->testpage->heading); + + // Without formatting the tags are preserved but cleaned. + $this->testpage->set_heading('a heading edit

', false); + $this->assertSame('a heading edit

', $this->testpage->heading); } public function test_set_title() {