Skip to content

Tests: Add unit coverage for the core abilities registered in abilities.php. - #15528

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66493-core-abilities-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66493-core-abilities-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 5, 2026

Copy link
Copy Markdown

Adds unit tests for behaviors of the core abilities registered in src/wp-includes/abilities.php that had no test, in tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php. No behavior is changed.

What is covered:

  • core/get-site-info permission
    • Allowed for an administrator, and for a user who only has manage_options delegated.
    • Denied, through both check_permissions() and execute(), for a subscriber and for a logged-out visitor.
  • Core ability categories
    • The label and description of the site, user and content categories. Only uncategorized was asserted before.
  • The core information abilities (core/get-site-info, core/get-user-info and core/get-environment-info)
    • Each one belongs to the expected, registered category.
    • Each one is annotated as read-only, not destructive and idempotent.
  • roles of core/get-user-info
    • A user with several roles gets them in order.
    • Roles that are not numbered in sequence are still returned as a list, and encoded as a JSON array.
    • A user without roles gets an empty list.

The permission tests check the outcome (check_permissions() and execute()), not how the capability is declared, so they stay valid if the way abilities declare required capabilities changes (see #66325).

Testing:

  • vendor/bin/phpunit --filter Tests_Abilities_API_WpRegisterCoreAbilities
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Abilities_API_WpRegisterCoreAbilities
  • vendor/bin/phpunit --group abilities-api
  • vendor/bin/phpcs tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php

I also temporarily broke the related lines in src/wp-includes/abilities.php (the required capability of core/get-site-info, the label and descriptions of the three categories, the category of an ability, each of the three annotations, and the array_values() call for the roles) and confirmed that a new test fails for each one.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…es.php.

Adds tests for the permission of `core/get-site-info`, the label and description of the `site`, `user` and `content` ability categories, the category and annotations of the core information abilities, and the `roles` returned by `core/get-user-info`.

See #66493.
@github-actions

github-actions Bot commented Nov 5, 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 hmbashar, gziolo.

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.

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

The review identifies no active issues with the added unit coverage for core abilities.

No open issues 🎉

What changed in this PR

Adds unit coverage for core abilities registered in src/wp-includes/abilities.php, without changing production behavior.

Changes:

  • Tests core/get-site-info permissions for administrators, delegated capability holders, subscribers, and logged-out visitors.
  • Verifies core category labels and descriptions, ability category assignments, and read-only, non-destructive, idempotent annotations.
  • Covers user-role ordering, normalization of sparse arrays, JSON array encoding, and users without roles.
File Description
tests/​phpunit/​tests/​abilities-api/​wpRegisterCoreAbilities.php Adds permission, category, annotation, and user-role tests for core abilities.

Review effort: Balanced

@gziolo gziolo 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 new tests! The tests for categories, annotations, delegated manage_options and user roles are useful. My comments are mostly about overlap with existing tests.

@gziolo gziolo 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 quick update, @hmbashar! All the feedback is addressed. The tests now focus on behavior we want to keep and don't overlap with the existing ones. Looks good to me. I will commit it once CI passes.

wporg-sync pushed a commit that referenced this pull request Nov 6, 2026
Cover `core/get-site-info` permissions, the categories and annotations of the core information abilities, and the roles returned by `core/get-user-info`.

Developed in #15528.

Props hmbashar, gziolo.
Fixes #66493.




git-svn-id: https://develop.svn.wordpress.org/trunk@65307 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65307
GitHub commit: 6af9238

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 6, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 6, 2026
Cover `core/get-site-info` permissions, the categories and annotations of the core information abilities, and the roles returned by `core/get-user-info`.

Developed in WordPress/wordpress-develop#15528.

Props hmbashar, gziolo.
Fixes #66493.



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


git-svn-id: http://core.svn.wordpress.org/trunk@64447 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.

3 participants