Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"plugin path",
"plugin search",
"plugin status",
"plugin check-update",
"plugin toggle",
"plugin uninstall",
"plugin update",
Expand All @@ -76,6 +77,7 @@
"theme path",
"theme search",
"theme status",
"theme check-update",
"theme update",
"theme mod list"
]
Expand Down
101 changes: 101 additions & 0 deletions features/plugin-check-update.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Feature: Check for plugin updates

@require-wp-5.2
Scenario: Check for plugin updates with no updates available
Given a WP install

When I run `wp plugin install wordpress-importer --activate`
Then STDOUT should not be empty

When I run `wp plugin check-update --all`
Then STDOUT should contain:
"""
Success: All plugins are up to date.
"""

When I run `wp plugin check-update wordpress-importer`
Then STDOUT should contain:
"""
Success: All plugins are up to date.
"""

Scenario: Check for plugin updates should throw an error unless --all given
Given a WP install

When I try `wp plugin check-update`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more plugins, or use --all.
"""
And STDOUT should be empty

@require-wp-5.2
Scenario: Check for specific plugin updates
Given a WP install

When I run `wp plugin install wordpress-importer --version=0.5`
Then STDOUT should not be empty

When I run `wp plugin check-update wordpress-importer --format=csv`
Then STDOUT should contain:
"""
wordpress-importer,inactive,0.5,
"""

@require-wp-5.2
Scenario: Check for all plugin updates with --all flag
Given a WP install

When I run `wp plugin install wordpress-importer --version=0.5 --activate`
Then STDOUT should not be empty

When I run `wp plugin check-update --all --format=csv`
Then STDOUT should contain:
"""
wordpress-importer,active,0.5,
"""

@require-wp-5.2
Scenario: Check for plugin updates in different output formats
Given a WP install

When I run `wp plugin install wordpress-importer --version=0.5`
Then STDOUT should not be empty

When I run `wp plugin check-update wordpress-importer --format=json`
Then STDOUT should be JSON containing:
"""
[{"name":"wordpress-importer","status":"inactive","version":"0.5"}]
"""

When I run `wp plugin check-update wordpress-importer --format=csv`
Then STDOUT should contain:
"""
name,status,version,update_version
"""
And STDOUT should contain:
"""
wordpress-importer,inactive,0.5
"""

@require-wp-5.2
Scenario: Check for plugin updates with custom fields
Given a WP install

When I run `wp plugin install wordpress-importer --version=0.5`
Then STDOUT should not be empty

When I run `wp plugin check-update wordpress-importer --fields=name,version`
Then STDOUT should be a table containing rows:
| name | version |
| wordpress-importer | 0.5 |

Scenario: Check for invalid plugin should error
Given a WP install

When I try `wp plugin check-update invalid-plugin-name`
Then STDERR should contain:
"""
Warning: The 'invalid-plugin-name' plugin could not be found.
"""
98 changes: 98 additions & 0 deletions features/theme-check-update.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Feature: Check for theme updates

Scenario: Check for theme updates with no updates available
Given a WP install

When I run `wp theme install twentytwelve --force`
And I run `wp theme update --all`
And I run `wp theme check-update --all`
Then STDOUT should contain:
"""
Success: All themes are up to date.
"""

When I run `wp theme check-update twentytwelve`
Then STDOUT should contain:
"""
Success: All themes are up to date.
"""

Scenario: Check for theme updates should throw an error unless --all given
Given a WP install

When I try `wp theme check-update`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more themes, or use --all.
"""
And STDOUT should be empty

Scenario: Check for specific theme updates
Given a WP install

When I run `wp theme install twentyfourteen --version=1.0 --force`
Then STDOUT should not be empty

When I run `wp theme install twentytwelve --force`
Then STDOUT should not be empty

When I run `wp theme check-update twentyfourteen --format=csv`
Then STDOUT should contain:
"""
twentyfourteen,inactive,1.0,
"""

