File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
tests/phpunit/tests/formatting Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -269,4 +269,36 @@ static function () {
269269 $ this ->assertStringNotContainsString ( '<p> ' , $ excerpt , 'Disallowed tag should be stripped. ' );
270270 $ this ->assertStringContainsString ( 'Hello ' , $ excerpt , 'Inner text of stripped tags should be kept. ' );
271271 }
272+
273+ /**
274+ * Tests that tags are balanced after truncation when allowed tags are set.
275+ *
276+ * @ticket 12084
277+ */
278+ public function test_excerpt_allowed_tags_balances_tags_after_truncation () {
279+ $ long_content = '<strong> ' . implode ( ' ' , range ( 1 , 60 ) ) . '</strong> ' ;
280+
281+ $ post = self ::factory ()->post ->create (
282+ array (
283+ 'post_content ' => $ long_content ,
284+ )
285+ );
286+
287+ add_filter (
288+ 'excerpt_allowed_tags ' ,
289+ static function () {
290+ return '<strong> ' ;
291+ }
292+ );
293+
294+ $ excerpt = wp_trim_excerpt ( '' , $ post );
295+
296+ remove_all_filters ( 'excerpt_allowed_tags ' );
297+
298+ $ this ->assertSame (
299+ substr_count ( $ excerpt , '<strong> ' ),
300+ substr_count ( $ excerpt , '</strong> ' ),
301+ 'Tags should be balanced after truncation. '
302+ );
303+ }
272304}
You can’t perform that action at this time.
0 commit comments