Skip to content

Commit

Permalink
Switch tests to use site-secrets instead of user-switching (#389)
Browse files Browse the repository at this point in the history
* Switch tests to use `site-secrets` instead of `user-switching`

User Switching increased its minimum supported PHP version, and started
breaking our tests. Time to use Daniel's plugin instead! Sorry John.

* Remove unused variable to fix PHPCS warning

* Drop Jetpack because it fails tests

* Update command description
  • Loading branch information
danielbachhuber authored Dec 8, 2023
1 parent 7118325 commit 506a20a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions features/plugin-activate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Feature: Activate WordPress plugins
And the return code should be 1

Scenario: Activate all when one plugin is hidden by "all_plugins" filter
Given I run `wp plugin install user-switching`
Given I run `wp plugin install site-secrets`
And a wp-content/mu-plugins/hide-us-plugin.php file:
"""
<?php
Expand All @@ -46,7 +46,7 @@ Feature: Activate WordPress plugins
*/
add_filter( 'all_plugins', function( $all_plugins ) {
unset( $all_plugins['user-switching/user-switching.php'] );
unset( $all_plugins['site-secrets/site-secrets.php'] );
return $all_plugins;
} );
"""
Expand All @@ -59,7 +59,7 @@ Feature: Activate WordPress plugins
"""
And STDOUT should not contain:
"""
Plugin 'user-switching' activated.
Plugin 'site-secrets' activated.
"""

@require-php-7
Expand Down
24 changes: 12 additions & 12 deletions features/plugin-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -113,48 +113,48 @@ Feature: Install WordPress plugins
Scenario: Return code is 1 when one or more plugin installations fail
Given a WP install

When I try `wp plugin install user-switching user-switching-not-a-plugin`
When I try `wp plugin install site-secrets site-secrets-not-a-plugin`
Then STDERR should contain:
"""
Warning:
"""
And STDERR should contain:
"""
user-switching-not-a-plugin
site-secrets-not-a-plugin
"""
And STDERR should contain:
"""
Error: Only installed 1 of 2 plugins.
"""
And STDOUT should contain:
"""
Installing User Switching
Installing Site Secrets
"""
And STDOUT should contain:
"""
Plugin installed successfully.
"""
And the return code should be 1

When I try `wp plugin install user-switching`
When I try `wp plugin install site-secrets`
Then STDOUT should be:
"""
Success: Plugin already installed.
"""
And STDERR should be:
"""
Warning: user-switching: Plugin already installed.
Warning: site-secrets: Plugin already installed.
"""
And the return code should be 0

When I try `wp plugin install user-switching-not-a-plugin`
When I try `wp plugin install site-secrets-not-a-plugin`
Then STDERR should contain:
"""
Warning:
"""
And STDERR should contain:
"""
user-switching-not-a-plugin
site-secrets-not-a-plugin
"""
And STDERR should contain:
"""
Expand Down Expand Up @@ -222,18 +222,18 @@ Feature: Install WordPress plugins
Scenario: Verify installed plugin activation
Given a WP install

When I run `wp plugin install user-switching`
When I run `wp plugin install site-secrets`
Then STDOUT should not be empty

When I try `wp plugin install user-switching --activate`
When I try `wp plugin install site-secrets --activate`
Then STDERR should contain:
"""
Warning: user-switching: Plugin already installed.
Warning: site-secrets: Plugin already installed.
"""

And STDOUT should contain:
"""
Activating 'user-switching'...
Plugin 'user-switching' activated.
Activating 'site-secrets'...
Plugin 'site-secrets' activated.
Success: Plugin already installed.
"""
11 changes: 5 additions & 6 deletions features/plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -579,28 +579,27 @@ Feature: Manage WordPress plugins
And these installed and active plugins:
"""
akismet
jetpack
user-switching
site-secrets
"""
And a wp-content/mu-plugins/hide-us-plugin.php file:
"""
<?php
/**
* Plugin Name: Hide User Switchign on Production
* Description: Hides the User Switching plugin on production sites
* Plugin Name: Hide Site Secrets on Production
* Description: Hides the Site Secrets plugin on production sites
* Author: WP-CLI tests
*/
add_filter( 'all_plugins', function( $all_plugins ) {
unset( $all_plugins['user-switching/user-switching.php'] );
unset( $all_plugins['site-secrets/site-secrets.php'] );
return $all_plugins;
} );
"""

When I run `wp plugin list --fields=name`
Then STDOUT should not contain:
"""
user-switching
site-secrets
"""

Scenario: Show dropins plugin list
Expand Down
4 changes: 2 additions & 2 deletions src/WP_CLI/CommandWithUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function install( $args, $assoc_args ) {
// Don't attempt to rename ZIPs uploaded to the releases page or coming from a raw source.
&& ! preg_match( '#github\.com/[^/]+/[^/]+/(?:releases/download|raw)/#', $slug ) ) {

$filter = function ( $source, $remote_source, $upgrader ) use ( $slug ) {
$filter = function ( $source ) use ( $slug ) {

$slug_dir = Utils\basename( $this->parse_url_host_component( $slug, PHP_URL_PATH ), '.zip' );

Expand All @@ -193,7 +193,7 @@ public function install( $args, $assoc_args ) {

return new WP_Error( 'wpcli_install_github', "Couldn't move Github-based project to appropriate directory." );
};
add_filter( 'upgrader_source_selection', $filter, 10, 3 );
add_filter( 'upgrader_source_selection', $filter, 10 );
}

if ( $file_upgrader->install( $slug ) ) {
Expand Down

0 comments on commit 506a20a

Please sign in to comment.