Scenario: Check for all theme updates with --all flag
Given a WP install

When I run `wp theme install twentyfourteen --version=1.0 --force`
Then STDOUT should not be empty

When I run `wp theme check-update --all --format=csv`
Then STDOUT should contain:
"""
twentyfourteen,inactive,1.0,
"""

Scenario: Check for theme updates in different output formats
Given a WP install

When I run `wp theme install twentyfourteen --version=1.0 --force`
Then STDOUT should not be empty

When I run `wp theme check-update twentyfourteen --format=json`
Then STDOUT should be JSON containing:
"""
[{"name":"twentyfourteen","status":"inactive","version":"1.0"}]
"""

When I run `wp theme check-update twentyfourteen --format=csv`
Then STDOUT should contain:
"""
name,status,version,update_version
"""
And STDOUT should contain:
"""
twentyfourteen,inactive,1.0
"""

Scenario: Check for theme updates with custom fields
Given a WP install

When I run `wp theme install twentyfourteen --version=1.0 --force`
Then STDOUT should not be empty

When I run `wp theme check-update twentyfourteen --fields=name,version`
Then STDOUT should be a table containing rows:
| name | version |
| twentyfourteen | 1.0 |

Scenario: Check for invalid theme should error
Given a WP install

When I try `wp theme check-update invalid-theme-name`
Then STDERR should contain:
"""
Warning: The 'invalid-theme-name' theme could not be found.
"""
94 changes: 94 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,100 @@ public function status( $args ) {
parent::status( $args );
}

/**
* Checks for plugin updates without performing them.
*
* Lists the available plugin updates. Similar to `wp core check-update`.
*
* ## OPTIONS
*
* [<plugin>...]
* : One or more plugins to check for updates.
*
* [--all]
* : If set, all plugins will be checked for updates.
*
* [--field=<field>]
* : Prints the value of a single field for each update.
*
* [--fields=<fields>]
* : Limit the output to specific object fields. Defaults to name,status,version,update_version.
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - csv
* - json
* - yaml
* ---
*
* ## EXAMPLES
*
* # Check for plugin updates
* $ wp plugin check-update
* +-----------+--------+---------+----------------+
* | name | status | version | update_version |
* +-----------+--------+---------+----------------+
* | akismet | active | 4.1.0 | 4.1.1 |
* +-----------+--------+---------+----------------+
*
* # List plugins with available updates in JSON format
* $ wp plugin check-update --format=json
* [{"name":"akismet","status":"active","version":"4.1.0","update_version":"4.1.1"}]
*
* @subcommand check-update
*/
public function check_update( $args, $assoc_args ) {
$all = Utils\get_flag_value( $assoc_args, 'all', false );

$args = $this->check_optional_args_and_all( $args, $all );
if ( ! $args ) {
return;
}

// Force WordPress to check for updates.
call_user_func( $this->upgrade_refresh );

if ( $all ) {
// Get all plugins
$items = $this->get_item_list();
} else {
// Get specific plugins and their update info
$plugins = $this->fetcher->get_many( $args );
$all_items = $this->get_item_list();
$items = [];
foreach ( $plugins as $plugin ) {
if ( isset( $all_items[ $plugin->file ] ) ) {
$items[ $plugin->file ] = $all_items[ $plugin->file ];
}
}
}

// Filter to only plugins with available updates
$items_with_updates = array_filter(
$items,
function ( $item ) {
return 'available' === $item['update'];
}
);

if ( empty( $items_with_updates ) ) {
WP_CLI::success( 'All plugins are up to date.' );
return;
}

// Set default fields for check-update output
if ( ! isset( $assoc_args['fields'] ) ) {
$assoc_args['fields'] = 'name,status,version,update_version';
}

$formatter = $this->get_formatter( $assoc_args );
$formatter->display_items( array_values( $items_with_updates ) );
}

/**
* Searches the WordPress.org plugin directory.
*
Expand Down
Loading