Skip to content

Commit e37fa1a

Browse files
committed
Fix test breakages run -> try; comment_post_ID non-null; @rmdir on empty.
1 parent f5973ee commit e37fa1a

File tree

6 files changed

+80
-18
lines changed

6 files changed

+80
-18
lines changed

features/option.feature

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Feature: Manage WordPress options
4848
When I run `wp option add auto_opt --autoload=no 'bar'`
4949
Then STDOUT should not be empty
5050

51-
When I run `wp option list --search='auto_opt' --autoload`
51+
When I run `wp option list --search='auto_opt' --autoload=off`
5252
Then STDOUT should not be empty
5353

5454
When I run `wp option list | grep -q "str_opt"`
@@ -65,6 +65,7 @@ Feature: Manage WordPress options
6565

6666
When I try `wp option get str_opt`
6767
Then the return code should be 1
68+
And STDERR should be empty
6869

6970
# Integer values
7071
When I run `wp option update blog_public 1`
@@ -216,3 +217,40 @@ Feature: Manage WordPress options
216217
"""
217218
Success: Value passed for 'home' option is unchanged.
218219
"""
220+
221+
Scenario: Bad values for autoload
222+
Given a WP install
223+
When I run `wp option add str_opt 'bar'`
224+
Then STDOUT should not be empty
225+
226+
When I try `wp option list --search='auto_opt' --autoload`
227+
Then STDOUT should not be empty
228+
And STDERR should be:
229+
"""
230+
Warning: --autoload parameter needs a value
231+
"""
232+
And the return code should be 0
233+
234+
When I try `wp option list --search='auto_opt' --autoload=no`
235+
Then STDOUT should be empty
236+
And STDERR should be:
237+
"""
238+
Error: Value of '--autoload' should be on or off.
239+
"""
240+
And the return code should be 1
241+
242+
When I try `wp option add str_opt_foo 'bar' --autoload`
243+
Then STDOUT should not be empty
244+
And STDERR should be:
245+
"""
246+
Warning: --autoload parameter needs a value
247+
"""
248+
And the return code should be 0
249+
250+
When I try `wp option add str_opt_foo 'bar' --autoload=off`
251+
Then STDOUT should be empty
252+
And STDERR should contain:
253+
"""
254+
Error: Parameter errors:
255+
"""
256+
And the return code should be 1

features/site-create.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Feature: Create a new site on a WP multisite
2222
Success: Generated 'wp-config.php' file.
2323
"""
2424
25-
When I run `wp core multisite-install --url=localhost/dev/ --title=Test --admin_user=admin [email protected]`
25+
# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
26+
When I try `wp core multisite-install --url=localhost/dev/ --title=Test --admin_user=admin [email protected]`
2627
Then STDOUT should contain:
2728
"""
2829
Success: Network installed. Don't forget to set up rewrite rules
2930
"""
31+
And the return code should be 0
3032
3133
When I run `wp site list --fields=blog_id,url`
3234
Then STDOUT should be a table containing rows:

features/site.feature

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Feature: Manage sites in a multisite installation
88
"""
99
Network with id 1000 does not exist.
1010
"""
11+
And STDOUT should be empty
12+
And the return code should be 1
1113

1214
Scenario: Create a subdomain site
1315
Given a WP multisite subdomain install
@@ -61,6 +63,7 @@ Feature: Manage sites in a multisite installation
6163
"""
6264
Error: You cannot delete the root site.
6365
"""
66+
And STDOUT should be empty
6467
And the return code should be 1
6568

6669
When I run `wp site delete {SITE_ID} --yes`
@@ -151,7 +154,7 @@ Feature: Manage sites in a multisite installation
151154
| blog_id | archived |
152155
| {FIRST_SITE} | 1 |
153156

154-
When I run `wp site archive {FIRST_SITE} {SECOND_SITE}`
157+
When I try `wp site archive {FIRST_SITE} {SECOND_SITE}`
155158
Then STDERR should be:
156159
"""
157160
Warning: Site {FIRST_SITE} already archived.
@@ -160,6 +163,7 @@ Feature: Manage sites in a multisite installation
160163
"""
161164
Success: Site {SECOND_SITE} archived.
162165
"""
166+
And the return code should be 0
163167

