Opened 6 days ago
Last modified 6 days ago
#66549 new enhancement
Tests: Add unit tests for the uncovered code of the Abilities API classes and the users and content abilities
| Reported by: | hmbashar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Abilities API | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The code coverage report on Codecov shows lines of the Abilities API that no test runs:
WP_Ability: unknown properties, a missing category, input without an input schema,wp_ability_validate_inputandwp_ability_validate_outputfilters that returnfalse, an invalid execute callback, a permission callback that returns aWP_Error, and serializing or unserializing the object.WP_Abilities_RegistryandWP_Ability_Categories_Registry: serializing and unserializing, the registry being requested beforeinit, and the first creation of the categories registry.WP_Ability_Category: an empty slug.WP_Abilities_Users: thedescription,url,first_name,last_name,nicknameandlocalefields, IDs that are not integers, rows that are not users, and a registration date that cannot be parsed.WP_Abilities_Content: posts whose parents loop, whose parent is not exposed, or whose status is not registered or not a string, and the IDs that are not in a list.
This ticket adds tests for these lines.
Change History (3)
This ticket was mentioned in PR #15710 on WordPress/wordpress-develop by @hmbashar.
6 days ago
#1
This ticket was mentioned in PR #15711 on WordPress/wordpress-develop by @hmbashar.
6 days ago
#2
Summary
Adds tests for code of the core/users-query ability that no test runs, according to the Codecov report.
- The
description,url,first_name,last_name,nicknameandlocalefields are returned with their values to a caller who can edit the user, and onlydescriptionandurlare returned to a caller who cannot. - The execute callback honors an ID sent as a digit string, a float, a decimal string or a signed string, and rejects a fraction, a number below 1, a float beyond
2 ** 53, a negative digit string and a word. - A row that is not a user is skipped when a query filter changes the fields of the query.
- A registration date that cannot be parsed is reported as
null.
Testing
vendor/bin/phpunit --filter 'Tests_Abilities_API_WpRegisterCoreUsersAbility::' vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Abilities_API_WpRegisterCoreUsersAbility::' vendor/bin/phpcs tests/phpunit/tests/abilities-api/wpRegisterCoreUsersAbility.php
Mutation check: 12 changes to class-wp-abilities-users.php (each field, the integer parsing, the skip of rows that are not users and the date check) were each caught by a test.
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 ticket was mentioned in PR #15712 on WordPress/wordpress-develop by @hmbashar.
6 days ago
#3
Summary
Adds tests for code of the core/content-query ability that no test runs, according to the Codecov report.
- An inherited post whose parents loop back to it is denied, and the check ends.
- An inherited post is denied when its parent is of a post type that is not exposed.
- A post with a status that is not registered is denied, even for an administrator.
- A post whose status is not a string is denied.
- The execute callback reads a single integer or float ID that is not in a list, and rejects
idsthat are not a list, a number or a string.
Testing
vendor/bin/phpunit --filter 'Tests_Abilities_API_WpRegisterCoreContentAbility::' vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Abilities_API_WpRegisterCoreContentAbility::' vendor/bin/phpcs tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php
Mutation check: 4 of 5 changes to class-wp-abilities-content.php were caught.
- The change that removes the "status is not a string" check survives. It is an equivalent change:
get_post_status_object( false )returnsnull, and the next check returnsfalsefor it too. The test still runs that line. - The two changes that remove the loop guard (the
isset()check and the$checked_post_idsupdate) were not run, because they recurse without end. The test fails instead of hanging only if the guard works.
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Summary
Adds tests for code of the Abilities API classes that no test runs, according to the Codecov report.
WP_Ability_doing_it_wrong()and ignored.categoryis required (missing, empty,null, integer and array).ability_missing_input_schemawhen the ability has no input schema.wp_ability_validate_inputandwp_ability_validate_outputfilters can reject withfalse(Invalid input./Invalid output.).ability_invalid_execute_callback.WP_Erroris reported with_doing_it_wrong()and its reason is not shown to the caller.Registries and category
WP_Abilities_RegistryandWP_Ability_Categories_Registrycannot be serialized or unserialized.WP_Ability_Categories_Registry::get_instance()returnsnullbeforeinit, and creates the registry once and fireswp_abilities_api_categories_init.WP_Ability_Categorythrows for an empty slug.Testing
Mutation check: 24 changes to the source (conditions, error codes and messages, the
throwof__sleep()and__wakeup(), theinitcheck, the action and the instance creation) were each caught by a test.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.