Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/phpunit/tests/query/parseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,49 @@ public function test_parse_query_hierarchical_taxonomy_query_var_array() {

$this->assertIsArray( $q->posts );
}

/**
* Tests that a secondary query can be `is_home` while serving a REST request.
*
* Runs in a separate process because constants cannot be redefined.
*
* @ticket 50213
*
* @covers WP_Query::parse_query
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_secondary_query_during_rest_request_can_be_home() {
define( 'REST_REQUEST', true );

$query = new WP_Query();
$query->parse_query( array() );

$this->assertFalse( $query->is_main_query(), 'Precondition: the query must not be the main query.' );
$this->assertTrue( $query->is_home );
}

/**
* Tests that the main query is not `is_home` while serving a REST request.
*
* Runs in a separate process because constants cannot be redefined.
*
* @ticket 50213
*
* @covers WP_Query::parse_query
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_main_query_during_rest_request_is_not_home() {
define( 'REST_REQUEST', true );

$query = new WP_Query();
$GLOBALS['wp_the_query'] = $query;
$query->parse_query( array() );

$this->assertTrue( $query->is_main_query(), 'Precondition: the query must be the main query.' );
$this->assertFalse( $query->is_home );
}
}
Loading