164168
When I run `wp site list --fields=blog_id,archived`
165169
Then STDOUT should be a table containing rows:
@@ -172,7 +176,7 @@ Feature: Manage sites in a multisite installation
172176
Success: Site {FIRST_SITE} unarchived.
173177
"""
174178

175-
When I run `wp site list --fields=blog_id,archived`
179+
When I try `wp site list --fields=blog_id,archived`
176180
Then STDOUT should be a table containing rows:
177181
| blog_id | archived |
178182
| {FIRST_SITE} | 0 |
@@ -182,6 +186,8 @@ Feature: Manage sites in a multisite installation
182186
"""
183187
Warning: You are not allowed to change the main site.
184188
"""
189+
And STDOUT should be empty
190+
And the return code should be 0
185191

186192
Scenario: Activate/deactivate a site
187193
Given a WP multisite install
@@ -201,7 +207,7 @@ Feature: Manage sites in a multisite installation
201207
| blog_id | deleted |
202208
| {FIRST_SITE} | 1 |
203209

204-
When I run `wp site deactivate {FIRST_SITE} {SECOND_SITE}`
210+
When I try `wp site deactivate {FIRST_SITE} {SECOND_SITE}`
205211
Then STDERR should be:
206212
"""
207213
Warning: Site {FIRST_SITE} already deactivated.
@@ -210,6 +216,7 @@ Feature: Manage sites in a multisite installation
210216
"""
211217
Success: Site {SECOND_SITE} deactivated.
212218
"""
219+
And the return code should be 0
213220

214221
When I run `wp site list --fields=blog_id,deleted`
215222
Then STDOUT should be a table containing rows:
@@ -227,11 +234,13 @@ Feature: Manage sites in a multisite installation
227234
| blog_id | deleted |
228235
| {FIRST_SITE} | 0 |
229236

230-
When I run `wp site deactivate 1`
237+
When I try `wp site deactivate 1`
231238
Then STDERR should be:
232239
"""
233240
Warning: You are not allowed to change the main site.
234241
"""
242+
And STDOUT should be empty
243+
And the return code should be 0
235244

236245
Scenario: Mark/remove a site from spam
237246
Given a WP multisite install
@@ -251,7 +260,7 @@ Feature: Manage sites in a multisite installation
251260
| blog_id | spam |
252261
| {FIRST_SITE} | 1 |
253262

254-
When I run `wp site spam {FIRST_SITE} {SECOND_SITE}`
263+
When I try `wp site spam {FIRST_SITE} {SECOND_SITE}`
255264
Then STDERR should be:
256265
"""
257266
Warning: Site {FIRST_SITE} already marked as spam.
@@ -260,6 +269,7 @@ Feature: Manage sites in a multisite installation
260269
"""
261270
Success: Site {SECOND_SITE} marked as spam.
262271
"""
272+
And the return code should be 0
263273

264274
When I run `wp site list --fields=blog_id,spam`
265275
Then STDOUT should be a table containing rows:
@@ -277,11 +287,13 @@ Feature: Manage sites in a multisite installation
277287
| blog_id | spam |
278288
| {FIRST_SITE} | 0 |
279289

280-
When I run `wp site spam 1`
290+
When I try `wp site spam 1`
281291
Then STDERR should be:
282292
"""
283293
Warning: You are not allowed to change the main site.
284294
"""
295+
And STDOUT should be empty
296+
And the return code should be 0
285297

286298
Scenario: Mark/remove a site as mature
287299
Given a WP multisite install
@@ -301,7 +313,7 @@ Feature: Manage sites in a multisite installation
301313
| blog_id | mature |
302314
| {FIRST_SITE} | 1 |
303315

304-
When I run `wp site mature {FIRST_SITE} {SECOND_SITE}`
316+
When I try `wp site mature {FIRST_SITE} {SECOND_SITE}`
305317
Then STDERR should be:
306318
"""
307319
Warning: Site {FIRST_SITE} already marked as mature.
@@ -310,6 +322,7 @@ Feature: Manage sites in a multisite installation
310322
"""
311323
Success: Site {SECOND_SITE} marked as mature.
312324
"""
325+
And the return code should be 0
313326

314327
When I run `wp site list --fields=blog_id,mature`
315328
Then STDOUT should be a table containing rows:
@@ -327,11 +340,13 @@ Feature: Manage sites in a multisite installation
327340
| blog_id | mature |
328341
| {FIRST_SITE} | 0 |
329342

330-
When I run `wp site unmature 1`
343+
When I try `wp site unmature 1`
331344
Then STDERR should be:
332345
"""
333346
Warning: You are not allowed to change the main site.
334347
"""
348+
And STDOUT should be empty
349+
And the return code should be 0
335350

