wpGetHttpHeaders.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @group http
  4. * @covers ::wp_get_http_headers
  5. */
  6. class Tests_HTTP_wpGetHttpHeaders extends WP_UnitTestCase {
  7. /**
  8. * Set up the environment
  9. */
  10. public function setUp() {
  11. parent::setUp();
  12. // Hook a fake HTTP request response.
  13. add_filter( 'pre_http_request', array( $this, 'fake_http_request' ), 10, 3 );
  14. }
  15. /**
  16. * Test with a valid URL
  17. */
  18. public function test_wp_get_http_headers_valid_url() {
  19. $result = wp_get_http_headers( 'http://example.com' );
  20. $this->assertTrue( $result );
  21. }
  22. /**
  23. * Test with an invalid URL
  24. */
  25. public function test_wp_get_http_headers_invalid_url() {
  26. $result = wp_get_http_headers( 'not_an_url' );
  27. $this->assertFalse( $result );
  28. }
  29. /**
  30. * Test to see if the deprecated argument is working
  31. */
  32. public function test_wp_get_http_headers_deprecated_argument() {
  33. $this->setExpectedDeprecated( 'wp_get_http_headers' );
  34. wp_get_http_headers( 'does_not_matter', $deprecated = true );
  35. }
  36. /**
  37. * Mock the HTTP request response
  38. *
  39. * @param bool $false False.
  40. * @param array $arguments Request arguments.
  41. * @param string $url Request URL.
  42. *
  43. * @return array|bool
  44. */
  45. public function fake_http_request( $false, $arguments, $url ) {
  46. if ( 'http://example.com' === $url ) {
  47. return array( 'headers' => true );
  48. }
  49. return false;
  50. }
  51. }