WpHtmlSplit.php 1.1 KB

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