[wp-trac] [WordPress Trac] #64412: Sporadic unit test failure in Tests_REST_WpRestUrlDetailsController::test_get_items

WordPress Trac noreply at wordpress.org
Sun Dec 14 07:50:06 UTC 2025


#64412: Sporadic unit test failure in
Tests_REST_WpRestUrlDetailsController::test_get_items
--------------------------+-------------------------
 Reporter:  westonruter   |      Owner:  westonruter
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  6.9.1
Component:  Editor        |    Version:  5.9
 Severity:  normal        |   Keywords:
  Focuses:  rest-api      |
--------------------------+-------------------------
 In #54358 via [51973] tests for the URL Details endpoint were introduced.
 These used a `https://placeholder-site.com` URL as the test URL for the
 unit tests in `Tests_REST_WpRestUrlDetailsController`. Recently, one of
 these tests has been failing sporadically:

 {{{
 1) Tests_REST_WpRestUrlDetailsController::test_get_items
 Failed asserting that two arrays are identical.
 --- Expected
 +++ Actual
 @@ @@
  Array &0 (
 -    'title' => 'Example Website — - with encoded content.'
 -    'icon' => 'https://placeholder-
 site.com/favicon.ico?querystringaddedfortesting'
 -    'description' => 'Example description text here. Lorem ipsum dolor
 sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
 labore et dolore.'
 -    'image' => 'https://placeholder-site.com/images/home/screen-
 themes.png?3'
 +    'code' => 'rest_invalid_param'
 +    'message' => 'Invalid parameter(s): url'
 +    'data' => Array &1 (
 +        'status' => 400
 +        'params' => Array &2 (
 +            'url' => 'Invalid parameter.'
 +        )
 +        'details' => Array &3 ()
 +    )
  )

 /var/www/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php:131
 }}}

 Even though the HTTP request is intercepted with a mocked response via the
 `pre_http_request` filter, it appears this mocking is not complete. In
 particular, the `wp-block-editor/v1/url-details` endpoint includes a `url`
 param which has `wp_http_validate_url()` as its `validate_callback`. This
 validation function ends up calling `gethostbyname()`. Since `https
 ://placeholder-site.com` is not an actual site, it appears that this
 `gethostbyname()` often returns with a failure. I can reproduce the unit
 test failure by patching `wp_http_validate_url()` as follows:

 {{{#!diff
 --- a/src/wp-includes/http.php
 +++ b/src/wp-includes/http.php
 @@ -593,7 +593,7 @@ function wp_http_validate_url( $url ) {
                         $ip = $host;
                 } else {
                         $ip = gethostbyname( $host );
 -                       if ( $ip === $host ) { // Error condition for
 gethostbyname().
 +                       if ( true || $ip === $host ) { // Error condition
 for gethostbyname().
                                 return false;
                         }
                 }
 }}}

 I think we should simply use the domain for a real site, like
 `https://example.com`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64412>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list