Skip to content

Add unit tests for AJAX actions: wp_ajax_dismiss_wp_pointer, `wp_aj… - #12138

Closed
pbearne wants to merge 4 commits into
WordPress:trunkfrom
pbearne:65252-ajax-actions-multiple-functions
Closed

pbearne wants to merge 4 commits into
WordPress:trunkfrom
pbearne:65252-ajax-actions-multiple-functions

Conversation

@pbearne

@pbearne pbearne commented Jun 9, 2026 •

Copy link
Copy Markdown

…ax_wp_fullscreen_save_post, and wp_ajax_wp_remove_post_lock`.

This PR adds unit tests for three AJAX handlers in ajax-actions.php to improve test coverage and ensure stability.

  • Trac ticket: https://core.trac.wordpress.org/ticket/65252

  • AI Disclosure:

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

Paul Bearne and others added 2 commits June 9, 2026 08:55
@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pbearne, lancewillett, ugyensupport.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Jun 9, 2026

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.

@dugyen

dugyen commented Sep 2, 2026

Copy link
Copy Markdown

Test report

Applied this PR's diff cleanly to current trunk and ran it against the WP core PHPUnit suite (PHPUnit 9.6.36, PHP 8.3, local MySQL test DB).

Results:

  • ✅ Patch applies cleanly — purely additive, 3 new test files, no production code touched.
  • ✅ All 7 new tests pass:
    • wp_ajax_dismiss_wp_pointer: 3 tests, 6 assertions
    • wp_ajax_wp_fullscreen_save_post: 2 tests, 6 assertions
    • wp_ajax_wp_remove_post_lock: 2 tests, 7 assertions
  • ✅ Mutation check — deliberately broke wp_ajax_dismiss_wp_pointer() (forced an early wp_die( 0 )) and the suite correctly caught it (1 failure, expected '1' got '0'), confirming the tests aren't tautological.
  • ✅ No naming/registration collisions with the existing tests/phpunit/tests/ajax/ suite.
  • ✅ WPCS: 0 violations across all 3 new files (phpcs.xml.dist).

Also manually reviewed the wp_ajax_wp_remove_post_lock() window-math assertion (time() - 145) against the source — it's correct, no false-positive risk there.

LGTM.

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.

🟡 Changes recommended

Both AJAX tests can pass despite missing the expected handler termination because their success-response assertions run only when _handleAjax() throws.

1 open issue
What changed in this PR

This PR expands WordPress AJAX handler test coverage with seven tests across three new test classes. It changes tests only, with no production behavior changes.

Changes:

  • Tests pointer dismissal for valid, invalid, and already-dismissed pointers.
  • Tests fullscreen post saving and invalid nonce rejection.
  • Tests post-lock removal by the lock owner and rejection for another user.
File Description
tests/​phpunit/​tests/​admin/​includes/​ajax-actions/​wp_ajax_wp_remove_post_lock.php Adds lock-removal and ownership tests.
tests/​phpunit/​tests/​admin/​includes/​ajax-actions/​wp_ajax_wp_fullscreen_save_post.php Adds save-success and invalid-nonce tests.
tests/​phpunit/​tests/​admin/​includes/​ajax-actions/​wp_ajax_dismiss_wp_pointer.php Adds pointer-dismissal and metadata tests.

Review effort: Balanced

);

try {
$this->_handleAjax( 'dismiss-wp-pointer' );

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These seven checks verify the saved pointer, post content, and post-lock state. None fails in either local AJAX run. The post-lock time bound matches the handler. Code approved; fresh CI is pending because the prior logs expired.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

@pbearne The patch passes local randomized PHPUnit checks against current trunk in single-site and multisite, plus PHP lint and coding standards.

The remaining failed checks are from June. Their logs have expired, and GitHub rejected a job rerun because the run is over a month old. I cannot establish the cause from the retained metadata. Could you refresh this branch against trunk to produce a current CI run before landing?

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Verify menu metabox output and saved menu locations, dismissed pointers, fullscreen post updates, and post-lock ownership and expiry. Cover relevant permission and nonce rejection paths.

Developed in: #11897, #11899, #12138

Props pbearne, ugyensupport.
See #65252.


git-svn-id: https://develop.svn.wordpress.org/trunk@65152 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Verify menu metabox output and saved menu locations, dismissed pointers, fullscreen post updates, and post-lock ownership and expiry. Cover relevant permission and nonce rejection paths.

Developed in: WordPress/wordpress-develop#11897, WordPress/wordpress-develop#11899, WordPress/wordpress-develop#12138

Props pbearne, ugyensupport.
See #65252.

Built from https://develop.svn.wordpress.org/trunk@65152


git-svn-id: http://core.svn.wordpress.org/trunk@64301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

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.

4 participants