Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#65196 new enhancement

Tests: Add unit tests for wp_refresh_post_lock()

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_lock() function in wp-admin/includes/misc.php. These tests ensure that the function correctly updates the post lock, handles invalid post IDs, and returns the appropriate Heartbeat response data (including updated lock and nonces if necessary).

Change History (1)

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


5 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Description:
This PR adds unit tests for the wp_refresh_post_lock() function in wp-admin/includes/misc.php. These tests ensure that the function correctly refreshes the post lock during Heartbeat requests, handles cases where the post is locked by another user, and verifies that the current user has the necessary permissions.

The tests cover:

  • Handling of missing or empty Heartbeat data.
  • Validation of the post_id parameter (zero, string, negative).
  • Verification that no lock refresh occurs if the user cannot edit the post.
  • Correct return of lock_error when the post is locked by another user, including optional avatar URLs.
  • Successful updating of the post lock and returning the new_lock value.

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

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.