Repository navigation
Tests: Add unit tests for is_protected_endpoint() - #14472
shail-mehta wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
Static review found no blocking issues in this test-only change; tests were not executed.
No open issues 🎉
What changed in this PR
Adds dedicated PHPUnit coverage for is_protected_endpoint() under ticket #65819, without changing production code.
Changes:
- Covers front-end, login, admin, and protected versus unprotected Ajax requests.
- Verifies filter behavior, with state cleanup and process isolation where needed.
| File | Description |
|---|---|
| tests/phpunit/tests/load/isProtectedEndpoint.php | Adds endpoint protection and filter tests. |
Review effort: Balanced
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks for the tests. The assertions match is_protected_endpoint(). One suggestion inline that would remove the need for separate processes.
| * @preserveGlobalState disabled | ||
| */ | ||
| public function test_returns_true_for_protected_ajax_action() { | ||
| define( 'DOING_AJAX', true ); |
There was a problem hiding this comment.
wp_doing_ajax() filters this constant: apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ). Could these tests use add_filter( 'wp_doing_ajax', '__return_true' ); instead of define()? Then they can drop @runInSeparateProcess and run in the normal process. The test framework restores hooks after each test. Each separate process starts WordPress again, so this keeps the suite faster.
The same applies to the other DOING_AJAX tests in this file. #14473 has the same pattern.
lancewillett
left a comment
There was a problem hiding this comment.
The admin/Ajax intersection and filter checks protect the endpoint decisions. Mukesh’s suggestion to replace constant definitions with the Ajax filter is addressed, allowing normal in-process execution. No blockers found.
Unit-tests audit and Copilot review found no blockers. PHPCS passed. Each class passed separately, and the combined batch passed randomized single-site and multisite runs: 63 tests, 95 assertions each (seeds 65829 and 65830). CI is green on the reviewed commit.
AI review · gpt-6
Verify protection for login, admin, and selected Ajax requests, front-end defaults, and the endpoint filter. Use the Ajax filter to avoid unnecessary process isolation. Developed in: #14472 Props shailu25, mukesh27. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64551 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #14472 landed in https://core.trac.wordpress.org/changeset/64551 |
Verify protection for login, admin, and selected Ajax requests, front-end defaults, and the endpoint filter. Use the Ajax filter to avoid unnecessary process isolation. Developed in: WordPress/wordpress-develop#14472 Props shailu25, mukesh27. See #65819. Built from https://develop.svn.wordpress.org/trunk@64551 git-svn-id: http://core.svn.wordpress.org/trunk@63701 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What
Trac ticket: #65819
Adds unit tests for
is_protected_endpoint()intests/phpunit/tests/load/isProtectedEndpoint.php.Covers front, login, admin, Ajax, and the
is_protected_endpointfilter.Test-only change.
Why
This helper has had no dedicated PHPUnit coverage. Fits the #65819 missing-coverage track, and no open PR covers it.
How
Testing instructions
Use of AI Tools