Skip to content

Tests: Add unit tests for WP_Plugin_Install_List_Table::prepare_items() - #15721

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66554-plugin-install-list-table-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66554-plugin-install-list-table-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Part 1 of the tests for WP_Plugin_Install_List_Table (ticket #66554): prepare_items() and the sorting of the plugins. The class is big, so the tests are in several pull requests, one for each area. no_items() and get_dependencies_notice() already have tests, and the open PR for get_installed_plugins() is separate.

  • The tab: the first tab when none or an invalid one is requested, a tab that is not in the menu, the search and beta tabs, the upload tab for users who can upload plugins, and the install_plugins_tabs and install_plugins_nonmenu_tabs filters.
  • The arguments that the API receives for each tab: browsing (featured, popular, beta), the page, the recommended tab with the installed plugins, a search by term, tag and author (and the globals $type and $term), and the favorites (the user option, saving the user with a nonce, save=0, an invalid nonce, no user, and the favorites form).
  • The install_plugins_table_api_args_{$tab} filter, and that the API is not asked without arguments.
  • The items, the pagination (total, per page, pages) and the groups from the response, and the error of the API.
  • The plugins are sorted by a field in ascending and descending order, a plugin without the field keeps its place, and the API order is kept without a field.
  • The counts of the installed plugins that are sent to the updates script.

Testing

vendor/bin/phpunit --filter 'Tests_Admin_wpPluginInstallListTablePrepareItems::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_wpPluginInstallListTablePrepareItems::'
vendor/bin/phpcs tests/phpunit/tests/admin/wpPluginInstallListTablePrepareItems.php

Mutation check: 32 changes to prepare_items(), order_callback() and get_installed_plugins() (the tabs and their filters, the arguments of each tab, the favorites flow, the pagination, the sorting and the script data) were each caught by a test.

The tests set $wp_version to a version that is not a pre-release (the beta tab is listed for pre-releases), and use a new WP_Scripts instance.

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

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

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 reported for the added plugin installation list-table tests.

No open issues 🎉

What changed in this PR

Adds unit tests for WP_Plugin_Install_List_Table::prepare_items() as part of ticket #66554, expanding plugin installation list-table coverage without changing production code.

Changes:

  • Covers tab selection, filters, API arguments, search, and favorites handling.
  • Checks response items, pagination, groups, API errors, and plugin sorting.
  • Verifies installed-plugin data sent to the updates script, with isolated API responses and restored test globals.
File Description
tests/​phpunit/​tests/​admin/​wpPluginInstallListTablePrepareItems.php Adds tests for list-table preparation, sorting, and updates-script data.

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.

Great work covering WP_Plugin_Install_List_Table::prepare_items(), @hmbashar! Detailed testing of pagination, query arguments, tabs, and error paths.

All 96 CI matrix runs pass.

One minor coding standard detail: in tests/phpunit/tests/admin/wpPluginInstallListTablePrepareItems.php, the class name is currently Tests_Admin_wpPluginInstallListTablePrepareItems with a lowercase wp. Capitalizing to Tests_Admin_WpPluginInstallListTablePrepareItems will match standard Core naming conventions.

AI Review: Gemini 3.8 Flash

@hmbashar

hmbashar commented Nov 6, 2026

Copy link
Copy Markdown
Author

Thanks for the review, @huzaifaalmesbah. I kept the lowercase wp in Tests_Admin_wpPluginInstallListTablePrepareItems on purpose: it follows the existing classes in tests/phpunit/tests/admin/ (for example Tests_Admin_wpThemeInstallListTable, Tests_Admin_wpPostsListTable and Tests_Admin_wpUsersListTable), where the lowercase wp mirrors the wp_ prefix of the class name.

@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