Opened 6 days ago
Closed 5 days ago
#66493 closed enhancement (fixed)
Tests: Add unit coverage for the core abilities registered in abilities.php
| Reported by: | hmbashar | Owned by: | gziolo |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Abilities API | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | tests |
Description
src/wp-includes/abilities.php registers the core ability categories and the core/get-site-info, core/get-user-info and core/get-environment-info abilities. The existing tests in tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php cover their schemas, execution, the fields input and the permissions of core/get-environment-info (#66369), but a few behaviors have no test:
- Permission of
core/get-site-info. The ability requiresmanage_options, but no test checks that a user without it, or a logged-out visitor, is denied, or that an administrator is allowed.core/get-environment-infoandcore/get-user-infoalready have such tests. - The
site,userandcontentcategories. Only theuncategorizedcategory has its label and description asserted. The other three are only used as a slug by the tests of other abilities. - The annotations. The
readonly,destructiveandidempotentannotations of the three abilities are not asserted. The registration tests only checkpublicandshow_in_rest. - The
rolesfield ofcore/get-user-info. Only the first role of a user with one role is asserted. The ability re-indexes the roles witharray_values()so they are encoded as a JSON list, but there is no test for a user with several roles or with none.
Proposed scope
Add tests to wpRegisterCoreAbilities.php that verify:
core/get-site-info:check_permissions()andexecute()for an administrator, a subscriber and a logged-out visitor, and that a user with onlymanage_optionsdelegated can use it.- The label and description of the
site,userandcontentcategories, and the category of each of the three abilities. - The annotations of the three abilities (read-only, not destructive, idempotent).
core/get-user-info: therolesof a user with several roles and of a user without roles are lists, in the order of the user's roles.
The tests check the outcome (check_permissions() and execute()) and not how the capability is declared, so they stay valid if the way abilities declare capabilities changes (see #66325).
Out of scope
This ticket only adds tests and does not change behavior. The settings, users and content abilities registered at the end of wp_register_core_abilities() have their own test files and are not touched.
Change History (4)
This ticket was mentioned in PR #15528 on WordPress/wordpress-develop by @hmbashar.
6 days ago
#1
- Keywords has-patch has-unit-tests added; needs-patch removed
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Adds unit tests for behaviors of the core abilities registered in
src/wp-includes/abilities.phpthat had no test, intests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.php. No behavior is changed.What is covered:
core/get-site-infopermissionmanage_optionsdelegated.check_permissions()andexecute(), for a subscriber and for a logged-out visitor.site,userandcontentcategories. Onlyuncategorizedwas asserted before.core/get-site-info,core/get-user-infoandcore/get-environment-info)rolesofcore/get-user-infoThe permission tests check the outcome (
check_permissions()andexecute()), 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_WpRegisterCoreAbilitiesvendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Abilities_API_WpRegisterCoreAbilitiesvendor/bin/phpunit --group abilities-apivendor/bin/phpcs tests/phpunit/tests/abilities-api/wpRegisterCoreAbilities.phpI also temporarily broke the related lines in
src/wp-includes/abilities.php(the required capability ofcore/get-site-info, the label and descriptions of the three categories, the category of an ability, each of the three annotations, and thearray_values()call for the roles) and confirmed that a new test fails for each one.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.