Repository navigation
Tests: Add unit test coverage for validate_active_plugins() - #14608
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 the source, and CI passes. One note about fixture cleanup inline.
| parent::set_up(); | ||
|
|
||
| $dir = WP_PLUGIN_DIR . '/' . self::NO_HEADER_DIR; | ||
| $this->assertDirectoryDoesNotExist( $dir, 'The test directory should not exist yet.' ); |
There was a problem hiding this comment.
In core tests, WP_PLUGIN_DIR is tests/phpunit/data/plugins, which is a tracked directory. If a run stops partway, such as on a fatal error or Ctrl+C, tear_down() never runs and this fixture folder stays there. The folder name is fixed, so this assertion fails on the next run. So every test in the class fails here until someone deletes the folder by hand. The leftover also shows up in git status.
Could this helper, or set_up(), remove a leftover folder first? #14600 already does this: its remove_plugin() helper runs in both set_up() and tear_down().
There was a problem hiding this comment.
Good catch, thanks! Added a remove_plugin() helper that runs in both set_up() and tear_down(), in 7d99d5d. I checked it with a leftover folder in place: the old code failed and the new code passes.
…te_active_plugins() tests.
Description
Adds tests for
validate_active_plugins(), which deactivates active plugins that are missing or invalid when the Plugins screen loads, and for thevalidate_plugin()errors it reports. The existing tests only check a removed plugin being reported and the empty case.The tests use a temporary plugin file without a header and the plugins in the test data directory. They cover:
active_pluginsoption that is not an array (a string or an integer) being reset;plugin_invalid,plugin_not_foundandno_plugin_headererrors with their messages, and the invalid plugins being deactivated silently while the valid one stays active;Removing or changing each branch of the two functions makes at least one test fail on single site or multisite.
This is a test-only change; no production code is modified.
Testing Instructions
npm run test:php -- --filter Tests_Admin_Includes_Plugin_ValidateActivePluginsnpm run test:php -- --filter Tests_Admin_Includes_Plugin_ValidateActivePlugins -c tests/phpunit/multisite.xmlnpm run test:php -- --filter Tests_Admin_Includes_Plugin_ValidateActivePlugins --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/validateActivePlugins.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.