From 429e2e5b48742b2f72d8e9d22f53d69230e15086 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Fri, 8 Mar 2024 11:29:33 +0545 Subject: [PATCH 1/2] Fix format in core check update command --- features/core-check-update.feature | 34 ++++++++++++++++++++++++++++++ src/Core_Command.php | 6 ++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/features/core-check-update.feature b/features/core-check-update.feature index 3eda2d73..626aab7e 100644 --- a/features/core-check-update.feature +++ b/features/core-check-update.feature @@ -42,3 +42,37 @@ Feature: Check for more recent versions """ 1 """ + + Scenario: Check output of check update in different formats (no updates available) + Given a WP install + And a setup.php file: + """ + updates = []; + $obj->last_checked = '1709881133'; + $obj->version_checked = $wp_version; + $obj->translations = []; + set_site_transient( 'update_core', $obj ); + """ + And I run `wp eval-file setup.php` + + When I run `wp core check-update` + Then STDOUT should be: + """ + Success: WordPress is at the latest version. + """ + + When I run `wp core check-update --format=json` + Then STDOUT should be: + """ + [] + """ + + When I run `wp core check-update --format=yaml` + Then STDOUT should be: + """ + --- + """ diff --git a/src/Core_Command.php b/src/Core_Command.php index 80139080..950f1293 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -77,16 +77,18 @@ class Core_Command extends WP_CLI_Command { * @subcommand check-update */ public function check_update( $_, $assoc_args ) { + $format = Utils\get_flag_value( $assoc_args, 'format', 'table' ); $updates = $this->get_updates( $assoc_args ); - if ( $updates ) { + + if ( $updates || 'table' !== $format ) { $updates = array_reverse( $updates ); $formatter = new Formatter( $assoc_args, [ 'version', 'update_type', 'package_url' ] ); $formatter->display_items( $updates ); - } elseif ( empty( $assoc_args['format'] ) || 'table' === $assoc_args['format'] ) { + } else { WP_CLI::success( 'WordPress is at the latest version.' ); } } From 5b50f5a8c5b4b33c4f97d60062fb1064172a7438 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Sun, 10 Mar 2024 21:01:08 +0545 Subject: [PATCH 2/2] Make last check date to very far future in core check update test --- features/core-check-update.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/core-check-update.feature b/features/core-check-update.feature index 626aab7e..91522990 100644 --- a/features/core-check-update.feature +++ b/features/core-check-update.feature @@ -52,7 +52,7 @@ Feature: Check for more recent versions $obj = new stdClass; $obj->updates = []; - $obj->last_checked = '1709881133'; + $obj->last_checked = strtotime( '1 January 2099' ); $obj->version_checked = $wp_version; $obj->translations = []; set_site_transient( 'update_core', $obj );