mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 23:58:03 +00:00
Shortcodes/Formatting: Add PCRE Performance Testing
* Move pattern from `wptexturize()` into a separate function. * Move pattern from `wp_html_split()` into a separate function. * Beautify code for `wp_html_split()`. * Remove unnecessary instances of `/s` modifier in patterns that don't use dots. * Add `tests/phpunit/data/formatting/whole-posts.php` for testing larger strings. * Add function `benchmark_pcre_backtracking()`. * Add tests for `wp_html_split()`. * Add tests for `wptexturize()`. * Add tests for `get_shortcode_regex()`. Props miqrogroove. Fixes #34121. git-svn-id: https://develop.svn.wordpress.org/trunk@34761 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2048,4 +2048,29 @@ String with a number followed by a single quote !q1!Expendables 3!q1! vestibulum
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automated performance testing of the main regex.
|
||||
*
|
||||
* @dataProvider data_whole_posts
|
||||
*/
|
||||
function test_pcre_performance( $input ) {
|
||||
global $shortcode_tags;
|
||||
|
||||
// With Shortcodes Disabled
|
||||
$regex = _get_wptexturize_split_regex( );
|
||||
$result = benchmark_pcre_backtracking( $regex, $input, 'split' );
|
||||
$this->assertLessThan( 200, $result );
|
||||
|
||||
// With Shortcodes Enabled
|
||||
$shortcode_regex = _get_wptexturize_shortcode_regex( array_keys( $shortcode_tags ) );
|
||||
$regex = _get_wptexturize_split_regex( $shortcode_regex );
|
||||
$result = benchmark_pcre_backtracking( $regex, $input, 'split' );
|
||||
return $this->assertLessThan( 200, $result );
|
||||
}
|
||||
|
||||
function data_whole_posts() {
|
||||
require_once( DIR_TESTDATA . '/formatting/whole-posts.php' );
|
||||
return data_whole_posts();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user