Skip to content

Commit 8272924

Browse files
Test: Verfiry allowed tags are balanced after excerpt truncation
1 parent e3bca6f commit 8272924

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/phpunit/tests/formatting/wpTrimExcerpt.php

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

0 commit comments

Comments
 (0)