Skip to content

Commit e3bca6f

Browse files
Test: Verfiry excerpt_allowed_tags filter to preserve specified HTML tags
1 parent dc44b89 commit e3bca6f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/phpunit/tests/formatting/wpTrimExcerpt.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)