-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathuser.feature
744 lines (611 loc) · 19.6 KB
/
user.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
Feature: Manage WordPress users
Scenario: User CRUD operations
Given a WP install
When I try `wp user get bogus-user`
Then the return code should be 1
And STDOUT should be empty
When I run `wp user create testuser2 [email protected] --first_name=test --last_name=user --role=author --porcelain`
Then STDOUT should be a number
And save STDOUT as {USER_ID}
When I run `wp user get {USER_ID}`
Then STDOUT should be a table containing rows:
| Field | Value |
| ID | {USER_ID} |
| roles | author |
When I run `wp user exists {USER_ID}`
Then STDOUT should be:
"""
Success: User with ID {USER_ID} exists.
"""
And the return code should be 0
When I try `wp user exists 1000`
And STDOUT should be empty
And the return code should be 1
When I run `wp user get {USER_ID} --field=user_registered`
Then STDOUT should not contain:
"""
0000-00-00 00:00:00
"""
When I run `wp user meta get {USER_ID} first_name`
Then STDOUT should be:
"""
test
"""
When I run `wp user list --fields=user_login,roles`
Then STDOUT should be a table containing rows:
| user_login | roles |
| testuser2 | author |
When I run `wp user meta get {USER_ID} last_name`
Then STDOUT should be:
"""
user
"""
When I run `wp user delete {USER_ID} --yes`
Then STDOUT should not be empty
When I try `wp user create testuser2 [email protected] --role=wrongrole --porcelain`
Then the return code should be 1
Then STDOUT should be empty
When I run `wp user create testuser [email protected] --porcelain`
Then STDOUT should be a number
And save STDOUT as {USER_ID}
When I try the previous command again
Then the return code should be 1
When I run `wp user update {USER_ID} --display_name=Foo`
And I run `wp user get {USER_ID}`
Then STDOUT should be a table containing rows:
| Field | Value |
| ID | {USER_ID} |
| display_name | Foo |
When I run `wp user get [email protected]`
Then STDOUT should be a table containing rows:
| Field | Value |
| ID | {USER_ID} |
| display_name | Foo |
When I run `wp user delete {USER_ID} --yes`
Then STDOUT should not be empty
When I run `wp user create testuser3 [email protected] --user_pass=testuser3pass`
Then STDOUT should not contain:
"""
Password:
"""
# Check with valid password.
When I run `wp user check-password testuser3 testuser3pass`
Then the return code should be 0
# Check with invalid password.
When I try `wp user check-password testuser3 invalidpass`
Then the return code should be 1
When I try `wp user check-password invaliduser randomstring`
Then STDERR should contain:
"""
Invalid user ID, email or login: 'invaliduser'
"""
And the return code should be 1
When I run `wp user create testuser3b [email protected] --user_pass="test\"user3b's\pass\!"`
Then STDOUT should not contain:
"""
Password:
"""
# Check password without the `--escape-chars` option.
When I try `wp user check-password testuser3b "test\"user3b's\pass\!"`
Then STDERR should be:
"""
Warning: Password contains characters that need to be escaped. Please escape them manually or use the `--escape-chars` option.
"""
And the return code should be 1
# Check password with the `--escape-chars` option.
When I try `wp user check-password testuser3b "test\"user3b's\pass\!" --escape-chars`
Then the return code should be 0
# Check password with manually escaped characters.
When I try `wp user check-password testuser3b "test\\\"user3b\'s\\\pass\\\!"`
Then the return code should be 0
Scenario: Reassigning user posts
Given a WP multisite install
When I run `wp user create bobjones [email protected] --role=author --porcelain`
And save STDOUT as {BOB_ID}
And I run `wp user create sally [email protected] --role=editor --porcelain`
And save STDOUT as {SALLY_ID}
When I run `wp post generate --count=3 --post_author=bobjones`
And I run `wp post list --author={BOB_ID} --format=count`
Then STDOUT should be:
"""
3
"""
When I run `wp user delete bobjones --reassign={SALLY_ID}`
And I run `wp post list --author={SALLY_ID} --format=count`
Then STDOUT should be:
"""
3
"""
When I try `wp user update 9999 --user_pass=securepassword`
Then the return code should be 1
And STDERR should contain:
"""
Error: No valid users found.
"""
Scenario: Delete user with invalid reassign
Given a WP install
And a session_no file:
"""
n
"""
And a session_yes file:
"""
y
"""
When I run `wp user create bobjones [email protected] --role=author --porcelain`
And save STDOUT as {BOB_ID}
When I run `wp post list --format=count`
And save STDOUT as {TOTAL_POSTS}
When I run `wp post generate --count=3 --format=ids --post_author=bobjones`
And I run `wp post list --author={BOB_ID} --format=count`
Then STDOUT should be:
"""
3
"""
When I run `wp user delete bobjones < session_no`
Then STDOUT should contain:
"""
--reassign parameter not passed. All associated posts will be deleted. Proceed? [y/n]
"""
When I run `wp user delete bobjones --reassign=99999 < session_no`
Then STDOUT should contain:
"""
--reassign parameter is invalid. All associated posts will be deleted. Proceed? [y/n]
"""
When I run `wp user delete bobjones < session_yes`
And I run `wp post list --format=count`
Then STDOUT should be:
"""
{TOTAL_POSTS}
"""
Scenario: Deleting user from the whole network
Given a WP multisite install
When I run `wp user create bobjones [email protected] --role=author --porcelain`
And save STDOUT as {BOB_ID}
When I run `wp user get bobjones`
Then STDOUT should not be empty
When I run `wp user delete bobjones --network --yes`
Then STDOUT should not be empty
When I try `wp user get bobjones`
Then STDERR should not be empty
And the return code should be 1
Scenario: Trying to delete existing user with no roles from a subsite
Given a WP multisite install
When I run `wp user create bobjones [email protected] --role=author --url=https://example.com --porcelain`
And save STDOUT as {BOB_ID}
When I run `wp user delete bobjones --yes`
Then STDOUT should contain:
"""
Success: Removed user
"""
And STDERR should be empty
When I try `wp user delete bobjones --yes`
Then STDERR should be:
"""
Warning: No roles found for user {BOB_ID} on https://example.com, no users deleted.
"""
And the return code should be 1
@require-wp-4.0
Scenario: Trying to delete super admin
Given a WP multisite install
When I run `wp user create bobjones [email protected] --role=author --porcelain`
And save STDOUT as {BOB_ID}
When I run `wp super-admin add {BOB_ID}`
And I try `wp user delete bobjones --network --yes`
Then STDERR should be:
"""
Warning: Failed deleting user {BOB_ID}. The user is a super admin.
"""
And the return code should be 1
Scenario: Create new users on multisite
Given a WP multisite install
When I try `wp user create bob-jones [email protected]`
Then STDERR should contain:
"""
lowercase letters (a-z) and numbers
"""
And the return code should be 1
When I run `wp user create bobjones [email protected] --display_name="Bob Jones"`
Then STDOUT should not be empty
When I run `wp user get bobjones --field=display_name`
Then STDOUT should be:
"""
Bob Jones
"""
Scenario: Managing user roles
Given a WP install
When I try `wp user add-role 1`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify at least one role to add.
"""
And STDOUT should be empty
When I run `wp user add-role 1 editor`
Then STDOUT should be:
"""
Success: Added 'editor' role for admin (1).
"""
When I run `wp user get 1 --field=roles`
Then STDOUT should be:
"""
administrator, editor
"""
When I run `wp user add-role 1 editor contributor`
Then STDOUT should be:
"""
Success: Added 'editor', 'contributor' roles for admin (1).
"""
When I run `wp user get 1 --field=roles`
Then STDOUT should be:
"""
administrator, editor, contributor
"""
When I run `wp user remove-role 1 editor contributor`
Then STDOUT should be:
"""
Success: Removed 'editor', 'contributor' roles from admin (1).
"""
When I run `wp user get 1 --field=roles`
Then STDOUT should be:
"""
administrator
"""
When I try `wp user add-role 1 edit`
Then STDERR should contain:
"""
Role doesn't exist
"""
And the return code should be 1
When I try `wp user set-role 1 edit`
Then STDERR should contain:
"""
Role doesn't exist
"""
And the return code should be 1
When I try `wp user remove-role 1 edit`
Then STDERR should contain:
"""
Role doesn't exist
"""
And the return code should be 1
When I run `wp user set-role 1 author`
Then STDOUT should not be empty
And I run `wp user get 1`
Then STDOUT should be a table containing rows:
| Field | Value |
| roles | author |
When I run `wp user remove-role 1 editor`
Then STDOUT should not be empty
And I run `wp user get 1`
Then STDOUT should be a table containing rows:
| Field | Value |
| roles | author |
When I run `wp user remove-role 1`
Then STDOUT should not be empty
And I run `wp user get 1`
Then STDOUT should be a table containing rows:
| Field | Value |
| roles | |
Scenario: Invalid User Role
Given a WP install
When I run `wp user create testuser4 [email protected]`
And I try `wp user update testuser4 --role=banana`
Then STDERR should be:
"""
Warning: Role doesn't exist: banana
"""
And STDOUT should contain:
"""
Success:
"""
And the return code should be 0
When I run `wp user get admin --field=roles`
Then STDOUT should be:
"""
administrator
"""
When I run `wp user update 1 --user_pass=new_password`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
Scenario: Managing user capabilities
Given a WP install
When I run `wp user add-cap 1 edit_vip_product`
Then STDOUT should be:
"""
Success: Added 'edit_vip_product' capability for admin (1).
"""
And I run `wp user list-caps 1 | tail -n 1`
Then STDOUT should be:
"""
edit_vip_product
"""
And I run `wp user remove-cap 1 edit_vip_product`
Then STDOUT should be:
"""
Success: Removed 'edit_vip_product' cap for admin (1).
"""
And I try the previous command again
Then the return code should be 1
And STDERR should be:
"""
Error: No such 'edit_vip_product' cap for admin (1).
"""
And STDOUT should be empty
When I run `wp user list-caps 1`
Then STDOUT should not contain:
"""
edit_vip_product
"""
And STDOUT should contain:
"""
publish_posts
"""
When I try `wp user remove-cap 1 publish_posts`
Then the return code should be 1
And STDERR should be:
"""
Error: The 'publish_posts' cap for admin (1) is inherited from a role.
"""
And STDOUT should be empty
And I run `wp user list-caps 1`
Then STDOUT should contain:
"""
publish_posts
"""
Scenario: Show password when creating a user
Given a WP install
When I run `wp user create testrandompass [email protected]`
Then STDOUT should contain:
"""
Password:
"""
When I run `wp user create testsuppliedpass [email protected] --user_pass=suppliedpass`
Then STDOUT should not contain:
"""
Password:
"""
Scenario: List network users
Given a WP multisite install
When I run `wp user create testsubscriber [email protected]`
Then STDOUT should contain:
"""
Success: Created user
"""
When I run `wp user list --field=user_login`
Then STDOUT should contain:
"""
testsubscriber
"""
When I run `wp user delete testsubscriber --yes`
Then STDOUT should contain:
"""
Success: Removed user
"""
When I run `wp user list --field=user_login`
Then STDOUT should not contain:
"""
testsubscriber
"""
When I run `wp user list --field=user_login --network`
Then STDOUT should contain:
"""
testsubscriber
"""
Scenario: Listing user capabilities
Given a WP install
When I run `wp user create bob [email protected] --role=contributor`
And I run `wp user list-caps bob`
Then STDOUT should be:
"""
edit_posts
read
level_1
level_0
delete_posts
contributor
"""
And I run `wp user list-caps bob --format=json`
Then STDOUT should be:
"""
[{"name":"edit_posts"},{"name":"read"},{"name":"level_1"},{"name":"level_0"},{"name":"delete_posts"},{"name":"contributor"}]
"""
And I run `wp user list-caps bob --format=count`
Then STDOUT should be:
"""
6
"""
When I run `wp user list-caps bob --exclude-role-names`
Then STDOUT should be:
"""
edit_posts
read
level_1
level_0
delete_posts
"""
When I run `wp user add-cap bob newcap`
And I run `wp user list-caps bob --origin=role`
Then STDOUT should be:
"""
edit_posts
read
level_1
level_0
delete_posts
contributor
"""
And I run `wp user list-caps bob --origin=user`
Then STDOUT should be:
"""
newcap
"""
Scenario: Make sure WordPress receives the slashed data it expects
Given a WP install
When I run `wp user create slasheduser [email protected] --display_name='My\User' --porcelain`
Then save STDOUT as {USER_ID}
When I run `wp user get {USER_ID} --field=display_name`
Then STDOUT should be:
"""
My\User
"""
When I run `wp user update {USER_ID} --display_name='My\New\User'`
Then STDOUT should not be empty
When I run `wp user get {USER_ID} --field=display_name`
Then STDOUT should be:
"""
My\New\User
"""
Scenario: Don't send user creation emails by default
Given a WP multisite install
When I run `wp user create testuser2 [email protected]`
Then an email should not be sent
When I run `wp user create testuser3 [email protected] --send-email`
Then an email should be sent
Scenario: List URLs of one or more users
Given a WP install
And I run `wp user create bob [email protected] --role=contributor`
When I run `wp user list --include=1,2 --field=url`
Then STDOUT should be:
"""
https://example.com/?author=1
https://example.com/?author=2
"""
Scenario: Get user with email as login
Given a WP install
And I run `wp user create [email protected] [email protected]`
When I run `wp user get [email protected] --field=user_login`
Then STDOUT should be:
"""
"""
When I run `wp user get [email protected] --field=user_login`
Then STDOUT should be:
"""
"""
Scenario: Mark/remove a user from spam
Given a WP multisite install
And I run `wp user create bumblebee [email protected] --role=author --porcelain`
And save STDOUT as {BBEE_ID}
And I run `wp user create oprime [email protected] --role=author --porcelain`
And save STDOUT as {OP_ID}
And I run `wp user get bumblebee`
Then STDOUT should not be empty
And I run `wp user get oprime`
Then STDOUT should not be empty
When I run `wp site create --slug=foo --porcelain`
Then save STDOUT as {SPAM_SITE_ID}
When I run `wp --url=example.com/foo user set-role {BBEE_ID} administrator`
Then STDOUT should contain:
"""
Success:
"""
When I run `wp user spam {BBEE_ID}`
Then STDOUT should be:
"""
User {BBEE_ID} marked as spam.
Success: Spammed 1 of 1 users.
"""
When I try the previous command again
Then STDERR should be:
"""
Warning: User {BBEE_ID} already marked as spam.
"""
And STDOUT should be:
"""
Success: User already spammed.
"""
And the return code should be 0
When I run `wp site list --site__in=1 --field=spam`
Then STDOUT should be:
"""
0
"""
When I run `wp site list --site__in={SPAM_SITE_ID} --field=spam`
Then STDOUT should be:
"""
1
"""
When I try `wp user spam {OP_ID} 9999`
Then STDOUT should be:
"""
User {OP_ID} marked as spam.
"""
And STDERR should be:
"""
Warning: Invalid user ID, email or login: '9999'
Error: Only spammed 1 of 2 users.
"""
And the return code should be 1
When I run `wp user unspam {BBEE_ID}`
Then STDOUT should contain:
"""
Success:
"""
When I run `wp site list --site__in=1 --field=spam`
Then STDOUT should be:
"""
0
"""
When I run `wp site list --site__in={SPAM_SITE_ID} --field=spam`
Then STDOUT should be:
"""
0
"""
@require-wp-4.3
Scenario: Sending emails on update
Given a WP install
When I run `wp user get 1 --field=user_email`
Then save STDOUT as {ORIGINAL_EMAIL}
When I run `wp user update 1 [email protected]`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should be sent
When I run `wp user update 1 --user_email={ORIGINAL_EMAIL} --skip-email`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should not be sent
When I run `wp user get 1 --field=user_pass`
Then save STDOUT as {ORIGINAL_PASSWORD}
When I run `wp user update 1 --user_pass=different_password`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should be sent
When I run `wp user update 1 --user_pass={ORIGINAL_PASSWORD} --skip-email`
Then STDOUT should contain:
"""
Success: Updated user 1.
"""
And an email should not be sent
Scenario: Set user url when creating a user
Given a WP install
And I run `wp user create testurl [email protected] --user_url='http://www.testsite.com'`
When I run `wp user get testurl --fields=user_url`
Then STDOUT should be a table containing rows:
| Field | Value |
| user_url | http://www.testsite.com |
Scenario: Support nickname creating and updating user
Given a WP install
When I run `wp user create testuser [email protected] --nickname=customtestuser --porcelain`
Then STDOUT should be a number
And save STDOUT as {USER_ID}
When I run `wp user meta get {USER_ID} nickname`
Then STDOUT should be:
"""
customtestuser
"""
When I run `wp user update {USER_ID} --nickname=newtestuser`
And I run `wp user meta get {USER_ID} nickname`
Then STDOUT should be:
"""
newtestuser
"""