336351
Scenario: Set/Unset a site as public
337352
Given a WP multisite install
@@ -351,7 +366,7 @@ Feature: Manage sites in a multisite installation
351366
| blog_id | public |
352367
| {FIRST_SITE} | 0 |
353368

354-
When I run `wp site private {FIRST_SITE} {SECOND_SITE}`
369+
When I try `wp site private {FIRST_SITE} {SECOND_SITE}`
355370
Then STDERR should be:
356371
"""
357372
Warning: Site {FIRST_SITE} already marked as private.
@@ -360,6 +375,7 @@ Feature: Manage sites in a multisite installation
360375
"""
361376
Success: Site {SECOND_SITE} marked as private.
362377
"""
378+
And the return code should be 0
363379

364380
When I run `wp site list --fields=blog_id,public`
365381
Then STDOUT should be a table containing rows:
@@ -377,11 +393,13 @@ Feature: Manage sites in a multisite installation
377393
| blog_id | public |
378394
| {FIRST_SITE} | 1 |
379395

380-
When I run `wp site private 1`
396+
When I try `wp site private 1`
381397
Then STDERR should be:
382398
"""
383399
Warning: You are not allowed to change the main site.
384400
"""
401+
And STDOUT should be empty
402+
And the return code should be 0
385403

386404
Scenario: Permit CLI operations against archived and suspended sites
387405
Given a WP multisite install

features/term.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Feature: Manage WordPress terms
7878
"""
7979
And the return code should be 0
8080

81-
When I run the previous command again
81+
When I try the previous command again
8282
Then STDOUT should be:
8383
"""
8484
Success: Term already deleted.
@@ -89,7 +89,7 @@ Feature: Manage WordPress terms
8989
"""
9090
And the return code should be 0
9191

92-
When I run `wp term delete post_tag {TERM_ID} {TERM_ID_TWO}`
92+
When I try `wp term delete post_tag {TERM_ID} {TERM_ID_TWO}`
9393
Then STDOUT should be:
9494
"""
9595
Deleted post_tag {TERM_ID_TWO}.

src/Comment_Command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,15 @@ public function generate( $args, $assoc_args ) {
163163
$notify = \WP_CLI\Utils\make_progress_bar( 'Generating comments', $assoc_args['count'] );
164164
}
165165

166+
$comment_post_ID = empty( $assoc_args['post_id'] ) ? 1 : $assoc_args['post_id'];
166167
$comment_count = wp_count_comments();
167168
$total = (int )$comment_count->total_comments;
168169
$limit = $total + $assoc_args['count'];
169170

170171
for ( $i = $total; $i < $limit; $i++ ) {
171172
$comment_id = wp_insert_comment( array(
172173
'comment_content' => "Comment {$i}",
173-
'comment_post_ID' => $assoc_args['post_id'],
174+
'comment_post_ID' => $comment_post_ID,
174175
) );
175176
if ( 'progress' === $format ) {
176177
$notify->tick();

src/Site_Command.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,11 @@ public function _empty( $args, $assoc_args ) {
195195
);
196196

197197
$files_to_unlink = $directories_to_delete = array();
198+
$is_main_site = is_main_site();
198199
foreach ( $files as $fileinfo ) {
199200
$realpath = $fileinfo->getRealPath();
200201
// Don't clobber subsites when operating on the main site
201-
if ( is_main_site() && false !== stripos( $realpath, '/sites/' ) ) {
202+
if ( $is_main_site && false !== stripos( $realpath, '/sites/' ) ) {
202203
continue;
203204
}
204205
if ( $fileinfo->isDir() ) {
@@ -211,9 +212,11 @@ public function _empty( $args, $assoc_args ) {
211212
unlink( $file );
212213
}
213214
foreach( $directories_to_delete as $directory ) {
214-
rmdir( $directory );
215+
// Directory could be main sites directory '/sites' which may be non-empty.
216+
@rmdir( $directory ); // @codingStandardsIgnoreLine
215217
}
216-
rmdir( $upload_dir['basedir'] );
218+
// May be non-empty if '/sites' still around.
219+
@rmdir( $upload_dir['basedir'] ); // @codingStandardsIgnoreLine
217220
}
218221

219222
WP_CLI::success( "The site at '" . site_url() . "' was emptied." );

0 commit comments

Comments
 (0)