/
site.feature
765 lines (637 loc) · 20.8 KB
/
site.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
Feature: Manage sites in a multisite installation
Scenario: Create a site
Given a WP multisite install
When I try `wp site create --slug=first --network_id=1000`
Then STDERR should contain:
"""
Network with id 1000 does not exist.
"""
And STDOUT should be empty
And the return code should be 1
Scenario: Create a subdomain site
Given a WP multisite subdomain install
When I run `wp site create --slug=first`
Then STDOUT should not be empty
When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | https://example.com/ |
| 2 | http://first.example.com/ |
When I run `wp site list --format=ids`
Then STDOUT should be:
"""
1 2
"""
When I run `wp site list --site_id=2 --format=ids`
Then STDOUT should be empty
When I run `wp --url=first.example.com option get home`
Then STDOUT should be:
"""
http://first.example.com
"""
Scenario: Delete a site by id
Given a WP multisite subdirectory install
When I run `wp site create --slug=first --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}
And I run `wp site list --site__in={SITE_ID} --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SCHEME}
When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | https://example.com/ |
| 2 | {SCHEME}://example.com/first/ |
When I run `wp site list --field=url`
Then STDOUT should be:
"""
https://example.com/
{SCHEME}://example.com/first/
"""
When I try `wp site delete 1`
Then STDERR should be:
"""
Error: You cannot delete the root site.
"""
And STDOUT should be empty
And the return code should be 1
When I run `wp site delete {SITE_ID} --yes`
Then STDOUT should be:
"""
Success: The site at '{SCHEME}://example.com/first/' was deleted.
"""
When I try the previous command again
Then the return code should be 1
Scenario: Filter site list
Given a WP multisite install
When I run `wp site create --slug=first --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}
And I run `wp site list --site__in={SITE_ID} --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SCHEME}
When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | https://example.com/ |
| 2 | {SCHEME}://example.com/first/ |
When I run `wp site list --field=url --blog_id=2`
Then STDOUT should be:
"""
{SCHEME}://example.com/first/
"""
Scenario: Filter site list by user
Given a WP multisite install
When I run `wp site create --slug=first --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}
And I run `wp site list --blog_id={SITE_ID} --field=url`
And save STDOUT as {SITE_URL}
And I run `wp user create newuser newuser@example.com --porcelain --url={SITE_URL}`
Then STDOUT should be a number
And save STDOUT as {USER_ID}
And I run `wp user get {USER_ID} --field=user_login`
And save STDOUT as {USER_LOGIN}
When I run `wp site list --field=url --site_user={USER_LOGIN}`
Then STDOUT should be:
"""
{SITE_URL}
"""
When I try `wp site list --site_user=invalid_user`
Then the return code should be 1
And STDERR should be:
"""
Error: Invalid user ID, email or login: 'invalid_user'
"""
When I run `wp user remove-role {USER_LOGIN} --url={SITE_URL}`
Then STDOUT should contain:
"""
Success: Removed
"""
When I run `wp site list --field=url --site_user={USER_LOGIN}`
Then STDOUT should be empty
Scenario: Delete a site by slug
Given a WP multisite install
When I run `wp site create --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/first/
"""
When I run `wp site delete --slug=first --yes`
Then STDOUT should contain:
"""
://example.com/first/' was deleted.
"""
When I try the previous command again
Then the return code should be 1
When I run `wp site create --slug=42`
Then STDOUT should contain:
"""
Success: Site 3 created: http
"""
And STDOUT should contain:
"""
://example.com/42/
"""
When I run `wp site delete --slug=42 --yes`
Then STDOUT should contain:
"""
://example.com/42/' was deleted.
"""
When I try the previous command again
Then STDERR should contain:
"""
Error: Could not find site with slug '42'.
"""
And the return code should be 1
Scenario: Archive a site by a numeric slug
Given a WP multisite install
When I run `wp site create --slug=42`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/42/
"""
When I run `wp site archive --slug=42`
Then STDOUT should contain:
"""
Success: Site 2 archived.
"""
When I try `wp site archive --slug=43`
Then STDERR should contain:
"""
Error: Could not find site with slug '43'.
"""
And the return code should be 1
Scenario: Get site info
Given a WP multisite install
When I run `wp site create --slug=first --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}
And I run `wp site list --site__in={SITE_ID} --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SCHEME}
When I run `wp site url {SITE_ID}`
Then STDOUT should be:
"""
{SCHEME}://example.com/first/
"""
When I run `wp site create --slug=second --porcelain`
Then STDOUT should be a number
And save STDOUT as {SECOND_ID}
And I run `wp site list --site__in={SECOND_ID} --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SECOND_SCHEME}
When I run `wp site url {SECOND_ID} {SITE_ID}`
Then STDOUT should be:
"""
{SECOND_SCHEME}://example.com/second/
{SCHEME}://example.com/first/
"""
Scenario: Not providing a site ID or slug when running an update blog status command should throw an error
Given a WP multisite install
When I try `wp site private`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more IDs of sites, or pass the slug for a single site using --slug.
"""
And STDOUT should be empty
Scenario: Site IDs or a slug can be provided, but not both.
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
When I try `wp site private 1 --slug=first`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more IDs of sites, or pass the slug for a single site using --slug.
"""
Scenario: Errors for an invalid slug
Given a WP multisite install
When I try `wp site private --slug=first`
Then the return code should be 1
And STDERR should be:
"""
Error: Could not find site with slug 'first'.
"""
Scenario: Archive/unarchive a site
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
And save STDOUT as {FIRST_SITE}
And I run `wp site create --slug=second --porcelain`
And save STDOUT as {SECOND_SITE}
When I run `wp site archive {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} archived.
"""
When I run `wp site list --fields=blog_id,archived`
Then STDOUT should be a table containing rows:
| blog_id | archived |
| {FIRST_SITE} | 1 |
When I try `wp site archive {FIRST_SITE} {SECOND_SITE}`
Then STDERR should be:
"""
Warning: Site {FIRST_SITE} already archived.
"""
And STDOUT should be:
"""
Success: Site {SECOND_SITE} archived.
"""
And the return code should be 0
When I run `wp site list --fields=blog_id,archived`
Then STDOUT should be a table containing rows:
| blog_id | archived |
| {FIRST_SITE} | 1 |
When I run `wp site unarchive {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} unarchived.
"""
When I run `wp site list --fields=blog_id,archived`
Then STDOUT should be a table containing rows:
| blog_id | archived |
| {FIRST_SITE} | 0 |
When I try `wp site archive 1`
Then STDERR should be:
"""
Warning: You are not allowed to change the main site.
"""
And STDOUT should be empty
And the return code should be 0
Scenario: Activate/deactivate a site
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
And save STDOUT as {FIRST_SITE}
And I run `wp site create --slug=second --porcelain`
And save STDOUT as {SECOND_SITE}
When I run `wp site deactivate {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} deactivated.
"""
When I run `wp site list --fields=blog_id,deleted`
Then STDOUT should be a table containing rows:
| blog_id | deleted |
| {FIRST_SITE} | 1 |
When I try `wp site deactivate {FIRST_SITE} {SECOND_SITE}`
Then STDERR should be:
"""
Warning: Site {FIRST_SITE} already deactivated.
"""
And STDOUT should be:
"""
Success: Site {SECOND_SITE} deactivated.
"""
And the return code should be 0
When I run `wp site list --fields=blog_id,deleted`
Then STDOUT should be a table containing rows:
| blog_id | deleted |
| {FIRST_SITE} | 1 |
When I run `wp site activate {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} activated.
"""
When I run `wp site list --fields=blog_id,deleted`
Then STDOUT should be a table containing rows:
| blog_id | deleted |
| {FIRST_SITE} | 0 |
When I try `wp site deactivate 1`
Then STDERR should be:
"""
Warning: You are not allowed to change the main site.
"""
And STDOUT should be empty
And the return code should be 0
Scenario: Mark/remove a site from spam
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
And save STDOUT as {FIRST_SITE}
And I run `wp site create --slug=second --porcelain`
And save STDOUT as {SECOND_SITE}
When I run `wp site spam {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} marked as spam.
"""
When I run `wp site list --fields=blog_id,spam`
Then STDOUT should be a table containing rows:
| blog_id | spam |
| {FIRST_SITE} | 1 |
When I try `wp site spam {FIRST_SITE} {SECOND_SITE}`
Then STDERR should be:
"""
Warning: Site {FIRST_SITE} already marked as spam.
"""
And STDOUT should be:
"""
Success: Site {SECOND_SITE} marked as spam.
"""
And the return code should be 0
When I run `wp site list --fields=blog_id,spam`
Then STDOUT should be a table containing rows:
| blog_id | spam |
| {FIRST_SITE} | 1 |
When I run `wp site unspam {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} removed from spam.
"""
When I run `wp site list --fields=blog_id,spam`
Then STDOUT should be a table containing rows:
| blog_id | spam |
| {FIRST_SITE} | 0 |
When I try `wp site spam 1`
Then STDERR should be:
"""
Warning: You are not allowed to change the main site.
"""
And STDOUT should be empty
And the return code should be 0
Scenario: Mark/remove a site as mature
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
And save STDOUT as {FIRST_SITE}
And I run `wp site create --slug=second --porcelain`
And save STDOUT as {SECOND_SITE}
When I run `wp site mature {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} marked as mature.
"""
When I run `wp site list --fields=blog_id,mature`
Then STDOUT should be a table containing rows:
| blog_id | mature |
| {FIRST_SITE} | 1 |
When I try `wp site mature {FIRST_SITE} {SECOND_SITE}`
Then STDERR should be:
"""
Warning: Site {FIRST_SITE} already marked as mature.
"""
And STDOUT should be:
"""
Success: Site {SECOND_SITE} marked as mature.
"""
And the return code should be 0
When I run `wp site list --fields=blog_id,mature`
Then STDOUT should be a table containing rows:
| blog_id | mature |
| {FIRST_SITE} | 1 |
When I run `wp site unmature {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} marked as unmature.
"""
When I run `wp site list --fields=blog_id,mature`
Then STDOUT should be a table containing rows:
| blog_id | mature |
| {FIRST_SITE} | 0 |
When I try `wp site unmature 1`
Then STDERR should be:
"""
Warning: You are not allowed to change the main site.
"""
And STDOUT should be empty
And the return code should be 0
Scenario: Set/Unset a site as public
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
And save STDOUT as {FIRST_SITE}
And I run `wp site create --slug=second --porcelain`
And save STDOUT as {SECOND_SITE}
When I run `wp site private {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} marked as private.
"""
When I run `wp site list --fields=blog_id,public`
Then STDOUT should be a table containing rows:
| blog_id | public |
| {FIRST_SITE} | 0 |
When I try `wp site private {FIRST_SITE} {SECOND_SITE}`
Then STDERR should be:
"""
Warning: Site {FIRST_SITE} already marked as private.
"""
And STDOUT should be:
"""
Success: Site {SECOND_SITE} marked as private.
"""
And the return code should be 0
When I run `wp site list --fields=blog_id,public`
Then STDOUT should be a table containing rows:
| blog_id | public |
| {FIRST_SITE} | 0 |
When I run `wp site public {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} marked as public.
"""
When I run `wp site list --fields=blog_id,public`
Then STDOUT should be a table containing rows:
| blog_id | public |
| {FIRST_SITE} | 1 |
When I try `wp site private 1`
Then STDERR should be:
"""
Warning: You are not allowed to change the main site.
"""
And STDOUT should be empty
And the return code should be 0
Scenario: Permit CLI operations against archived and suspended sites
Given a WP multisite install
And I run `wp site create --slug=first --porcelain`
And save STDOUT as {FIRST_SITE}
When I run `wp site archive {FIRST_SITE}`
Then STDOUT should be:
"""
Success: Site {FIRST_SITE} archived.
"""
When I run `wp --url=example.com/first option get home`
Then STDOUT should contain:
"""
://example.com/first
"""
Scenario: Create site with title containing slash
Given a WP multisite install
And I run `wp site create --slug=mysite --title="My\Site"`
Then STDOUT should not be empty
When I run `wp option get blogname --url=example.com/mysite`
Then STDOUT should be:
"""
My\Site
"""
Scenario: Activate/deactivate a site by slug
Given a WP multisite install
When I run `wp site create --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/first/
"""
When I run `wp site deactivate --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 deactivated.
"""
When I run `wp site list --fields=blog_id,deleted`
Then STDOUT should be a table containing rows:
| blog_id | deleted |
| 2 | 1 |
When I try `wp site deactivate --slug=first`
Then STDERR should be:
"""
Warning: Site 2 already deactivated.
"""
When I run `wp site activate --slug=first`
Then STDOUT should be:
"""
Success: Site 2 activated.
"""
When I run `wp site list --fields=blog_id,deleted`
Then STDOUT should be a table containing rows:
| blog_id | deleted |
| 2 | 0 |
Scenario: Archive/unarchive a site by slug
Given a WP multisite install
When I run `wp site create --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/first/
"""
When I run `wp site archive --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 archived.
"""
When I run `wp site list --fields=blog_id,archived`
Then STDOUT should be a table containing rows:
| blog_id | archived |
| 2 | 1 |
When I try `wp site archive --slug=first`
Then STDERR should be:
"""
Warning: Site 2 already archived.
"""
When I run `wp site unarchive --slug=first`
Then STDOUT should be:
"""
Success: Site 2 unarchived.
"""
When I run `wp site list --fields=blog_id,archived`
Then STDOUT should be a table containing rows:
| blog_id | archived |
| 2 | 0 |
Scenario: Mark/remove a site by slug from spam
Given a WP multisite install
When I run `wp site create --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/first/
"""
When I run `wp site spam --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 marked as spam.
"""
When I run `wp site list --fields=blog_id,spam`
Then STDOUT should be a table containing rows:
| blog_id | spam |
| 2 | 1 |
When I try `wp site spam --slug=first`
Then STDERR should be:
"""
Warning: Site 2 already marked as spam.
"""
When I run `wp site unspam --slug=first`
Then STDOUT should be:
"""
Success: Site 2 removed from spam.
"""
When I run `wp site list --fields=blog_id,spam`
Then STDOUT should be a table containing rows:
| blog_id | spam |
| 2 | 0 |
Scenario: Mark/remove a site by slug as mature
Given a WP multisite install
When I run `wp site create --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/first/
"""
When I run `wp site mature --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 marked as mature.
"""
When I run `wp site list --fields=blog_id,mature`
Then STDOUT should be a table containing rows:
| blog_id | mature |
| 2 | 1 |
When I try `wp site mature --slug=first`
Then STDERR should be:
"""
Warning: Site 2 already marked as mature.
"""
When I run `wp site unmature --slug=first`
Then STDOUT should be:
"""
Success: Site 2 marked as unmature.
"""
When I run `wp site list --fields=blog_id,mature`
Then STDOUT should be a table containing rows:
| blog_id | mature |
| 2 | 0 |
Scenario: Set/Unset a site by slug as public
Given a WP multisite install
When I run `wp site create --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 created: http
"""
And STDOUT should contain:
"""
://example.com/first/
"""
When I run `wp site private --slug=first`
Then STDOUT should contain:
"""
Success: Site 2 marked as private.
"""
When I run `wp site list --fields=blog_id,public`
Then STDOUT should be a table containing rows:
| blog_id | public |
| 2 | 0 |
When I try `wp site private --slug=first`
Then STDERR should be:
"""
Warning: Site 2 already marked as private.
"""
When I run `wp site public --slug=first`
Then STDOUT should be:
"""
Success: Site 2 marked as public.
"""
When I run `wp site list --fields=blog_id,public`
Then STDOUT should be a table containing rows:
| blog_id | public |
| 2 | 1 |