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
This commit is contained in:
Sergey Biryukov 2022-03-02 15:38:27 +00:00
parent 69b9940da2
commit b28dcfd832
2 changed files with 21 additions and 17 deletions

View File

@ -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.
*

View File

@ -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' );
}
}