GetUrlInContent.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_GetUrlInContent extends WP_UnitTestCase {
  6. /**
  7. * URL Content Data Provider
  8. *
  9. * array ( input_txt, converted_output_txt )
  10. */
  11. public function get_input_output() {
  12. return array(
  13. array( // Empty content.
  14. '',
  15. false,
  16. ),
  17. array( // No URLs.
  18. '<div>NO URL CONTENT</div>',
  19. false,
  20. ),
  21. array( // Ignore none link elements.
  22. '<div href="/relative.php">NO URL CONTENT</div>',
  23. false,
  24. ),
  25. array( // Single link.
  26. 'ABC<div><a href="/relative.php">LINK</a> CONTENT</div>',
  27. '/relative.php',
  28. ),
  29. array( // Multiple links.
  30. 'ABC<div><a href="/relative.php">LINK</a> CONTENT <a href="/suppress.php">LINK</a></div>',
  31. '/relative.php',
  32. ),
  33. array( // Escape link.
  34. 'ABC<div><a href="http://example.com/Mr%20WordPress 2">LINK</a> CONTENT </div>',
  35. 'http://example.com/Mr%20WordPress%202',
  36. ),
  37. );
  38. }
  39. /**
  40. * Validate the get_url_in_content function
  41. *
  42. * @dataProvider get_input_output
  43. */
  44. function test_get_url_in_content( $in_str, $exp_str ) {
  45. $this->assertSame( $exp_str, get_url_in_content( $in_str ) );
  46. }
  47. }