File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
tests/phpunit/tests/formatting Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -240,4 +240,33 @@ public function test_excerpt_allowed_tags_default_strips_all_html() {
240240
241241 $ this ->assertStringNotContainsString ( '< ' , $ excerpt , 'Default excerpt should contain no HTML tags. ' );
242242 }
243+
244+ /**
245+ * Tests that the excerpt_allowed_tags filter preserves specified tags
246+ * and strips disallowed ones while keeping their inner text.
247+ *
248+ * @ticket 12084
249+ */
250+ public function test_excerpt_allowed_tags_preserves_specified_tags () {
251+ $ post = self ::factory ()->post ->create (
252+ array (
253+ 'post_content ' => '<p>Hello <strong>bold</strong> and <em>italic</em> text.</p> ' ,
254+ )
255+ );
256+
257+ add_filter (
258+ 'excerpt_allowed_tags ' ,
259+ static function () {
260+ return '<strong><em> ' ;
261+ }
262+ );
263+
264+ $ excerpt = wp_trim_excerpt ( '' , $ post );
265+
266+ remove_all_filters ( 'excerpt_allowed_tags ' );
267+
268+ $ this ->assertStringContainsString ( '<strong>bold</strong> ' , $ excerpt , 'Allowed tag should be preserved. ' );
269+ $ this ->assertStringNotContainsString ( '<p> ' , $ excerpt , 'Disallowed tag should be stripped. ' );
270+ $ this ->assertStringContainsString ( 'Hello ' , $ excerpt , 'Inner text of stripped tags should be kept. ' );
271+ }
243272}
You can’t perform that action at this time.
0 commit comments