| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Tests for wp_convert_hr_to_bytes(). |
| 5 | * |
| 6 | * @group load.php |
| 7 | */ |
| 8 | class Tests_Functions_Fix_Server_Vars extends WP_UnitTestCase { |
| 9 | |
| 10 | /** |
| 11 | * Tests that fallback when PHP_SELF is empty |
| 12 | * |
| 13 | * @ticket 34634 |
| 14 | * |
| 15 | * @dataProvider data_wp_fix_server_vars_php_self |
| 16 | * |
| 17 | * @param string $expected The expected PHP_SELF value. |
| 18 | * @param string $php_self_value The value for the server PHP_SELF value. |
| 19 | * @param string $request_uri_value The value for the server REQUEST_URI. |
| 20 | */ |
| 21 | public function test_wp_fix_server_vars_php_self( $expected, $php_self_value, $request_uri_value ) { |
| 22 | // Saves the current values. |
| 23 | $PHP_SELF = $_SERVER['PHP_SELF']; |
| 24 | $REQUEST_URI = $_SERVER['REQUEST_URI']; |
| 25 | |
| 26 | // Overrides the current values. |
| 27 | $_SERVER['PHP_SELF'] = $php_self_value; |
| 28 | $_SERVER['REQUEST_URI'] = $request_uri_value; |
| 29 | |
| 30 | wp_fix_server_vars(); |
| 31 | |
| 32 | $this->assertSame( $expected, $_SERVER['PHP_SELF'] ); |
| 33 | |
| 34 | // Put back the previous value. |
| 35 | $_SERVER['PHP_SELF'] = $PHP_SELF; |
| 36 | $_SERVER['REQUEST_URI'] = $REQUEST_URI; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Data provider for test_wp_fix_server_vars_php_self(). |
| 42 | * |
| 43 | * @return array { |
| 44 | * @type array { |
| 45 | * @type string $expected The expected output. |
| 46 | * @type string $value The php self value. |
| 47 | * @type string $value The request uri value. |
| 48 | * } |
| 49 | * } |
| 50 | */ |
| 51 | public function data_wp_fix_server_vars_php_self() { |
| 52 | return array( |
| 53 | array( '/index.php', '', '' ), |
| 54 | array( '/test.php', '', '/test.php' ), |
| 55 | ); |
| 56 | } |
| 57 | } |