diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index a58144f843..c135d0d93e 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -1250,7 +1250,7 @@ function wp( $query_vars = '' ) { * @global array $wp_header_to_desc * * @param int $code HTTP status code. - * @return string Empty string if not found, or description if found. + * @return string Status description if found, an empty string otherwise. */ function get_status_header_desc( $code ) { global $wp_header_to_desc; diff --git a/tests/phpunit/tests/functions/getStatusHeaderDesc.php b/tests/phpunit/tests/functions/getStatusHeaderDesc.php new file mode 100644 index 0000000000..09634afc70 --- /dev/null +++ b/tests/phpunit/tests/functions/getStatusHeaderDesc.php @@ -0,0 +1,42 @@ +assertSame( get_status_header_desc( $code ), $expected ); + } + + /** + * Data provider for test_get_status_header_desc(). + * + * @return array + */ + public function _status_strings() { + return array( + array( 200, 'OK' ), + array( 301, 'Moved Permanently' ), + array( 404, 'Not Found' ), + array( 500, 'Internal Server Error' ), + + // A string to make sure that the absint() is working. + array( "200", 'OK' ), + + // Not recognized codes return empty strings. + array( 9999, '' ), + array( 'random', '' ), + ); + } +}