WPMakeLinkRelative.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_WPMakeLinkRelative extends WP_UnitTestCase {
  6. public function test_wp_make_link_relative_with_http_scheme() {
  7. $link = 'http://example.com/this-is-a-test-http-url/';
  8. $relative_link = wp_make_link_relative( $link );
  9. $this->assertSame( '/this-is-a-test-http-url/', $relative_link );
  10. }
  11. public function test_wp_make_link_relative_with_https_scheme() {
  12. $link = 'https://example.com/this-is-a-test-https-url/';
  13. $relative_link = wp_make_link_relative( $link );
  14. $this->assertSame( '/this-is-a-test-https-url/', $relative_link );
  15. }
  16. /**
  17. * @ticket 30373
  18. */
  19. public function test_wp_make_link_relative_with_no_scheme() {
  20. $link = '//example.com/this-is-a-test-schemeless-url/';
  21. $relative_link = wp_make_link_relative( $link );
  22. $this->assertSame( '/this-is-a-test-schemeless-url/', $relative_link );
  23. }
  24. /**
  25. * @ticket 30373
  26. */
  27. public function test_wp_make_link_relative_should_retain_URL_param_that_is_also_a_URL() {
  28. $link = 'https://example.com/this-is-a-test/?redirect=https://example.org/a-different-test-post/';
  29. $relative_link = wp_make_link_relative( $link );
  30. $this->assertSame( '/this-is-a-test/?redirect=https://example.org/a-different-test-post/', $relative_link );
  31. }
  32. /**
  33. * @ticket 26819
  34. */
  35. function test_wp_make_link_relative_with_no_path() {
  36. $link = 'http://example.com';
  37. $relative_link = wp_make_link_relative( $link );
  38. $this->assertSame( '', $relative_link );
  39. }
  40. }