Make WordPress Core

Opened 6 weeks ago

Last modified 5 weeks ago

#65180 new feature request

Tests: Add unit tests for wp_reset_vars()

Reported by: pbearne's profile pbearne Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch has-unit-tests
Focuses: tests Cc:

Description

This ticket adds unit tests for the wp_reset_vars() function in wp-admin/includes/misc.php. This function resets global variables based on $_GET and $_POST values.

Change History (3)

This ticket was mentioned in PR #11737 on WordPress/wordpress-develop by @pbearne.


6 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Description:
This PR adds unit tests for the wp_reset_vars() function in wp-admin/includes/misc.php. These tests ensure that the function correctly resets global variables based on the values in $_POST and $_GET, or defaults them to an empty string.

The tests cover:

  • Resetting variables from $_POST when they are not empty.
  • Resetting variables from $_GET when they are empty in $_POST (including cases like '0' or '').
  • Defaulting variables to an empty string when they are missing from both $_POST and $_GET.
  • Handling multiple variables simultaneously.

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

AI Disclosure:

  • AI assistance: Yes
  • Tool(s): Junie (JetBrains)
  • Model(s): gemini-3-flash-preview
  • Used for: Code analysis, test implementation, and workflow management.

#2 @darshitrajyaguru97
5 weeks ago

Tested the patch locally and confirmed the new wp_reset_vars() tests are passing successfully.

Environment:

  • WordPress: trunk
  • PHP: 8.2.29
  • Database: MySQL
  • PHPUnit: latest Core test suite

The added coverage looks solid overall, especially around documenting the current empty() behavior for values like '0' and ''.

A few additional edge cases may be worth considering, either in this patch or a potential follow-up:

  • false
  • 0 (integer)
  • null
  • array values

Additionally, in tear_down(), previously unset globals could potentially be restored using unset() instead of assigning null, which may help preserve the original global state more accurately.

Patch tests successfully.

#3 @desrosj
5 weeks ago

  • Focuses tests added

Adding the tests focus, which is used to indicate a ticket is solely focused on adding tests.

Note: See TracTickets for help on using tickets.