Skip to content

Tests: Add unit tests for the uncovered code of the Abilities API classes - #15710

Closed
hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66549-abilities-api-classes-tests
Closed

hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66549-abilities-api-classes-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for code of the Abilities API classes that no test runs, according to the Codecov report.

WP_Ability

  • An unknown property is reported with _doing_it_wrong() and ignored.
  • The category is required (missing, empty, null, integer and array).
  • Input is rejected with ability_missing_input_schema when the ability has no input schema.
  • The wp_ability_validate_input and wp_ability_validate_output filters can reject with false (Invalid input. / Invalid output.).
  • An ability of a custom class without an execute callback returns ability_invalid_execute_callback.
  • A permission callback that returns a WP_Error is reported with _doing_it_wrong() and its reason is not shown to the caller.
  • The ability cannot be serialized or unserialized.

Registries and category

  • WP_Abilities_Registry and WP_Ability_Categories_Registry cannot be serialized or unserialized.
  • WP_Ability_Categories_Registry::get_instance() returns null before init, and creates the registry once and fires wp_abilities_api_categories_init.
  • WP_Ability_Category throws for an empty slug.

Testing

vendor/bin/phpunit --filter 'Tests_Abilities_API_WpAbility::'
vendor/bin/phpunit --filter 'Tests_Abilities_API_WpAbilitiesRegistry::'
vendor/bin/phpunit --filter 'Tests_Abilities_API_WpAbilityCategoryRegistry::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Abilities_API_'
vendor/bin/phpcs tests/phpunit/tests/abilities-api/

Mutation check: 24 changes to the source (conditions, error codes and messages, the throw of __sleep() and __wakeup(), the init check, the action and the instance creation) were each caught by a test.

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

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.

@github-actions

github-actions Bot commented Nov 6, 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.

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.

@hmbashar hmbashar closed this Nov 12, 2026
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.

1 participant