diff --git a/tests/phpunit/tests/http/getHttpHeaders.php b/tests/phpunit/tests/http/getHttpHeaders.php new file mode 100644 index 0000000000..ccb6b4f545 --- /dev/null +++ b/tests/phpunit/tests/http/getHttpHeaders.php @@ -0,0 +1,69 @@ +assertTrue( $result ); + } + + /** + * Test with an invalid URL + */ + public function test_wp_get_http_headers_invalid_url() { + $result = wp_get_http_headers( 'not_an_url' ); + $this->assertFalse( $result ); + } + + /** + * Test to see if the deprecated argument is working + */ + public function test_wp_get_http_headers_deprecated_argument() { + $this->setExpectedDeprecated( 'wp_get_http_headers' ); + + wp_get_http_headers( 'does_not_matter', $deprecated = true ); + } + + /** + * Mock the HTTP request response + * + * @param bool $false False. + * @param array $arguments Request arguments. + * @param string $url Request URL. + * + * @return array|bool + */ + public function fake_http_request( $false, $arguments, $url ) { + if ( 'http://example.com' === $url ) { + return array( 'headers' => true ); + } + + return false; + } +} diff --git a/tests/phpunit/tests/http/remoteRetrieveHeaders.php b/tests/phpunit/tests/http/remoteRetrieveHeaders.php new file mode 100644 index 0000000000..f7785803c4 --- /dev/null +++ b/tests/phpunit/tests/http/remoteRetrieveHeaders.php @@ -0,0 +1,38 @@ + $headers ); + + $result = wp_remote_retrieve_headers( $response ); + $this->assertEquals( $headers, $result ); + } + + /** + * Response is a WP_Error + */ + function test_remote_retrieve_headers_is_error() { + $response = new WP_Error( 'Some error' ); + + $result = wp_remote_retrieve_headers( $response ); + $this->assertEquals( array(), $result ); + } + + /** + * Response does not contain 'headers' + */ + function test_remote_retrieve_headers_invalid_response() { + $response = array( 'no_headers' => 'set'); + + $result = wp_remote_retrieve_headers( $response ); + $this->assertEquals( array(), $result ); + } +}