Skip to content

Build/Test Tools: Preserve plugin query vars between tests - #12730

Draft
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-37207-preserve-plugin-query-vars
Draft

Build/Test Tools: Preserve plugin query vars between tests#12730
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-37207-preserve-plugin-query-vars

Conversation

@ArkaPrabhaChowdhury

Copy link
Copy Markdown

Preserves public query variables registered by plugins during bootstrap when the WordPress test suite runs in non-core mode. This prevents endpoints registered on init from disappearing after the first test while retaining the existing reset behavior for core tests.

Adds regression coverage across the actual test teardown boundary.

Trac ticket: https://core.trac.wordpress.org/ticket/37207

Testing

  • Focused rewrite endpoint suite: 10 tests, 19 assertions
  • Ticket group: 2 tests, 2 assertions
  • External plugin-mode reproduction: 2 tests, 2 assertions
  • PHP syntax checks
  • PHPCBF and PHPCS
  • git diff --check

Use of AI Tools

AI assistance: Yes
Tool(s): OpenAI Codex
Model(s): GPT-5
Used for: Ticket investigation, implementation, regression tests, and local validation; the resulting diff and test output were reviewed before publication.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copilot AI review requested due to automatic review settings July 28, 2026 08:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Preserves plugin-registered public query vars across PHPUnit test teardown when running the WordPress test suite in non-core (“plugin”) mode, preventing rewrite endpoints registered during bootstrap/init from disappearing after the first test.

Changes:

  • Capture the initial $wp->public_query_vars during bootstrap for non-core test runs.
  • Restore those captured query vars onto the fresh WP instance created during WP_UnitTestCase::tear_down().
  • Add regression tests that validate preservation across an actual test teardown boundary.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/phpunit/includes/bootstrap.php Captures initial public query vars after wp-settings.php in non-core mode.
tests/phpunit/includes/abstract-testcase.php Restores captured public query vars during test teardown when present.
tests/phpunit/tests/rewrite/addRewriteEndpoint.php Adds regression coverage validating query vars persist across teardown in plugin-mode scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +75
public function test_should_preserve_query_vars_registered_during_plugin_bootstrap() {
add_rewrite_endpoint( 'plugin-endpoint', EP_ROOT );
$GLOBALS['_wp_tests_initial_public_query_vars'] = $GLOBALS['wp']->public_query_vars;

$this->assertContains( 'plugin-endpoint', $GLOBALS['wp']->public_query_vars );
}

/**
* Verifies the query variables after the preceding test's tear down.
*
* @ticket 37207
*
* @depends test_should_preserve_query_vars_registered_during_plugin_bootstrap
*/
public function test_should_restore_query_vars_registered_during_plugin_bootstrap() {
try {
$this->assertContains( 'plugin-endpoint', $GLOBALS['wp']->public_query_vars );
} finally {
unset( $GLOBALS['_wp_tests_initial_public_query_vars'] );
}
}
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI review requested due to automatic review settings July 28, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants