Skip to content

Tests: Add unit tests for plugins_api() - #15714

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66553-plugins-api-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66553-plugins-api-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for plugins_api(), which had no direct tests (17 lines were not covered on Codecov).

  • The arguments are passed to the filters as an object, with the default locale and WordPress version, and with 24 plugins per page for a query only.
  • The plugins_api_args, plugins_api and plugins_api_result filters: a result of plugins_api is returned without a request and is marked as external, except for an error.
  • The request to api.wordpress.org/plugins/info/1.2/, its action, arguments, timeout and user agent, and the response as an object.
  • A response that is not JSON, an error in the response, and a JSON value that is not an array.
  • A failed secure request is made again without SSL, and the failure is reported, except in a JSON request.

Testing

vendor/bin/phpunit --filter 'Admin_Includes_Plugin_Install_PluginsApi_Test::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Admin_Includes_Plugin_Install_PluginsApi_Test::'
vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin-install/PluginsApi_Test.php

Mutation check: 24 changes to plugins_api() (defaults, conditions, timeout, user agent, SSL retry, error codes and data, the external flag and the filters) were each caught by a test.

The branch that makes one request when SSL is not supported is not tested, because wp_http_supports() depends on the transports of the server. The two SSL tests are skipped when SSL is not supported.

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

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.

@hmbashar
hmbashar marked this pull request as ready for review November 6, 2026 14:11
@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