From 805bba352a5d841a14eaa394e5ef6219ec4fe626 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Mon, 2 Feb 2026 20:22:39 +0530 Subject: [PATCH 01/11] Adds new and subcommands to the sidebar command --- features/sidebar.feature | 21 ++++++++++++ src/Sidebar_Command.php | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/features/sidebar.feature b/features/sidebar.feature index 3741e57b..f9903200 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -26,3 +26,24 @@ Feature: Manage WordPress sidebars """ 4 """ + + Scenario: Get sidebar details + Given a WP install + When I run `wp theme install twentytwelve --activate` + And I run `wp sidebar get sidebar-1` + Then STDOUT should contain: + """ + sidebar-1 + """ + + Scenario: Sidebar exists command returns success + Given a WP install + When I run `wp theme install twentytwelve --activate` + And I run `wp sidebar exists sidebar-1` + Then the return code should be 0 + + Scenario: Sidebar exists command returns failure + Given a WP install + When I run `wp theme install twentytwelve --activate` + And I try `wp sidebar exists does-not-exist` + Then the return code should be 1 \ No newline at end of file diff --git a/src/Sidebar_Command.php b/src/Sidebar_Command.php index b126b117..1128d36a 100644 --- a/src/Sidebar_Command.php +++ b/src/Sidebar_Command.php @@ -84,4 +84,74 @@ public function list_( $args, $assoc_args ) { $formatter = new Formatter( $assoc_args, $this->fields ); $formatter->display_items( $sidebars ); } + + /** + * Get details about a specific sidebar. + * + * ## OPTIONS + * + * + * : The sidebar ID. + * + * [--fields=] + * : Limit the output to specific object fields. + * + * [--format=] + * : Render output in a particular format. + * --- + * default: table + * options: + * - table + * - json + * - yaml + * --- + * + * ## EXAMPLES + * + * $ wp sidebar get sidebar-1 + * $ wp sidebar get wp_inactive_widgets --format=json + * + * @when after_wp_load + */ + public function get( $args, $assoc_args ) { + global $wp_registered_sidebars; + + Utils\wp_register_unused_sidebar(); + + $id = $args[0]; + + if ( ! isset( $wp_registered_sidebars[ $id ] ) ) { + WP_CLI::error( "Sidebar '{$id}' does not exist." ); + } + + $formatter = new Formatter( $assoc_args, $this->fields ); + $formatter->display_item( $wp_registered_sidebars[ $id ] ); + } + + /** + * Check if a sidebar exists. + * + * ## OPTIONS + * + * + * : The sidebar ID. + * + * ## EXAMPLES + * + * $ wp sidebar exists sidebar-1 + * $ wp sidebar exists wp_inactive_widgets && echo "exists" + * + * @when after_wp_load + */ + public function exists( $args ) { + global $wp_registered_sidebars; + + Utils\wp_register_unused_sidebar(); + + if ( isset( $wp_registered_sidebars[ $args[0] ] ) ) { + WP_CLI::halt( 0 ); + } + + WP_CLI::halt( 1 ); + } } From 825c1719efff94f02024401396e3b918f33e7522 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Mon, 2 Feb 2026 20:42:38 +0530 Subject: [PATCH 02/11] test(sidebar): make functional tests deterministic and CI-safe --- features/sidebar.feature | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index f9903200..15aa2657 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -2,10 +2,20 @@ Feature: Manage WordPress sidebars Scenario: List available sidebars Given a WP install - - When I try `wp theme delete twentytwelve --force` - And I run `wp theme install twentytwelve --activate` - Then STDOUT should not be empty + When I run `wp eval ' + register_sidebar([ + "id" => "sidebar-1", + "name" => "Main Sidebar" + ]); + register_sidebar([ + "id" => "sidebar-2", + "name" => "First Front Page Widget Area" + ]); + register_sidebar([ + "id" => "sidebar-3", + "name" => "Second Front Page Widget Area" + ]); + '` When I run `wp sidebar list --fields=name,id` Then STDOUT should be a table containing rows: @@ -29,7 +39,7 @@ Feature: Manage WordPress sidebars Scenario: Get sidebar details Given a WP install - When I run `wp theme install twentytwelve --activate` + When I run `wp eval 'register_sidebar(["id"=>"sidebar-1","name"=>"Test Sidebar"]);'` And I run `wp sidebar get sidebar-1` Then STDOUT should contain: """ @@ -38,12 +48,19 @@ Feature: Manage WordPress sidebars Scenario: Sidebar exists command returns success Given a WP install - When I run `wp theme install twentytwelve --activate` + When I run `wp eval 'register_sidebar(["id"=>"sidebar-1","name"=>"Test Sidebar"]);'` And I run `wp sidebar exists sidebar-1` Then the return code should be 0 Scenario: Sidebar exists command returns failure Given a WP install - When I run `wp theme install twentytwelve --activate` - And I try `wp sidebar exists does-not-exist` - Then the return code should be 1 \ No newline at end of file + When I try `wp sidebar exists does-not-exist` + Then the return code should be 1 + + Scenario: Get non-existing sidebar returns error + Given a WP install + When I try `wp sidebar get does-not-exist` + Then STDERR should contain: + """ + does not exist + """ \ No newline at end of file From 41975cd398fb25655a43e06948d6abebfdfe4681 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Mon, 2 Feb 2026 20:48:07 +0530 Subject: [PATCH 03/11] test(sidebar): fix gherkin multiline steps and make tests CI-safe --- features/sidebar.feature | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index 15aa2657..d6e3847f 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -2,20 +2,10 @@ Feature: Manage WordPress sidebars Scenario: List available sidebars Given a WP install - When I run `wp eval ' - register_sidebar([ - "id" => "sidebar-1", - "name" => "Main Sidebar" - ]); - register_sidebar([ - "id" => "sidebar-2", - "name" => "First Front Page Widget Area" - ]); - register_sidebar([ - "id" => "sidebar-3", - "name" => "Second Front Page Widget Area" - ]); - '` + + When I run `wp eval "register_sidebar(array('id'=>'sidebar-1','name'=>'Main Sidebar'))"` + And I run `wp eval "register_sidebar(array('id'=>'sidebar-2','name'=>'First Front Page Widget Area'))"` + And I run `wp eval "register_sidebar(array('id'=>'sidebar-3','name'=>'Second Front Page Widget Area'))"` When I run `wp sidebar list --fields=name,id` Then STDOUT should be a table containing rows: @@ -39,7 +29,7 @@ Feature: Manage WordPress sidebars Scenario: Get sidebar details Given a WP install - When I run `wp eval 'register_sidebar(["id"=>"sidebar-1","name"=>"Test Sidebar"]);'` + When I run `wp eval "register_sidebar(array('id'=>'sidebar-1','name'=>'Test Sidebar'))"` And I run `wp sidebar get sidebar-1` Then STDOUT should contain: """ @@ -48,7 +38,7 @@ Feature: Manage WordPress sidebars Scenario: Sidebar exists command returns success Given a WP install - When I run `wp eval 'register_sidebar(["id"=>"sidebar-1","name"=>"Test Sidebar"]);'` + When I run `wp eval "register_sidebar(array('id'=>'sidebar-1','name'=>'Test Sidebar'))"` And I run `wp sidebar exists sidebar-1` Then the return code should be 0 @@ -63,4 +53,4 @@ Feature: Manage WordPress sidebars Then STDERR should contain: """ does not exist - """ \ No newline at end of file + """ From 2d5adcb5339089ca7a79464d094ea55f92d7208c Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Mon, 2 Feb 2026 21:08:35 +0530 Subject: [PATCH 04/11] test(sidebar): make functional tests deterministic and CI-safe --- features/sidebar.feature | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index d6e3847f..fc2f5d66 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -2,10 +2,10 @@ Feature: Manage WordPress sidebars Scenario: List available sidebars Given a WP install - - When I run `wp eval "register_sidebar(array('id'=>'sidebar-1','name'=>'Main Sidebar'))"` - And I run `wp eval "register_sidebar(array('id'=>'sidebar-2','name'=>'First Front Page Widget Area'))"` - And I run `wp eval "register_sidebar(array('id'=>'sidebar-3','name'=>'Second Front Page Widget Area'))"` + When I run `wp theme install twentytwelve --activate` + + # Register sidebars for the test + And I run `wp eval 'register_sidebar(["name" => "Main Sidebar", "id" => "sidebar-1"]); register_sidebar(["name" => "First Front Page Widget Area", "id" => "sidebar-2"]); register_sidebar(["name" => "Second Front Page Widget Area", "id" => "sidebar-3"]);'` When I run `wp sidebar list --fields=name,id` Then STDOUT should be a table containing rows: @@ -28,29 +28,28 @@ Feature: Manage WordPress sidebars """ Scenario: Get sidebar details - Given a WP install - When I run `wp eval "register_sidebar(array('id'=>'sidebar-1','name'=>'Test Sidebar'))"` - And I run `wp sidebar get sidebar-1` - Then STDOUT should contain: - """ - sidebar-1 - """ + Given a WP install + When I run `wp theme install twentytwelve --activate` + And I run `wp eval 'register_sidebar(["name" => "Main Sidebar", "id" => "sidebar-1"]);'` + And I run `wp sidebar get sidebar-1` + Then STDOUT should contain "Main Sidebar" + And STDOUT should contain "sidebar-1" Scenario: Sidebar exists command returns success Given a WP install - When I run `wp eval "register_sidebar(array('id'=>'sidebar-1','name'=>'Test Sidebar'))"` + When I run `wp theme install twentytwelve --activate` + And I run `wp eval 'register_sidebar(["name" => "Main Sidebar", "id" => "sidebar-1"]);'` And I run `wp sidebar exists sidebar-1` - Then the return code should be 0 + Then the command should succeed Scenario: Sidebar exists command returns failure Given a WP install - When I try `wp sidebar exists does-not-exist` - Then the return code should be 1 + When I run `wp theme install twentytwelve --activate` + And I run `wp sidebar exists non_existing_sidebar` + Then the command should fail Scenario: Get non-existing sidebar returns error Given a WP install - When I try `wp sidebar get does-not-exist` - Then STDERR should contain: - """ - does not exist - """ + When I run `wp theme install twentytwelve --activate` + And I run `wp sidebar get non_existing_sidebar` + Then the command should fail \ No newline at end of file From 0181329b31d08d09d5056345e95f48475a8c028c Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Mon, 2 Feb 2026 21:41:56 +0530 Subject: [PATCH 05/11] test(sidebar): make functional tests deterministic and CI-safe --- features/sidebar.feature | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index fc2f5d66..63edc639 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -2,10 +2,10 @@ Feature: Manage WordPress sidebars Scenario: List available sidebars Given a WP install - When I run `wp theme install twentytwelve --activate` - - # Register sidebars for the test - And I run `wp eval 'register_sidebar(["name" => "Main Sidebar", "id" => "sidebar-1"]); register_sidebar(["name" => "First Front Page Widget Area", "id" => "sidebar-2"]); register_sidebar(["name" => "Second Front Page Widget Area", "id" => "sidebar-3"]);'` + + When I try `wp theme delete twentytwelve --force` + And I run `wp theme install twentytwelve --activate` + Then STDOUT should not be empty When I run `wp sidebar list --fields=name,id` Then STDOUT should be a table containing rows: @@ -28,28 +28,31 @@ Feature: Manage WordPress sidebars """ Scenario: Get sidebar details - Given a WP install - When I run `wp theme install twentytwelve --activate` - And I run `wp eval 'register_sidebar(["name" => "Main Sidebar", "id" => "sidebar-1"]);'` - And I run `wp sidebar get sidebar-1` - Then STDOUT should contain "Main Sidebar" - And STDOUT should contain "sidebar-1" + Given a WP install + When I run `wp theme install twentytwelve --activate` + And I run `wp sidebar get sidebar-1` + Then STDOUT should contain: + """ + sidebar-1 + """ Scenario: Sidebar exists command returns success Given a WP install When I run `wp theme install twentytwelve --activate` - And I run `wp eval 'register_sidebar(["name" => "Main Sidebar", "id" => "sidebar-1"]);'` And I run `wp sidebar exists sidebar-1` - Then the command should succeed + Then the return code should be 0 Scenario: Sidebar exists command returns failure Given a WP install When I run `wp theme install twentytwelve --activate` - And I run `wp sidebar exists non_existing_sidebar` - Then the command should fail + And I try `wp sidebar exists does-not-exist` + Then the return code should be 1 Scenario: Get non-existing sidebar returns error Given a WP install When I run `wp theme install twentytwelve --activate` - And I run `wp sidebar get non_existing_sidebar` - Then the command should fail \ No newline at end of file + And I try `wp sidebar get does-not-exist` + Then STDERR should contain: + """ + does not exist + """ \ No newline at end of file From 770b58e6a7d150cacf5bd2a07325d09de4aca5d3 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Tue, 3 Feb 2026 12:00:36 +0530 Subject: [PATCH 06/11] Checked all test and passed --- features/sidebar.feature | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index 63edc639..f2151541 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -1,12 +1,9 @@ Feature: Manage WordPress sidebars - Scenario: List available sidebars Given a WP install - - When I try `wp theme delete twentytwelve --force` - And I run `wp theme install twentytwelve --activate` - Then STDOUT should not be empty - + When I run `wp theme install twentytwelve` + And I run `wp theme activate twentytwelve` + Then the return code should be 0 When I run `wp sidebar list --fields=name,id` Then STDOUT should be a table containing rows: | name | id | @@ -14,13 +11,11 @@ Feature: Manage WordPress sidebars | First Front Page Widget Area | sidebar-2 | | Second Front Page Widget Area | sidebar-3 | | Inactive Widgets | wp_inactive_widgets | - When I run `wp sidebar list --format=ids` Then STDOUT should be: """ sidebar-1 sidebar-2 sidebar-3 wp_inactive_widgets """ - When I run `wp sidebar list --format=count` Then STDOUT should be: """ @@ -29,8 +24,10 @@ Feature: Manage WordPress sidebars Scenario: Get sidebar details Given a WP install - When I run `wp theme install twentytwelve --activate` - And I run `wp sidebar get sidebar-1` + When I run `wp theme install twentytwelve` + And I run `wp theme activate twentytwelve` + Then the return code should be 0 + When I run `wp sidebar get sidebar-1` Then STDOUT should contain: """ sidebar-1 @@ -38,21 +35,27 @@ Feature: Manage WordPress sidebars Scenario: Sidebar exists command returns success Given a WP install - When I run `wp theme install twentytwelve --activate` - And I run `wp sidebar exists sidebar-1` + When I run `wp theme install twentytwelve` + And I run `wp theme activate twentytwelve` + Then the return code should be 0 + When I run `wp sidebar exists sidebar-1` Then the return code should be 0 Scenario: Sidebar exists command returns failure Given a WP install - When I run `wp theme install twentytwelve --activate` - And I try `wp sidebar exists does-not-exist` + When I run `wp theme install twentytwelve` + And I run `wp theme activate twentytwelve` + Then the return code should be 0 + When I try `wp sidebar exists does-not-exist` Then the return code should be 1 Scenario: Get non-existing sidebar returns error Given a WP install - When I run `wp theme install twentytwelve --activate` - And I try `wp sidebar get does-not-exist` + When I run `wp theme install twentytwelve` + And I run `wp theme activate twentytwelve` + Then the return code should be 0 + When I try `wp sidebar get does-not-exist` Then STDERR should contain: """ does not exist - """ \ No newline at end of file + """ From 530c09a431d5f9c20565fbb182be8444b240ad80 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Tue, 3 Feb 2026 12:36:17 +0530 Subject: [PATCH 07/11] Updated sidebar feature with background process --- features/sidebar.feature | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index f2151541..fa85be0f 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -1,9 +1,10 @@ Feature: Manage WordPress sidebars - Scenario: List available sidebars + Background: Given a WP install - When I run `wp theme install twentytwelve` - And I run `wp theme activate twentytwelve` - Then the return code should be 0 + And I try `wp theme delete twentytwelve --force` + And I run `wp theme install twentytwelve --activate` + + Scenario: List available sidebars When I run `wp sidebar list --fields=name,id` Then STDOUT should be a table containing rows: | name | id | @@ -23,10 +24,6 @@ Feature: Manage WordPress sidebars """ Scenario: Get sidebar details - Given a WP install - When I run `wp theme install twentytwelve` - And I run `wp theme activate twentytwelve` - Then the return code should be 0 When I run `wp sidebar get sidebar-1` Then STDOUT should contain: """ @@ -34,26 +31,14 @@ Feature: Manage WordPress sidebars """ Scenario: Sidebar exists command returns success - Given a WP install - When I run `wp theme install twentytwelve` - And I run `wp theme activate twentytwelve` - Then the return code should be 0 When I run `wp sidebar exists sidebar-1` Then the return code should be 0 Scenario: Sidebar exists command returns failure - Given a WP install - When I run `wp theme install twentytwelve` - And I run `wp theme activate twentytwelve` - Then the return code should be 0 When I try `wp sidebar exists does-not-exist` Then the return code should be 1 Scenario: Get non-existing sidebar returns error - Given a WP install - When I run `wp theme install twentytwelve` - And I run `wp theme activate twentytwelve` - Then the return code should be 0 When I try `wp sidebar get does-not-exist` Then STDERR should contain: """ From 06bd4b16fa4f9d4c047c93e0c6f04eaa5a0ae947 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Tue, 10 Feb 2026 15:09:17 +0530 Subject: [PATCH 08/11] Update src/Sidebar_Command.php Updated list of format Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Sidebar_Command.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Sidebar_Command.php b/src/Sidebar_Command.php index 1128d36a..0734cdee 100644 --- a/src/Sidebar_Command.php +++ b/src/Sidebar_Command.php @@ -102,7 +102,10 @@ public function list_( $args, $assoc_args ) { * default: table * options: * - table + * - csv * - json + * - ids + * - count * - yaml * --- * From 46cdb3d734640818fae81472eda6662239ec7ee0 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Tue, 10 Feb 2026 20:34:28 +0530 Subject: [PATCH 09/11] Updated last scenario in sidebar feature file and updated list of format, array condtion in sidebar command file --- features/sidebar.feature | 1 + src/Sidebar_Command.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index fa85be0f..0e5c69df 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -44,3 +44,4 @@ Feature: Manage WordPress sidebars """ does not exist """ + And the return code should be 1 \ No newline at end of file diff --git a/src/Sidebar_Command.php b/src/Sidebar_Command.php index 1128d36a..03a15b73 100644 --- a/src/Sidebar_Command.php +++ b/src/Sidebar_Command.php @@ -102,7 +102,10 @@ public function list_( $args, $assoc_args ) { * default: table * options: * - table + * - csv * - json + * - ids + * - count * - yaml * --- * @@ -120,7 +123,7 @@ public function get( $args, $assoc_args ) { $id = $args[0]; - if ( ! isset( $wp_registered_sidebars[ $id ] ) ) { + if ( ! array_key_exists( $id, $wp_registered_sidebars ) ) { WP_CLI::error( "Sidebar '{$id}' does not exist." ); } @@ -148,7 +151,7 @@ public function exists( $args ) { Utils\wp_register_unused_sidebar(); - if ( isset( $wp_registered_sidebars[ $args[0] ] ) ) { + if ( array_key_exists( $args[0], $wp_registered_sidebars ) ) { WP_CLI::halt( 0 ); } From 8c3a208cea0e0836eb39f320d8fe337ebec24db6 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Tue, 10 Feb 2026 20:38:11 +0530 Subject: [PATCH 10/11] Updated last scenario in sidebar feature file and updated list of format, array condtion in sidebar command file --- features/sidebar.feature | 3 ++- src/Sidebar_Command.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/features/sidebar.feature b/features/sidebar.feature index 0e5c69df..5e5d4315 100644 --- a/features/sidebar.feature +++ b/features/sidebar.feature @@ -44,4 +44,5 @@ Feature: Manage WordPress sidebars """ does not exist """ - And the return code should be 1 \ No newline at end of file + And the return code should be 1 + \ No newline at end of file diff --git a/src/Sidebar_Command.php b/src/Sidebar_Command.php index 03a15b73..126294ed 100644 --- a/src/Sidebar_Command.php +++ b/src/Sidebar_Command.php @@ -157,4 +157,4 @@ public function exists( $args ) { WP_CLI::halt( 1 ); } -} +} \ No newline at end of file From 4e8ec50becbf77d44da671353cdb5aaeaba31b31 Mon Sep 17 00:00:00 2001 From: Sohilbhai Ghanchivahora Date: Tue, 10 Feb 2026 20:42:28 +0530 Subject: [PATCH 11/11] Added new line at the end --- src/Sidebar_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sidebar_Command.php b/src/Sidebar_Command.php index 126294ed..03a15b73 100644 --- a/src/Sidebar_Command.php +++ b/src/Sidebar_Command.php @@ -157,4 +157,4 @@ public function exists( $args ) { WP_CLI::halt( 1 ); } -} \ No newline at end of file +}