Repository navigation
Tests: Add unit test coverage for deactivate_plugins() - #14605
huzaifaalmesbah wants to merge 2 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
The assertions match deactivate_plugins(), and CI passes. One suggestion inline.
| deactivate_plugins( 'a/a.php', false, true ); | ||
|
|
||
| $this->assertSame( array( 'a/a.php', 'b/b.php', 'c.php' ), get_option( 'active_plugins' ), 'The site activation should be kept.' ); | ||
| $this->assertNotContains( 'deactivated_plugin', array_column( $this->calls, 0 ), 'The plugin should not be reported as deactivated.' ); |
There was a problem hiding this comment.
Core has a quirk on this path. With $network_wide = true and a plugin that is active only on the site, deactivate_plugins() still fires deactivate_plugin. It then hits continue before deactivate_{$plugin} and deactivated_plugin, so nothing is deactivated. This test only checks that deactivated_plugin does not fire, so the misleading first hook goes unrecorded.
Could the test assert the full list of calls instead? Then the current behavior is written down, and any change to it shows up in the test:
$this->assertSame(
array( array( 'deactivate_plugin', array( 'a/a.php', false ) ) ),
$this->calls,
'Only deactivate_plugin should fire, although the plugin stays active.'
);There was a problem hiding this comment.
Agreed, thanks! The test now asserts the full list of calls, so the deactivate_plugin call is recorded, in 90231f6.
…a site-active plugin.
Description
Adds tests for
deactivate_plugins(). The function is mostly used as cleanup in other tests; onlymultisite/network.phpchecks it, by counting thedeactivated_pluginhook for a network-active plugin. Its handling of several plugins, paths, inactive plugins and the$network_wideargument had no tests.The tests set the active plugins options directly and record the deactivation hooks. They cover:
deactivate_plugin,deactivate_{$plugin}anddeactivated_pluginfiring in order for each;true;Removing or changing each branch of the function makes at least one test fail on single site or multisite. The recovery mode branch is left out.
This is a test-only change; no production code is modified.
Testing Instructions
npm run test:php -- --filter Tests_Admin_Includes_Plugin_DeactivatePluginsnpm run test:php -- --filter Tests_Admin_Includes_Plugin_DeactivatePlugins -c tests/phpunit/multisite.xmlnpm run test:php -- --filter Tests_Admin_Includes_Plugin_DeactivatePlugins --order-by=randomnpm run test:php -- --group pluginsnode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin/deactivatePlugins.phpTrac 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.