From 0b48fd24931ec854b711a790466389b1615d70c4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 14 Sep 2019 14:53:45 +0000 Subject: [PATCH] HTTP API: Add a unit test for `get_status_header_desc()`. Props pbearne. Fixes #46631. git-svn-id: https://develop.svn.wordpress.org/trunk@46107 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 2 +- .../tests/functions/getStatusHeaderDesc.php | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/tests/functions/getStatusHeaderDesc.php 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', '' ), + ); + } +}