From f30182b43d7183aa7a219fd9645c653b01b46fb5 Mon Sep 17 00:00:00 2001 From: Dave Koston Date: Tue, 10 Dec 2024 10:40:59 -0600 Subject: [PATCH] features: Add more tests for uninstall --- features/plugin-uninstall.feature | 54 +++++++++++++++++++++++++++++++ src/Plugin_Command.php | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/features/plugin-uninstall.feature b/features/plugin-uninstall.feature index bf67746f..98ef9d2e 100644 --- a/features/plugin-uninstall.feature +++ b/features/plugin-uninstall.feature @@ -11,6 +11,39 @@ Feature: Uninstall a WordPress plugin Success: Uninstalled 1 of 1 plugins. """ And the return code should be 0 + And STDERR should be empty + And the wp-content/plugins/akismet directory should not exist + + + Scenario: Uninstall an installed plugin but do not delete its files + When I run `wp plugin uninstall akismet --skip-delete` + Then STDOUT should be: + """ + Ran uninstall procedure for 'akismet' plugin without deleting. + Success: Uninstalled 1 of 1 plugins. + """ + And the return code should be 0 + And STDERR should be empty + And the wp-content/plugins/akismet directory should exist + + Scenario: Uninstall a plugin that is not in a folder and has custom name + When I run `wp plugin uninstall hello` + Then STDOUT should be: + """ + Uninstalled and deleted 'hello' plugin. + Success: Uninstalled 1 of 1 plugins. + """ + And the return code should be 0 + And STDERR should be empty + And the wp-content/plugins/hello.php file should not exist + + Scenario: Missing required inputs + When I run `wp plugin uninstall` + Then STDOUT should be: + """ + Please specify one or more plugins, or use --all. + """ + And the return code should be 1 Scenario: Attempting to uninstall a plugin that's activated When I run `wp plugin activate akismet` @@ -25,6 +58,19 @@ Feature: Uninstall a WordPress plugin And STDOUT should be empty And the return code should be 1 + Scenario: Attempting to uninstall a plugin that's activated (using --deactivate) + When I run `wp plugin activate akismet` + Then STDOUT should not be empty + + When I try `wp plugin uninstall akismet --deactivate` + Then STDOUT should be: + """ + Uninstalled and deleted 'akismet' plugin. + Success: Uninstalled 1 of 1 plugins. + """ + And STDERR should be empty + And the return code should be 0 + Scenario: Attempting to uninstall a plugin that doesn't exist When I try `wp plugin uninstall debug-bar` Then STDERR should be: @@ -43,12 +89,14 @@ Feature: Uninstall a WordPress plugin Success: Uninstalled 2 of 2 plugins. """ And the return code should be 0 + And STDERR should be empty When I run the previous command again Then STDOUT should be: """ Success: No plugins uninstalled. """ + And STDERR should be empty Scenario: Uninstall all installed plugins when one or more activated When I run `wp plugin activate --all` @@ -65,12 +113,14 @@ Feature: Uninstall a WordPress plugin Error: No plugins uninstalled. """ And the return code should be 1 + And STDOUT should be empty When I run `wp plugin uninstall --deactivate --all` Then STDOUT should contain: """ Success: Uninstalled 2 of 2 plugins. """ + And STDERR should be empty Scenario: Excluding a plugin from uninstallation when using --all switch When I try `wp plugin uninstall --all --exclude=akismet,hello` @@ -79,6 +129,7 @@ Feature: Uninstall a WordPress plugin Success: No plugins uninstalled. """ And the return code should be 0 + And STDERR should be empty Scenario: Excluding a missing plugin should not throw an error Given a WP install @@ -104,6 +155,7 @@ Feature: Uninstall a WordPress plugin """ And the wp-content/languages/plugins/wordpress-importer-fr_FR.mo file should exist And the wp-content/languages/plugins/wordpress-importer-fr_FR.po file should exist + And the wp-content/languages/plugins/wordpress-importer-fr_FR.l10n.php file should exist When I run `wp plugin uninstall wordpress-importer` Then STDOUT should contain: @@ -112,3 +164,5 @@ Feature: Uninstall a WordPress plugin """ And the wp-content/languages/plugins/wordpress-importer-fr_FR.mo file should not exist And the wp-content/languages/plugins/wordpress-importer-fr_FR.po file should not exist + And the wp-content/languages/plugins/wordpress-importer-fr_FR.l10n.php file should not exist + And STDERR should be empty diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 3c903180..ff1692b3 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -1158,7 +1158,7 @@ public function uninstall( $args, $assoc_args = array() ) { WP_CLI::log( "Uninstalled and deleted '$plugin->name' plugin." ); } else { $delete_errors[] = $plugin->file; - WP_CLI::log( "Ran uninstall procedure for '$plugin->name' plugin. Deletion failed" ); + WP_CLI::log( "Ran uninstall procedure for '$plugin->name' plugin. Deletion of plugin files failed" ); ++$errors; continue; }