-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathuser-import-csv.feature
More file actions
184 lines (157 loc) · 5.32 KB
/
user-import-csv.feature
File metadata and controls
184 lines (157 loc) · 5.32 KB
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
Feature: Import users from CSV
Scenario: Importing users from a CSV file
Given a WP install
And a users.csv file:
"""
user_login,user_email,display_name,role
bobjones,bobjones@example.com,Bob Jones,contributor
newuser1,newuser1@example.com,New User,author
admin,admin@example.com,Existing User,administrator
"""
When I try `wp user import-csv users-incorrect.csv --skip-update`
Then STDERR should be:
"""
Error: Missing file: users-incorrect.csv
"""
And the return code should be 1
When I run `wp user import-csv users.csv`
Then STDOUT should not be empty
And an email should not be sent
When I run `wp user list --format=count`
Then STDOUT should be:
"""
3
"""
When I run `wp user list --format=json`
Then STDOUT should be JSON containing:
"""
[{
"user_login":"admin",
"display_name":"Existing User",
"user_email":"admin@example.com",
"roles":"administrator"
}]
"""
Scenario: Import new users on multisite
Given a WP multisite install
And a user-invalid.csv file:
"""
user_login,user_email,display_name,role
bob-jones,bobjones@example.com,Bob Jones,contributor
"""
And a user-valid.csv file:
"""
user_login,user_email,display_name,role
bobjones,bobjones@example.com,Bob Jones,contributor
"""
When I try `wp user import-csv user-invalid.csv`
# Message changed from "Only lowercase..." to "Usernames can contain only lowercase..." in `wpmu_validate_user_signup()` WP 4.4 https://core.trac.wordpress.org/ticket/33336
Then STDERR should contain:
"""
lowercase letters (a-z) and numbers
"""
And the return code should be 0
When I run `wp user import-csv user-valid.csv`
Then STDOUT should not be empty
And an email should not be sent
When I run `wp user get bobjones --field=display_name`
Then STDOUT should be:
"""
Bob Jones
"""
Scenario: Import new users but don't update existing
Given a WP install
And a users.csv file:
"""
user_login,user_email,display_name,role
bobjones,bobjones@example.com,Bob Jones,contributor
newuser1,newuser1@example.com,New User,author
admin,admin@example.com,Existing User,administrator
"""
When I run `wp user create bobjones bobjones@example.com --display_name="Robert Jones" --role=administrator`
Then STDOUT should not be empty
When I run `wp user import-csv users.csv --skip-update --send-email`
Then STDOUT should not be empty
And an email should be sent
When I run `wp user list --format=count`
Then STDOUT should be:
"""
3
"""
When I run `wp user get bobjones --fields=user_login,display_name,user_email,roles --format=json`
Then STDOUT should be JSON containing:
"""
{
"user_login":"bobjones",
"display_name":"Robert Jones",
"user_email":"bobjones@example.com",
"roles":"administrator"
}
"""
Scenario: Import users from a CSV file generated by `wp user list`
Given a WP install
When I run `wp user delete 1 --yes`
And I run `wp user create bobjones bobjones@example.com --display_name="Bob Jones" --role=contributor`
And I run `wp user create billjones billjones@example.com --display_name="Bill Jones" --role=administrator`
And I run `wp user add-role billjones author`
Then STDOUT should not be empty
When I run `wp user list --field=user_login | wc -l | tr -d ' '`
Then STDOUT should be:
"""
2
"""
When I run `wp user list --format=csv > users.csv`
Then the users.csv file should exist
When I run `wp user delete $(wp user list --format=ids) --yes`
Then STDOUT should not be empty
When I run `wp user list --field=user_login | wc -l | tr -d ' '`
Then STDOUT should be:
"""
0
"""
When I run `wp user import-csv users.csv`
Then STDOUT should not be empty
When I run `wp user list --fields=display_name,roles`
Then STDOUT should be a table containing rows:
| display_name | roles |
| Bob Jones | contributor |
| Bill Jones | administrator,author |
@broken
Scenario: Importing users from STDIN
Given a WP install
And a users.csv file:
"""
user_login,user_email,display_name,role
bobjones,bobjones@example.com,Bob Jones,contributor
newuser1,newuser1@example.com,New User,author
admin,admin@example.com,Existing User,administrator
"""
When I try `wp user import-csv -`
Then STDERR should be:
"""
Error: Unable to read content from STDIN.
"""
And the return code should be 1
When I run `cat users.csv | wp user import-csv -`
Then STDOUT should be:
"""
Success: bobjones created.
Success: newuser1 created.
Success: admin updated.
"""
And an email should not be sent
When I run `wp user list --format=count`
Then STDOUT should be:
"""
3
"""
When I run `wp user list --format=json`
Then STDOUT should be JSON containing:
"""
[{
"user_login":"admin",
"display_name":"Existing User",
"user_email":"admin@example.com",
"roles":"administrator"
}]
"""