diff --git a/features/plugin-list.feature b/features/plugin-list.feature new file mode 100644 index 00000000..d8a680db --- /dev/null +++ b/features/plugin-list.feature @@ -0,0 +1,64 @@ +Feature: List WordPress plugins + + Scenario: Refresh update_plugins transient when listing plugins with --force-check flag + Given a WP install + And I run `wp plugin uninstall --all` + And I run `wp plugin install hello-dolly` + And a update-transient.php file: + """ + response['hello-dolly/hello.php'] = (object) array( + 'id' => 'w.org/plugins/hello-dolly', + 'slug' => 'hello-dolly', + 'plugin' => 'hello-dolly/hello.php', + 'new_version' => '100.0.0', + 'url' => 'https://wordpress.org/plugins/hello-dolly/', + 'package' => 'https://downloads.wordpress.org/plugin/hello-dolly.100.0.0.zip', + ); + $transient->checked = array( + 'hello-dolly/hello.php' => '1.7.2', + ); + unset( $transient->no_update['hello-dolly/hello.php'] ); + set_site_transient( 'update_plugins', $transient ); + WP_CLI::success( 'Transient updated.' ); + """ + + # Populates the initial transient in the database + When I run `wp plugin list --fields=name,status,update` + Then STDOUT should be a table containing rows: + | name | status | update | + | hello-dolly | inactive | none | + + # Modify the transient in the database to simulate an update + When I run `wp eval-file update-transient.php` + Then STDOUT should be: + """ + Success: Transient updated. + """ + + # Verify the fake transient value produces the expected output + When I run `wp plugin list --fields=name,status,update` + Then STDOUT should be a table containing rows: + | name | status | update | + | hello-dolly | inactive | available | + + # Repeating the same command again should produce the same results + When I run the previous command again + Then STDOUT should be a table containing rows: + | name | status | update | + | hello-dolly | inactive | available | + + # Using the --force-check flag should refresh the transient back to the original value + When I run `wp plugin list --fields=name,status,update --force-check` + Then STDOUT should be a table containing rows: + | name | status | update | + | hello-dolly | inactive | none | + + When I try `wp plugin list --skip-update-check --force-check` + Then STDERR should contain: + """ + Error: Plugin updates cannot be both force-checked and skipped. Choose one. + """ + And STDOUT should be empty + And the return code should be 1 diff --git a/features/theme-list.feature b/features/theme-list.feature new file mode 100644 index 00000000..b9aec2f6 --- /dev/null +++ b/features/theme-list.feature @@ -0,0 +1,62 @@ +Feature: List WordPress themes + + Scenario: Refresh update_themes transient when listing themes with --force-check flag + Given a WP install + And I run `wp theme delete --all --force` + And I run `wp theme install --force twentytwelve --version=4.2` + And a update-transient.php file: + """ + response['twentytwelve'] = (object) array( + 'theme' => 'twentytwelve', + 'new_version' => '100.0.0', + 'url' => 'https://wordpress.org/themes/twentytwelve/', + 'package' => 'https://downloads.wordpress.org/theme/twentytwelve.100.zip' + ); + $transient->checked = array( + 'twentytwelve' => '4.2', + ); + unset( $transient->no_update['twentytwelve'] ); + set_site_transient( 'update_themes', $transient ); + WP_CLI::success( 'Transient updated.' ); + """ + + # Populates the initial transient in the database + When I run `wp theme list --fields=name,update` + Then STDOUT should be a table containing rows: + | name | update | + | twentytwelve | none | + + # Modify the transient in the database to simulate an update + When I run `wp eval-file update-transient.php` + Then STDOUT should be: + """ + Success: Transient updated. + """ + + # Verify the fake transient value produces the expected output + When I run `wp theme list --fields=name,update` + Then STDOUT should be a table containing rows: + | name | update | + | twentytwelve | available | + + # Repeating the same command again should produce the same results + When I run the previous command again + Then STDOUT should be a table containing rows: + | name | update | + | twentytwelve | available | + + # Using the --force-check flag should refresh the transient back to the original value + When I run `wp theme list --fields=name,update --force-check` + Then STDOUT should be a table containing rows: + | name | update | + | twentytwelve | none | + + When I try `wp theme list --skip-update-check --force-check` + Then STDERR should contain: + """ + Error: Theme updates cannot be both force-checked and skipped. Choose one. + """ + And STDOUT should be empty + And the return code should be 1 diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 935d4b44..a6d1ba32 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -1325,6 +1325,9 @@ public function delete( $args, $assoc_args = array() ) { * [--skip-update-check] * : If set, the plugin update check will be skipped. * + * [--force-check] + * : Bypass the transient cache and force a fresh update check. + * * [--recently-active] * : If set, only recently active plugins will be shown and the status filter will be ignored. * diff --git a/src/Theme_Command.php b/src/Theme_Command.php index 19bf71b0..eb2862a6 100644 --- a/src/Theme_Command.php +++ b/src/Theme_Command.php @@ -857,6 +857,9 @@ public function delete( $args, $assoc_args ) { * [--skip-update-check] * : If set, the theme update check will be skipped. * + * [--force-check] + * : Bypass the transient cache and force a fresh update check. + * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each theme: diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index d925aeb2..4642704e 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -532,6 +532,16 @@ static function ( $result ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore -- Whitelisting to provide backward compatibility to classes possibly extending this class. protected function _list( $_, $assoc_args ) { + // If `--force-check` and `--skip-update-check` flags are both present, abort. + if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) && true === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) { + WP_CLI::error( ucfirst( "{$this->item_type} updates cannot be both force-checked and skipped. Choose one." ) ); + } + + // If `--force-check` flag is present, delete the upgrade transient. + if ( true === (bool) Utils\get_flag_value( $assoc_args, 'force-check', false ) ) { + delete_site_transient( $this->upgrade_transient ); + } + // Force WordPress to check for updates if `--skip-update-check` is not passed. if ( false === (bool) Utils\get_flag_value( $assoc_args, 'skip-update-check', false ) ) { call_user_func( $this->upgrade_refresh );