[wp-trac] [WordPress Trac] #49988: Incorrect usage of `get_home_url` in PHPUnit tests

WordPress Trac noreply at wordpress.org
Thu Apr 23 18:11:35 UTC 2020


#49988: Incorrect usage of `get_home_url` in PHPUnit tests
--------------------------+-----------------------------
 Reporter:  david.binda   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The `Tests_oEmbed_Response_Data` class uses the `get_home_url` incorrectly
 on multiple places.

 The function is being called with `'/'` passed to it as first param.

 However, the first param should be a `$blog_id` (either `null` or `int`),
 and is used for a call to `switch_to_blog`.

 So, calling the `get_home_url( '/' )` attempts to switch to blog `'/'`
 which fails, and URL of the current blog is being returned, but the
 trailing slash is not being appended.

 Which leads to the second issue with those tests - they are actually
 passing without the trailing slash being added, which I guess is expected
 (at least accordingly to the code generating actual data:
 https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/embed.php?annotate=blame#L548 )

 Fix should be as easy as removing the param passed to `get_home_url`
 function call, as it's being done in attached patch.

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


More information about the wp-trac mailing list