MDL-69464 core_output: allow to avoid formatting in page->set_heading

This commit is contained in:
Marina Glancy
2020-08-25 13:22:36 +08:00
committed by Andrew Nicols
parent 427f046cff
commit 4413ca209f
2 changed files with 11 additions and 2 deletions
+3 -2
View File
@@ -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 <body>.
* @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);
}
/**
+8
View File
@@ -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 <a href="#">edit</a><p>');
$this->assertSame('a heading edit', $this->testpage->heading);
// Without formatting the tags are preserved but cleaned.
$this->testpage->set_heading('a heading <a href="#">edit</a><p>', false);
$this->assertSame('a heading <a href="#">edit</a><p></p>', $this->testpage->heading);
}
public function test_set_title() {