Skip to content

Site Health: Add unit tests for zero active plugins and installed themes - #13960

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/56134-site-health-zero-count-tests
Open

irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/56134-site-health-zero-count-tests

Conversation

@irozum

@irozum irozum commented Oct 3, 2026

Copy link
Copy Markdown

What this covers: Adds unit tests for WP_Site_Health::get_test_plugin_version() and WP_Site_Health::get_test_theme_version(), specifically the zero-count messaging branch that [53816] / [53817] introduced for this ticket.

Why these cases: Before [53816], a site with 0 active plugins (or 0 installed themes) got the confusing "Your site has 0 active plugins, and they are all up to date." wording. The fix added a dedicated branch for the zero case ("Your site does not have any active plugins." / "...does not have any installed themes."), but neither method had any test coverage at all, so nothing guards that wording today.

  • test_get_test_plugin_version_with_no_active_plugins — sets active_plugins to an empty array and asserts the description contains the zero-plugins message.
  • test_get_test_theme_version_with_no_installed_themes — temporarily points $wp_theme_directories at an empty list (clearing the themes cache, same pattern used in Tests_Theme_ThemeDir) so wp_get_themes() returns no themes, then asserts both the good status and the zero-themes message.

Test-only change: this PR adds no production behaviour — git diff trunk touches only tests/phpunit/tests/admin/wpSiteHealth.php. Each new test was verified to fail when the corresponding message string in src/wp-admin/includes/class-wp-site-health.php is altered, then verified to pass again once reverted.

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

This is a follow-up to [53816] (and its coding-standards follow-up [53817]), which already fixed and closed this ticket — these tests just add the missing coverage.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Picking the ticket, reading the existing fix and surrounding code to determine the exact untested branches, writing the two test methods, and running the red/green verification loop. I reviewed the diff and test output before opening this PR.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 3, 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. 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 irozum.

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

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

Thanks for working on this, @irozum! I really appreciate you covering the zero-count wording in get_test_plugin_version() and get_test_theme_version(); neither method had a test in the Site Health suite before, and emptying the theme directories to reach the no-themes branch is a neat way to get there.

One note on the ticket: #56134 was closed as fixed in 6.1, so it can't take new commits. Coverage additions without a ticket of their own usually go under the release's test umbrella ticket, which for 7.2 is #65819. Would you be open to updating the Trac ticket: link in the description to that one?

I left one small note inline as well.

AI Review: Opus 5.5

* @covers ::get_test_plugin_version
*/
public function test_get_test_plugin_version_with_no_active_plugins() {
update_option( 'active_plugins', array() );

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.

On multisite, is_plugin_active() also counts network-activated plugins, so this relies on active_sitewide_plugins being empty in the test environment. Would it be worth clearing that too when is_multisite(), so the "no active plugins" precondition is explicit in both setups?

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.

2 participants