Repository navigation
Tests: Add unit test coverage for delete_plugins() - #14604
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.
| $slug = 'delete-test-plugin-' . ++self::$counter; | ||
| $dir = WP_PLUGIN_DIR . '/' . $slug; | ||
|
|
||
| $this->assertDirectoryDoesNotExist( $dir, 'The test plugin 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 slug comes from a counter that starts at 1 again on the next run, so this assertion fails on the same folder name. 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_path() helper in d7805bf. create_plugin_directory(), create_undeletable_plugin() and create_file() now clear a leftover path before creating it, and tear_down() uses the same helper. The class passes with leftover plugin folders, single-file plugins and undeletable folders in place.
…e_plugins() tests.
Description
Adds tests for
delete_plugins(), which deletes plugins from the Plugins screen after running their uninstall routines. The function was only reached through capability and Ajax tests.The tests create temporary plugins (and translation files) in the test data directories with the direct filesystem method, and remove anything left behind. A plugin that cannot be removed is simulated with a non-empty directory named like a single-file plugin, which a non-recursive delete cannot remove. They cover:
falsewithout plugins;delete_pluginanddeleted_pluginreceiving the plugin and the result;.po,.mo,.l10n.phpand.jsontranslation files being removed, while other plugins' translations are kept;could_not_remove_pluginerror naming one or several plugins, withdeleted_pluginreceivingfalse, while the other plugins are still deleted.Removing or changing each branch of the function makes at least one test fail. The request-credentials paths that print a form and exit are left out.
This is a test-only change; no production code is modified.
Testing Instructions
npm run test:php -- --filter Tests_Admin_Includes_Plugin_DeletePluginsnpm run test:php -- --filter Tests_Admin_Includes_Plugin_DeletePlugins -c tests/phpunit/multisite.xmlnpm run test:php -- --filter Tests_Admin_Includes_Plugin_DeletePlugins --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/deletePlugins.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.