| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group formatting |
| | 5 | */ |
| | 6 | class Tests_Formatting_WpHtmlSplit extends WP_UnitTestCase { |
| | 7 | |
| | 8 | /** |
| | 9 | * Basic functionality goes here. |
| | 10 | * |
| | 11 | * @dataProvider data_basic_features |
| | 12 | */ |
| | 13 | function test_basic_features( $input, $output ) { |
| | 14 | return $this->assertEquals( $output, wp_html_split( $input ) ); |
| | 15 | } |
| | 16 | |
| | 17 | function data_basic_features() { |
| | 18 | return array( |
| | 19 | array( |
| | 20 | 'abcd efgh', |
| | 21 | array( 'abcd efgh' ), |
| | 22 | ), |
| | 23 | array( |
| | 24 | 'abcd <html> efgh', |
| | 25 | array( 'abcd ', '<html>', ' efgh' ), |
| | 26 | ), |
| | 27 | array( |
| | 28 | 'abcd <!-- <html> --> efgh', |
| | 29 | array( 'abcd ', '<!-- <html> -->', ' efgh' ), |
| | 30 | ), |
| | 31 | array( |
| | 32 | 'abcd <![CDATA[ <html> ]]> efgh', |
| | 33 | array( 'abcd ', '<![CDATA[ <html> ]]>', ' efgh' ), |
| | 34 | ), |
| | 35 | ); |
| | 36 | } |
| | 37 | |
| | 38 | /** |
| | 39 | * Automated performance testing of the main regex. |
| | 40 | * |
| | 41 | * @dataProvider data_whole_posts |
| | 42 | */ |
| | 43 | function test_pcre_performance( $input ) { |
| | 44 | $regex = get_html_split_regex(); |
| | 45 | $result = benchmark_pcre_backtracking( $regex, $input, 'split' ); |
| | 46 | return $this->assertLessThan( 200, $result ); |
| | 47 | } |
| | 48 | |
| | 49 | function data_whole_posts() { |
| | 50 | require_once( DIR_TESTDATA . '/formatting/whole-posts.php' ); |
| | 51 | return data_whole_posts(); |
| | 52 | } |
| | 53 | } |
| | 54 | No newline at end of file |