Skip to content

Commit

Permalink
features: Add more tests for uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoston committed Dec 10, 2024
1 parent 60d9786 commit f30182b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions features/plugin-uninstall.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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:
Expand All @@ -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`
Expand 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`
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f30182b

Please sign in to comment.