From 129e5f5278c0c79eb5b225675969a3f09e344332 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 23 Feb 2015 01:07:18 +0000 Subject: [PATCH] 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 --- tests/phpunit/includes/testcase.php | 2 +- tests/phpunit/tests/includes/helpers.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index dc888740f6..81f9686050 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -333,7 +333,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } $parts = parse_url($url); if (isset($parts['scheme'])) { - $req = $parts['path']; + $req = isset( $parts['path'] ) ? $parts['path'] : ''; if (isset($parts['query'])) { $req .= '?' . $parts['query']; // parse the url query vars into $_GET diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php index 025b9384f6..b717fdcb1a 100755 --- a/tests/phpunit/tests/includes/helpers.php +++ b/tests/phpunit/tests/includes/helpers.php @@ -185,6 +185,16 @@ class Tests_TestHelpers extends WP_UnitTestCase { $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() { _deprecated_function( __METHOD__, '2.5' ); }