diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index e95323a2e0..5f1d6c4b25 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -433,15 +433,16 @@ function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) { continue; case PREG_RECURSION_LIMIT_ERROR: trigger_error('PCRE recursion limit encountered before backtrack limit.'); - break; + return; case PREG_BAD_UTF8_ERROR: trigger_error('UTF-8 error during PCRE benchmark.'); - break; + return; case PREG_INTERNAL_ERROR: trigger_error('Internal error during PCRE benchmark.'); - break; + return; default: - trigger_error('Unexpected error during PCRE benchmark.'); + trigger_error('Unexpected error during PCRE benchmark.'); + return; } } diff --git a/tests/phpunit/tests/formatting/WpHtmlSplit.php b/tests/phpunit/tests/formatting/WpHtmlSplit.php new file mode 100644 index 0000000000..363177f723 --- /dev/null +++ b/tests/phpunit/tests/formatting/WpHtmlSplit.php @@ -0,0 +1,53 @@ +assertEquals( $output, wp_html_split( $input ) ); + } + + function data_basic_features() { + return array( + array( + 'abcd efgh', + array( 'abcd efgh' ), + ), + array( + 'abcd efgh', + array( 'abcd ', '', ' efgh' ), + ), + array( + 'abcd efgh', + array( 'abcd ', '', ' efgh' ), + ), + array( + 'abcd ]]> efgh', + array( 'abcd ', ' ]]>', ' efgh' ), + ), + ); + } + + /** + * Automated performance testing of the main regex. + * + * @dataProvider data_whole_posts + */ + function test_pcre_performance( $input ) { + $regex = get_html_split_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(); + } +}