Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#65197 new enhancement

Tests: Add unit tests for wp_refresh_post_nonces()

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: Cc:

Description

This ticket adds comprehensive unit tests for the wp_refresh_post_nonces() function in wp-admin/includes/misc.php. These tests ensure that the function correctly returns refreshed nonces for post locking and unlocking when appropriate Heartbeat data is provided and the user has the necessary permissions.

Change History (1)

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


5 weeks ago
#1

  • Keywords has-patch has-unit-tests added

….php
Description:
This PR adds unit tests for the wp_refresh_post_nonces() function in wp-admin/includes/misc.php. These tests ensure that the function correctly refreshes post-related nonces (like getpermalinknonce, _wpnonce, etc.) during Heartbeat requests, while verifying user permissions and handling invalid post IDs.

The tests cover:

  • Handling of missing or empty Heartbeat data.
  • Validation of the post_id parameter (zero, string, non-numeric).
  • Verification that no nonces are refreshed if the current user cannot edit the post.
  • Successful generation and verification of all 5 nonces (getpermalinknonce, samplepermalinknonce, closedpostboxesnonce, _ajax_linking_nonce, and _wpnonce) when authorized.

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

AI Disclosure:

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