Skip to content

Tests: Add unit tests for the plugin status functions and activate_plugins() - #15716

Open
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66555-plugin-status-tests
Open

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66555-plugin-status-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Summary

Adds tests for the plugin status and activation functions of wp-admin/includes/plugin.php that the ticket lists. is_plugin_active() and is_plugin_inactive() already have a test for a plugin that is active and one that is not, and activate_plugin() has its own tests, so these tests add what was missing.

isPluginActive.php

  • is_plugin_active() and is_plugin_inactive() for a listed plugin, another plugin, a plugin that is not there, the folder of a plugin, a different case, an empty string, null and true (the comparison is strict), and a plugin that is active for the network.
  • is_plugin_active_for_network(): always false on a single site, and on a network true only for the plugins that are listed.
  • is_network_only_plugin(): the Network header (true, TRUE, false, another value, none), and a full path with spaces.

activatePlugins.php

  • activate_plugins() activates several plugins, or a single plugin that is not in an array.
  • It returns a plugins_invalid error with the error of each plugin that could not be activated, keyed by plugin, and still activates the other plugins.
  • The plugin is added to the redirect URL of each plugin, and nothing is redirected without a redirect URL.
  • The $silent and $network_wide arguments are passed to activate_plugin().

Testing

vendor/bin/phpunit --filter 'Tests_Admin_Includes_Plugin_(IsPluginActive|ActivatePlugins)::'
vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Admin_Includes_Plugin_(IsPluginActive|ActivatePlugins)::'
vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin/isPluginActive.php tests/phpunit/tests/admin/includes/plugin/activatePlugins.php

Mutation check: 16 changes to is_plugin_active(), is_plugin_inactive(), is_plugin_active_for_network(), is_network_only_plugin() and activate_plugins() were each caught by a test, on single-site or on multisite (the checks that only matter on a network are caught by the multisite run).

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

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-status and bulk-activation tests.

No open issues 🎉

What changed in this PR

Adds PHPUnit coverage for plugin status checks and bulk activation in wp-admin/includes/plugin.php, extending existing tests without changing production code.

Changes:

  • Covers active and inactive plugin checks, network activation status, and network-only plugin headers.
  • Tests bulk activation success, per-plugin errors, redirects, and forwarding of silent and network-wide arguments.
  • Adds temporary plugin fixtures with teardown cleanup.
File Description
tests/​phpunit/​tests/​admin/​includes/​plugin/​isPluginActive.php Adds plugin status and network-only header tests.
tests/​phpunit/​tests/​admin/​includes/​plugin/​activatePlugins.php Adds bulk activation, error handling, redirect, and argument-forwarding tests.

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 on this, @hmbashar! Comprehensive coverage for activate_plugins(), silent activations, network activation checks, and status helpers (is_plugin_active(), is_plugin_inactive()).

The test isolation and global state restoration in tear_down() are cleanly handled, and all 96 CI matrix checks pass.

Looks ready to land!

AI Review: Gemini 3.8 Flash

@hmbashar

hmbashar commented Nov 6, 2026

Copy link
Copy Markdown
Author

A note for the review: activate_plugins() and is_network_only_plugin() already have a few tests in tests/phpunit/tests/admin/includesPlugin.php (test_activate_plugins_single_no_array, test_activate_plugins_single_array, test_is_network_only_plugin_hello, test_is_network_only_plugin). The tests in this pull request overlap with them for the activation of a plugin that is not in an array, and add the cases that were missing: the aggregated plugins_invalid error, the redirect of each plugin, the $silent and $network_wide arguments, and the Network header values.

🤖 Addressed by Claude Code

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