From b28dcfd83243459e9cc08f46f70418ebfde9dde8 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 2 Mar 2022 15:38:27 +0000 Subject: [PATCH] Docs: Add a `@since` note for `WP::parse_request()` about the new return value. Includes minor code layout fixes for consistency. Additionally, this moves a more general unit test above the more specific one. Follow-up to [52814]. See #10886. git-svn-id: https://develop.svn.wordpress.org/trunk@52815 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp.php | 5 ++++ tests/phpunit/tests/wp/parseRequest.php | 33 ++++++++++++------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/wp-includes/class-wp.php b/src/wp-includes/class-wp.php index 35ebb06371..23af2fff87 100644 --- a/src/wp-includes/class-wp.php +++ b/src/wp-includes/class-wp.php @@ -125,6 +125,7 @@ class WP { * filters and actions that can be used to further manipulate the result. * * @since 2.0.0 + * @since 6.0.0 A return value was added. * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * @@ -758,13 +759,17 @@ class WP { */ public function main( $query_args = '' ) { $this->init(); + $parsed = $this->parse_request( $query_args ); + $this->send_headers(); + if ( $parsed ) { $this->query_posts(); $this->handle_404(); $this->register_globals(); } + /** * Fires once the WordPress environment has been set up. * diff --git a/tests/phpunit/tests/wp/parseRequest.php b/tests/phpunit/tests/wp/parseRequest.php index 3e9d3114fd..edf65cb660 100644 --- a/tests/phpunit/tests/wp/parseRequest.php +++ b/tests/phpunit/tests/wp/parseRequest.php @@ -16,7 +16,22 @@ class Tests_WP_ParseRequest extends WP_UnitTestCase { } /** - * Test that PHP 8.1 "passing null to non-nullable" deprecation notice + * Tests the return value of the parse_request() method. + * + * @ticket 10886 + */ + public function test_parse_request_returns_bool() { + // Check that parse_request() returns true by default. + $this->assertTrue( $this->wp->parse_request() ); + + add_filter( 'do_parse_request', '__return_false' ); + + // Check that parse_request() returns false if the request was not parsed. + $this->assertFalse( $this->wp->parse_request() ); + } + + /** + * Tests that PHP 8.1 "passing null to non-nullable" deprecation notice * is not thrown when the home URL has no path/trailing slash (default setup). * * Note: This does not test the actual functioning of the parse_request() method. @@ -39,20 +54,4 @@ class Tests_WP_ParseRequest extends WP_UnitTestCase { $this->wp->parse_request(); $this->assertSame( '', $this->wp->request ); } - /** - * Test that the parse_request() returns bool - * - * @ticket 10886 - */ - public function test_parse_request_returns_bool() { - - // check if parse_request() returns true for default setup. - $this->assertTrue( $this->wp->parse_request(), 'returns true' ); - - // add filter to shortcut the parse_request function. - add_filter( 'do_parse_request', '__return_false' ); - $this->assertFalse( $this->wp->parse_request(), 'returns false' ); - remove_filter( 'do_parse_request', '__return_false' ); - - } }