Skip to content

Tests: Add unit test coverage for WP_Plugins_List_Table::no_items() - #14585

Closed
huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:tests/plugins-list-table-no-items
Closed

huzaifaalmesbah wants to merge 2 commits into
WordPress:trunkfrom
huzaifaalmesbah:tests/plugins-list-table-no-items

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Description

Adds tests for WP_Plugins_List_Table::no_items(), the message shown on the Plugins screen when a view or search has no plugins. The method had no tests.

The tests set the $plugins global and the search request, and restore both, along with the request URI that the list table changes for a search. They cover:

  • "No plugins are currently available." without installed plugins, and "No plugins found." when plugins are installed but none are in the view;
  • an empty or '0' search term not being treated as a search;
  • the search message with the link to search the plugin directory, on single site, for a user who can install plugins;
  • the search term being unslashed, URL-decoded and escaped in the message, and encoded in the link;
  • no directory link for a user who cannot install plugins, or on multisite.

Removing or changing each branch of the method makes at least one test fail on single site or multisite.

This is a test-only change; no production code is modified.

Testing Instructions

  1. Run the tests on single site:
    npm run test:php -- --filter Tests_Admin_wpPluginsListTableNoItems
  2. Run them on multisite:
    npm run test:php -- --filter Tests_Admin_wpPluginsListTableNoItems -c tests/phpunit/multisite.xml
  3. Run them in random order:
    npm run test:php -- --filter Tests_Admin_wpPluginsListTableNoItems --order-by=random
  4. Run the plugins group:
    npm run test:php -- --group plugins
  5. Run PHPCS on the test file:
    node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/wpPluginsListTableNoItems.php

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Brainstorming edge-case scenarios and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.

@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review October 20, 2026 21:27
@github-actions

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. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props huzaifaalmesbah.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@huzaifaalmesbah

Copy link
Copy Markdown
Member Author

Small follow-up in ec3b7ae: tear_down() now unsets $_SERVER['REQUEST_URI'] when it was not set before the test, instead of setting it to null, so no state leaks into later tests.

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

Static review found no blocking issues in the focused test-only changes; tests were not executed.

No open issues 🎉

What changed in this PR

Adds unit coverage for the Plugins screen’s empty-state messages without changing production code.

Changes:

  • Tests empty plugin lists, unmatched views, and empty search terms.
  • Covers search escaping and directory-link visibility by capability and multisite status.
File Description
tests/​phpunit/​tests/​admin/​wpPluginsListTableNoItems.php Adds tests for WP_Plugins_List_Table::no_items().

Review effort: Balanced

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

The unit-tests audit found no landing blockers. The affected classes passed individually and together across three randomized seeds on single-site and multisite, with no failures or skips. PHPCS passed. CI is still running; please wait for it before landing.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 20, 2026
Test `WP_Plugins_List_Table::no_items()` for empty views, search terms, escaped output, directory links, installation permissions, and multisite behavior.

Developed in: #14585

Props huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64668 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 20, 2026
Test `WP_Plugins_List_Table::no_items()` for empty views, search terms, escaped output, directory links, installation permissions, and multisite behavior.

Developed in: WordPress/wordpress-develop#14585

Props huzaifaalmesbah.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64668


git-svn-id: http://core.svn.wordpress.org/trunk@63818 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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