Skip to content

Commit 5bc5398

Browse files
committed
REST API: Use valid host in unit tests for URL Details endpoint.
This ensures that the `url` parameter is not marked as invalid due to `wp_http_validate_url()` failing because of a `gethostbyname()` failure. Follow-up to [51973]. Reviewed by peterwilsoncc. Merges [61377] to the 6.9 branch. Props westonruter, swissspidy. See #54358. Fixes #64412. git-svn-id: https://develop.svn.wordpress.org/branches/6.9@61378 602fd350-edb4-49c9-b593-d223f7449a82
1 parent abbf49a commit 5bc5398

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ class Tests_REST_WpRestUrlDetailsController extends WP_Test_REST_Controller_Test
4343
/**
4444
* URL placeholder.
4545
*
46+
* Even though the request is being intercepted with a mocked response, it is not fully bypassing the network. The
47+
* REST API endpoint is validating the `url` parameter with `wp_http_validate_url()` which includes a call to
48+
* `gethostbyname()`. So the domain used in the placeholder URL must be valid to ensure it passes a validity check.
49+
*
4650
* @since 5.9.0
4751
*
4852
* @var string
4953
*/
50-
const URL_PLACEHOLDER = 'https://placeholder-site.com';
54+
const URL_PLACEHOLDER = 'https://example.com';
5155

5256
/**
5357
* Array of request args.
@@ -129,9 +133,9 @@ public function test_get_items() {
129133
$this->assertSame(
130134
array(
131135
'title' => 'Example Website — - with encoded content.',
132-
'icon' => 'https://placeholder-site.com/favicon.ico?querystringaddedfortesting',
136+
'icon' => 'https://example.com/favicon.ico?querystringaddedfortesting',
133137
'description' => 'Example description text here. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.',
134-
'image' => 'https://placeholder-site.com/images/home/screen-themes.png?3',
138+
'image' => 'https://example.com/images/home/screen-themes.png?3',
135139
),
136140
$data
137141
);
@@ -444,7 +448,7 @@ static function ( $response, $url ) {
444448

445449
$this->assertSame( 418, $data['status'], 'Response "status" is not 418' );
446450

447-
$expected = 'Response for URL https://placeholder-site.com altered via rest_prepare_url_details filter';
451+
$expected = 'Response for URL https://example.com altered via rest_prepare_url_details filter';
448452
$this->assertSame( $expected, $data['response'], 'Response "response" is not "' . $expected . '"' );
449453
}
450454

0 commit comments

Comments
 (0)