Skip to content

Commit 0854b02

Browse files
Copilotswissspidy
andcommitted
Address open review comments: add debug logging for range expansions and feature tests for site, comment, user range operations
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent baac6f0 commit 0854b02

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

features/comment.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,24 @@ Feature: Manage WordPress comments
501501
"""
502502
Deleted comment {COMMENT_ID_3}.
503503
"""
504+
505+
Scenario: Trash comments using ID ranges
506+
Given a WP install
507+
508+
When I run `wp comment create --comment_post_ID=1 --comment_content='Comment D' --comment_author='D' --porcelain`
509+
Then STDOUT should be a number
510+
And save STDOUT as {COMMENT_ID_1}
511+
512+
When I run `wp comment create --comment_post_ID=1 --comment_content='Comment E' --comment_author='E' --porcelain`
513+
Then STDOUT should be a number
514+
And save STDOUT as {COMMENT_ID_2}
515+
516+
When I run `wp comment trash {COMMENT_ID_1}-{COMMENT_ID_2}`
517+
Then STDOUT should contain:
518+
"""
519+
Trashed comment {COMMENT_ID_1}.
520+
"""
521+
And STDOUT should contain:
522+
"""
523+
Trashed comment {COMMENT_ID_2}.
524+
"""

features/site.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,3 +891,26 @@ Feature: Manage sites in a multisite installation
891891
"""
892892
1
893893
"""
894+
895+
Scenario: Archive sites using ID ranges
896+
Given a WP multisite install
897+
And I run `wp site create --slug=rangesite1 --porcelain`
898+
And save STDOUT as {SITE_ID_1}
899+
And I run `wp site create --slug=rangesite2 --porcelain`
900+
And save STDOUT as {SITE_ID_2}
901+
And I run `wp site create --slug=rangesite3 --porcelain`
902+
And save STDOUT as {SITE_ID_3}
903+
904+
When I run `wp site archive {SITE_ID_1}-{SITE_ID_3}`
905+
Then STDOUT should contain:
906+
"""
907+
Success: Site {SITE_ID_1} archived.
908+
"""
909+
And STDOUT should contain:
910+
"""
911+
Success: Site {SITE_ID_2} archived.
912+
"""
913+
And STDOUT should contain:
914+
"""
915+
Success: Site {SITE_ID_3} archived.
916+
"""

features/user.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,28 @@ Feature: Manage WordPress users
803803
"""
804804
Removed user {USER_ID_3}
805805
"""
806+
807+
Scenario: Reset passwords using ID ranges
808+
Given a WP install
809+
810+
When I run `wp user create resetrange1 resetrange1@example.com --role=subscriber --porcelain`
811+
Then STDOUT should be a number
812+
And save STDOUT as {USER_ID_1}
813+
814+
When I run `wp user create resetrange2 resetrange2@example.com --role=subscriber --porcelain`
815+
Then STDOUT should be a number
816+
And save STDOUT as {USER_ID_2}
817+
818+
When I run `wp user reset-password {USER_ID_1}-{USER_ID_2} --skip-email`
819+
Then STDOUT should contain:
820+
"""
821+
Reset password for resetrange1.
822+
"""
823+
And STDOUT should contain:
824+
"""
825+
Reset password for resetrange2.
826+
"""
827+
And STDOUT should contain:
828+
"""
829+
Passwords reset for 2 users.
830+
"""

src/WP_CLI/ExpandsIdRanges.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace WP_CLI;
44

5+
use WP_CLI;
6+
57
/**
68
* Trait that provides ID range expansion for WP-CLI commands.
79
*
@@ -39,13 +41,19 @@ protected static function expand_id_ranges( array $args, callable $get_ids_in_ra
3941
$start = $end;
4042
$end = $temp;
4143
}
42-
$ids = array_merge( $ids, $get_ids_in_range( $start, $end ) );
44+
$range_ids = $get_ids_in_range( $start, $end );
45+
WP_CLI::debug( sprintf( "Expanded range '%s' to %d IDs.", $arg, count( $range_ids ) ), 'range-expansion' );
46+
$ids = array_merge( $ids, $range_ids );
4347
} elseif ( preg_match( '/^(\d+)-$/', $arg, $matches ) ) {
4448
// Open-ended range: "34-"
45-
$ids = array_merge( $ids, $get_ids_in_range( (int) $matches[1], null ) );
49+
$range_ids = $get_ids_in_range( (int) $matches[1], null );
50+
WP_CLI::debug( sprintf( "Expanded range '%s' to %d IDs.", $arg, count( $range_ids ) ), 'range-expansion' );
51+
$ids = array_merge( $ids, $range_ids );
4652
} elseif ( preg_match( '/^-(\d+)$/', $arg, $matches ) ) {
4753
// Lower-bounded range: "-35"
48-
$ids = array_merge( $ids, $get_ids_in_range( 1, (int) $matches[1] ) );
54+
$range_ids = $get_ids_in_range( 1, (int) $matches[1] );
55+
WP_CLI::debug( sprintf( "Expanded range '%s' to %d IDs.", $arg, count( $range_ids ) ), 'range-expansion' );
56+
$ids = array_merge( $ids, $range_ids );
4957
} else {
5058
$ids[] = $arg;
5159
}

0 commit comments

Comments
 (0)