Skip to content

Commit cb7c390

Browse files
Tests: Cover format_for_editor().
Verify that HTML entities are encoded but quotes are preserved, and the `format_for_editor` filter receives arguments and modifies the returned text. Developed in #15361. Props devmuhib, huzaifaalmesbah, lancewillett. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65734 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2b8adf7 commit cb7c390

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* Tests for the `format_for_editor()` function.
5+
*
6+
* @group formatting
7+
*
8+
* @covers ::format_for_editor
9+
*/
10+
class Tests_Formatting_FormatForEditor extends WP_UnitTestCase {
11+
12+
/**
13+
* Tests that format_for_editor() encodes HTML entities but preserves quotes.
14+
*
15+
* @ticket 65819
16+
*/
17+
public function test_format_for_editor_encodes_entities_without_quotes() {
18+
$input = '<p>"Hello" & \'World\'</p>';
19+
$expected = '&lt;p&gt;"Hello" &amp; \'World\'&lt;/p&gt;';
20+
21+
$this->assertSame( $expected, format_for_editor( $input ) );
22+
}
23+
24+
/**
25+
* Tests that the `format_for_editor` filter receives arguments and modifies the returned text.
26+
*
27+
* @ticket 65819
28+
*/
29+
public function test_format_for_editor_filter() {
30+
$filter = new MockAction();
31+
add_filter( 'format_for_editor', array( $filter, 'filter_append' ), 10, 2 );
32+
33+
$actual = format_for_editor( 'Hello World', 'tinymce' );
34+
35+
$this->assertSame( 1, $filter->get_call_count() );
36+
$this->assertSame( array( 'Hello World', 'tinymce' ), $filter->get_args()[0] );
37+
$this->assertSame( 'Hello World_append', $actual );
38+
}
39+
}

0 commit comments

Comments
 (0)