Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only unauthenticate user when parse_query is for the main query #712

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Add test case for wp_unauthenticate_error_template_requests()
westonruter committed Feb 26, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
westonruter Weston Ruter
commit 8553fd820dff4d5b9b50825d6016a0330fb051a6
20 changes: 20 additions & 0 deletions tests/test-general-template.php
Original file line number Diff line number Diff line change
@@ -75,4 +75,24 @@ public function test_wp_unauthenticate_error_template_requests( $request_url, $a
$this->assertEquals( 0, get_current_user_id() );
}
}

/**
* Test that that `wp_unauthenticate_error_template_requests()` running at the `parse_query` action doesn't cause
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Test that that `wp_unauthenticate_error_template_requests()` running at the `parse_query` action doesn't cause
* Test that `wp_unauthenticate_error_template_requests()` running at the `parse_query` action doesn't cause

* an incorrect usage notice if there is not global `$wp_query` yet, such as when doing a subquery early in the WP
* execution flow.
*
* @covers ::wp_unauthenticate_error_template_requests()
*/
public function test_wp_unauthenticate_error_template_requests_for_subqueries() {
global $wp_query;
$wp_query = null;

$user_id = $this->factory()->user->create( array( 'role' => 'author' ) );
wp_set_current_user( $user_id );

$query = new WP_Query();
$query->parse_query( 's=test' );

$this->assertTrue( is_user_logged_in() );
}
}