Skip to content

Commit 5fd32be

Browse files
committed
Tests: Cover wp_get_server_protocol().
Verify recognized HTTP protocol values and the fallback for unknown, empty, or missing `SERVER_PROTOCOL` values. Developed in: #14417 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64512 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 38f5cdf commit 5fd32be

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* Tests for wp_get_server_protocol().
5+
*
6+
* @group load
7+
*
8+
* @covers ::wp_get_server_protocol
9+
*/
10+
class Tests_Load_WpGetServerProtocol extends WP_UnitTestCase {
11+
12+
/**
13+
* Original SERVER_PROTOCOL value.
14+
*
15+
* @var string|null
16+
*/
17+
private $original_server_protocol;
18+
19+
public function set_up() {
20+
parent::set_up();
21+
22+
$this->original_server_protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : null;
23+
}
24+
25+
public function tear_down() {
26+
if ( null === $this->original_server_protocol ) {
27+
unset( $_SERVER['SERVER_PROTOCOL'] );
28+
} else {
29+
$_SERVER['SERVER_PROTOCOL'] = $this->original_server_protocol;
30+
}
31+
32+
parent::tear_down();
33+
}
34+
35+
/**
36+
* Tests recognized HTTP protocol versions and the fallback for unknown values.
37+
*
38+
* @ticket 65819
39+
*
40+
* @dataProvider data_wp_get_server_protocol
41+
*
42+
* @param string|null $server_protocol Value for $_SERVER['SERVER_PROTOCOL'], or null to unset.
43+
* @param string $expected Expected return value.
44+
*/
45+
public function test_wp_get_server_protocol( $server_protocol, $expected ) {
46+
if ( null === $server_protocol ) {
47+
unset( $_SERVER['SERVER_PROTOCOL'] );
48+
} else {
49+
$_SERVER['SERVER_PROTOCOL'] = $server_protocol;
50+
}
51+
52+
$this->assertSame( $expected, wp_get_server_protocol() );
53+
}
54+
55+
/**
56+
* Data provider for test_wp_get_server_protocol().
57+
*
58+
* @return array[]
59+
*/
60+
public static function data_wp_get_server_protocol() {
61+
return array(
62+
'HTTP/1.1' => array( 'HTTP/1.1', 'HTTP/1.1' ),
63+
'HTTP/2' => array( 'HTTP/2', 'HTTP/2' ),
64+
'HTTP/2.0' => array( 'HTTP/2.0', 'HTTP/2.0' ),
65+
'HTTP/3' => array( 'HTTP/3', 'HTTP/3' ),
66+
'HTTP/1.0' => array( 'HTTP/1.0', 'HTTP/1.0' ),
67+
'unknown value' => array( 'HTTP/0.9', 'HTTP/1.0' ),
68+
'empty string' => array( '', 'HTTP/1.0' ),
69+
'missing header' => array( null, 'HTTP/1.0' ),
70+
);
71+
}
72+
}

0 commit comments

Comments
 (0)