Ensure that a request URL is always set in `WP_UnitTestCase::go_to()`.

Failure to set this variable meant that passing the home URL to `go_to()`
(without a trailing slash) resulted in a PHP notice, and failed to reset the
globals properly.

Props joostdevalk.
Fixes #31417.

git-svn-id: https://develop.svn.wordpress.org/trunk@31515 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-02-23 01:07:18 +00:00
parent e61b0021bd
commit 129e5f5278
2 changed files with 11 additions and 1 deletions

View File

@ -333,7 +333,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
} }
$parts = parse_url($url); $parts = parse_url($url);
if (isset($parts['scheme'])) { if (isset($parts['scheme'])) {
$req = $parts['path']; $req = isset( $parts['path'] ) ? $parts['path'] : '';
if (isset($parts['query'])) { if (isset($parts['query'])) {
$req .= '?' . $parts['query']; $req .= '?' . $parts['query'];
// parse the url query vars into $_GET // parse the url query vars into $_GET

View File

@ -185,6 +185,16 @@ class Tests_TestHelpers extends WP_UnitTestCase {
$this->mock_incorrect_usage(); $this->mock_incorrect_usage();
} }
/**
* @ticket 31417
*/
public function test_go_to_should_go_to_home_page_when_passing_the_untrailingslashed_home_url() {
$this->assertFalse( is_home() );
$home = untrailingslashit( get_option( 'home' ) );
$this->go_to( $home );
$this->assertTrue( is_home() );
}
protected function mock_deprecated() { protected function mock_deprecated() {
_deprecated_function( __METHOD__, '2.5' ); _deprecated_function( __METHOD__, '2.5' );
} }