Make WordPress Core

Opened 4 months ago

Last modified 4 months ago

#65198 new enhancement

Tests: Add unit tests for wp_refresh_metabox_loader_nonces()

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

Description

This ticket adds comprehensive unit tests for the wp_refresh_metabox_loader_nonces() function in wp-admin/includes/misc.php. These tests ensure that the function correctly returns refreshed nonces (meta-box-loader and update-post_{$post_id}) when valid data is provided and the user has edit permissions.

Change History (2)

#1 @pbearne
4 months ago

  • Focuses tests added

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


4 months ago
#2

  • Keywords has-patch has-unit-tests added

…ludes/misc.php
Description:
This PR adds unit tests for the wp_refresh_metabox_loader_nonces() function in wp-admin/includes/misc.php. These tests ensure that the function correctly refreshes nonces used for meta boxes in the block editor 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 metabox_loader_nonce and _wpnonce when authorized.

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

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.