Skip to content

Tests: Add unit tests for is_protected_endpoint() - #14472

Closed
shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:65819-add-is-protected-endpoint-tests
Closed

shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:65819-add-is-protected-endpoint-tests

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

What

Trac ticket: #65819

Adds unit tests for is_protected_endpoint() in tests/phpunit/tests/load/isProtectedEndpoint.php.

Covers front, login, admin, Ajax, and the is_protected_endpoint filter.

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

  • Assert login and admin requests are protected, and front-end requests are not
  • Cover protected vs unprotected Ajax actions
  • Confirm the filter can add endpoints and does not run when the request is already protected

Testing instructions

npm run test:php -- --filter Tests_Load_IsProtectedEndpoint

Use of AI Tools

  • Cursor

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.

🟢 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

@shail-mehta
shail-mehta marked this pull request as ready for review October 19, 2026 08:41
@github-actions

github-actions Bot commented Oct 19, 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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props shailu25, mukesh27.

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

@mukeshpanchal27 mukeshpanchal27 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.

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 );

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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in c5a784e

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.

🟢 Approval recommended

Static review found no blocking issues in this test-only change; PHPUnit was not executed.

No open issues 🎉

Review effort: Balanced

@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.

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

wporg-sync pushed a commit that referenced this pull request Oct 19, 2026
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
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 19, 2026
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
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