| 267 | |
| 268 | /** |
| 269 | * @ticket 36356 |
| 270 | * |
| 271 | * @dataProvider get_component_from_parsed_url_array_testcases |
| 272 | */ |
| 273 | function test_get_component_from_parsed_url_array( $url, $component, $expected ) { |
| 274 | $parts = wp_parse_url( $url ); |
| 275 | $actual = _get_component_from_parsed_url_array( $parts, $component ); |
| 276 | $this->assertSame( $expected, $actual ); |
| 277 | } |
| 278 | |
| 279 | function get_component_from_parsed_url_array_testcases() { |
| 280 | // 0: A URL, 1: PHP URL constant, 2: The expected result. |
| 281 | return array( |
| 282 | array( 'http://example.com/', -1, array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/' ) ), |
| 283 | array( 'http://example.com/', -1, array( 'scheme' => 'http', 'host' => 'example.com', 'path' => '/' ) ), |
| 284 | array( 'http://example.com/', PHP_URL_HOST, 'example.com' ), |
| 285 | array( 'http://example.com/', PHP_URL_USER, null ), |
| 286 | array( 'http:///example.com', -1, false ), |
| 287 | array( 'http:///example.com', PHP_URL_HOST, null ), |
| 288 | ); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * @ticket 36356 |
| 293 | * |
| 294 | * @dataProvider wp_translate_php_url_constant_to_key_testcases |
| 295 | */ |
| 296 | function test_wp_translate_php_url_constant_to_key( $input, $expected ) { |
| 297 | $actual = _wp_translate_php_url_constant_to_key( $input ); |
| 298 | $this->assertSame( $expected, $actual ); |
| 299 | } |
| 300 | |
| 301 | function wp_translate_php_url_constant_to_key_testcases() { |
| 302 | // 0: PHP URL constant, 1: The expected result. |
| 303 | return array( |
| 304 | array( PHP_URL_SCHEME, 'scheme' ), |
| 305 | array( PHP_URL_HOST, 'host' ), |
| 306 | array( PHP_URL_PORT, 'port' ), |
| 307 | array( PHP_URL_USER, 'user' ), |
| 308 | array( PHP_URL_PASS, 'pass' ), |
| 309 | array( PHP_URL_PATH, 'path' ), |
| 310 | array( PHP_URL_QUERY, 'query' ), |
| 311 | array( PHP_URL_FRAGMENT, 'fragment' ), |
| 312 | |
| 313 | // Test with non-PHP_URL_CONSTANT parameter. |
| 314 | array( 'something', false ), |
| 315 | array( ABSPATH, false ), |
| 316 | ); |
| 317 | } |
| 318 | |