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' ) );
+ }
+}