Skip to content

Tests: Add unit tests for WP_Plugin_Dependencies::get_dependency_api_data() - #15736

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66560-plugin-dependencies-api-data-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66560-plugin-dependencies-api-data-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for WP_Plugin_Dependencies::get_dependency_api_data() and get_plugin_dirnames(). The notice for unmet dependencies on a network (the other lines that Codecov shows) already has a test that only runs on multisite, and the code of the Ajax request has its own test class, so these are the parts that were left.

  • The data is returned only on the plugins and the new plugins screens (not on others), and the data that was read before is returned as it is.
  • The API is asked for a dependency without data, with the name copied to the Name key, and the data and the time to ask again are kept in transients.
  • The API is not asked when the data has a date of the last update, is asked again when it has none or when the time to ask again has passed, and a dependency that the API cannot find is left out.
  • A dependency that is not on WordPress.org uses its slug as its name, or the name of the installed plugin.
  • The data of a slug that is no longer a dependency is removed, the data is sorted by slug, and empty data is removed.
  • get_plugin_dirnames() returns the folders that it listed before, and lists the plugin folders by slug.

Testing

vendor/bin/phpunit --filter 'Tests_Admin_WPPluginDependencies_GetDependencyApiData::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_WPPluginDependencies_GetDependencyApiData::'
vendor/bin/phpcs tests/phpunit/tests/admin/plugin-dependencies/getDependencyApiData.php

Mutation check: 17 changes to the two methods (the screen check, the cached data, the transients, the names, the API errors, the removal, the sorting and the cache of the folders) were each caught by a test.

The tests use the base class of the Plugin Dependencies tests to set the static properties.

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

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 15:59
@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.

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

No active review issues are recorded for the added plugin dependency API and directory-mapping tests.

No open issues 🎉

What changed in this PR

Adds unit tests for WordPress plugin dependency API data and plugin-directory mapping, without changing production code.

Changes:

  • Covers screen restrictions, cached data, API requests, transient refreshes, and API errors.
  • Tests fallback names, removal of stale or empty data, and sorting by slug.
  • Verifies cached and newly generated plugin-directory mappings.
File Description
tests/​phpunit/​tests/​admin/​plugin-dependencies/​getDependencyApiData.php Adds tests for get_dependency_api_data() and get_plugin_dirnames(), with mocked API responses and transient cleanup.

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah 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.

Awesome work on this, @hmbashar! The tests for WP_Plugin_Dependencies::get_dependency_api_data() are very comprehensive, properly testing transients, circular dependencies, error responses, and directory mapping.

Clean mocking via the plugins_api filter and proper static cleanup in tear_down(). All 97 CI checks pass.

Looks ready to land!

AI Review: Gemini 3.8 Flash

@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.

3 participants