From 6770af57af07a7d82a4cace8c84b58f62e0329d0 Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Sun, 1 Nov 2026 16:35:29 +0600 Subject: [PATCH] Tests: Cover format_to_edit(). See #65819. Props devmuhib009. --- .../phpunit/tests/formatting/formatToEdit.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/phpunit/tests/formatting/formatToEdit.php diff --git a/tests/phpunit/tests/formatting/formatToEdit.php b/tests/phpunit/tests/formatting/formatToEdit.php new file mode 100644 index 0000000000000..4cb55c8ae8768 --- /dev/null +++ b/tests/phpunit/tests/formatting/formatToEdit.php @@ -0,0 +1,53 @@ +"hello" & \'world\''; + $expected = '<b>"hello" & 'world'</b>'; + + $this->assertSame( $expected, format_to_edit( $content ) ); + $this->assertSame( $expected, format_to_edit( $content, false ) ); + } + + /** + * Tests that format_to_edit() does not escape text when $rich_text is true. + * + * @ticket 65819 + */ + public function test_format_to_edit_does_not_escape_when_rich_text_is_true() { + $content = '"hello" & \'world\''; + + $this->assertSame( $content, format_to_edit( $content, true ) ); + } + + /** + * Tests that format_to_edit filter modifies content before escaping. + * + * @ticket 65819 + */ + public function test_format_to_edit_filter() { + add_filter( + 'format_to_edit', + static function ( $text ) { + return $text . ' & extra'; + } + ); + + $expected = 'original & <span>extra</span>'; + + $this->assertSame( $expected, format_to_edit( 'original' ) ); + } +}