File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,49 @@ Feature: Manage WordPress users
136
136
3
137
137
"""
138
138
139
+ Scenario : Delete user with invalid reassign
140
+ Given a WP install
141
+ And a session_no file:
142
+ """
143
+ n
144
+ """
145
+ And a session_yes file:
146
+ """
147
+ y
148
+ """
149
+
150
+ When I run `wp user create bobjones bob@example.com --role=author --porcelain`
151
+ And save STDOUT as {BOB_ID}
152
+
153
+ When I run `wp post list --format=count`
154
+ And save STDOUT as {TOTAL_POSTS}
155
+
156
+ When I run `wp post generate --count=3 --format=ids --post_author=bobjones`
157
+ And I run `wp post list --author={BOB_ID} --format=count`
158
+ Then STDOUT should be:
159
+ """
160
+ 3
161
+ """
162
+
163
+ When I run `wp user delete bobjones < session_no`
164
+ Then STDOUT should contain:
165
+ """
166
+ --reassign parameter not passed. All associated posts will be deleted. Proceed? [y/n]
167
+ """
168
+
169
+ When I run `wp user delete bobjones --reassign=99999 < session_no`
170
+ Then STDOUT should contain:
171
+ """
172
+ --reassign parameter is invalid. All associated posts will be deleted. Proceed? [y/n]
173
+ """
174
+
175
+ When I run `wp user delete bobjones < session_yes`
176
+ And I run `wp post list --format=count`
177
+ Then STDOUT should be:
178
+ """
179
+ {TOTAL_POSTS}
180
+ """
181
+
139
182
Scenario: Deleting user from the whole network
140
183
Given a WP multisite install
141
184
Original file line number Diff line number Diff line change @@ -280,8 +280,12 @@ public function delete( $args, $assoc_args ) {
280
280
WP_CLI ::error ( 'Reassigning content to a different user is not supported on multisite. ' );
281
281
}
282
282
283
+ $ is_reassign_valid = ( $ reassign && false === get_userdata ( $ reassign ) ) ? false : true ;
284
+
283
285
if ( ! $ reassign ) {
284
286
WP_CLI ::confirm ( '--reassign parameter not passed. All associated posts will be deleted. Proceed? ' , $ assoc_args );
287
+ } elseif ( ! $ is_reassign_valid ) {
288
+ WP_CLI ::confirm ( '--reassign parameter is invalid. All associated posts will be deleted. Proceed? ' , $ assoc_args );
285
289
}
286
290
287
291
$ users = $ this ->fetcher ->get_many ( $ args );
You can’t perform that action at this time.
0 commit comments