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
This commit is contained in:
Sergey Biryukov 2019-09-14 14:53:45 +00:00
parent 4f2fc80f65
commit 0b48fd2493
2 changed files with 43 additions and 1 deletions

View File

@ -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;

View File

@ -0,0 +1,42 @@
<?php
/**
* Tests get_status_header_desc function
*
* @since 5.3.0
*
* @group functions.php
*/
class Tests_Functions_get_status_header_desc extends WP_UnitTestCase {
/**
* @dataProvider _status_strings
*
* @param int $code HTTP status code.
* @param string $expected Status description.
*/
public function test_get_status_header_desc( $code, $expected ) {
$this->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', '' ),
);
}
}