-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathdb.feature
328 lines (268 loc) · 8.07 KB
/
db.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
Feature: Perform database operations
Scenario: DB CRUD
Given an empty directory
And WP files
And wp-config.php
And I run `wp config set WP_DEBUG true --type=constant --raw`
And a session_no file:
"""
n
"""
And a session_yes file:
"""
y
"""
When I try `wp option get home`
Then STDOUT should be empty
And STDERR should contain:
"""
(which means your username and password is okay)
"""
When I run `wp db create`
Then STDOUT should be:
"""
Success: Database created.
"""
When I try the previous command again
Then the return code should be 1
When I run `wp db drop --yes`
Then STDOUT should be:
"""
Success: Database dropped.
"""
When I try the previous command again
Then the return code should be 1
When I run `wp db drop < session_no`
# Check for contains only, as the string contains a trailing space.
Then STDOUT should contain:
"""
Are you sure you want to drop the 'wp_cli_test' database? [y/n]
"""
When I run `wp db reset < session_yes`
Then STDOUT should be:
"""
Are you sure you want to reset the 'wp_cli_test' database? [y/n] Success: Database reset.
"""
Scenario: DB CRUD with passed-in dbuser/dbpass
Given an empty directory
And WP files
And wp-config.php
And I run `wp config set WP_DEBUG true --type=constant --raw`
When I try `wp option get home`
Then STDOUT should be empty
And STDERR should contain:
"""
(which means your username and password is okay)
"""
When I run `wp db create --dbuser=wp_cli_test`
Then STDOUT should be:
"""
Success: Database created.
"""
When I try `wp db create --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
When I run `wp db drop --yes --dbpass=password1`
Then STDOUT should be:
"""
Success: Database dropped.
"""
When I try `wp db drop --yes --dbpass=no_such_pass`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
When I run `wp db reset --yes --dbuser=wp_cli_test --dbpass=password1`
Then STDOUT should be:
"""
Success: Database reset.
"""
When I try `wp db reset --yes --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
Scenario: Clean up a WordPress install without dropping its database entirely but tables with prefix.
Given a WP install
When I run `wp db query "create table custom_table as select * from wp_users;"`
Then STDOUT should be empty
And the return code should be 0
When I run `wp db clean --yes --dbuser=wp_cli_test --dbpass=password1`
Then STDOUT should be:
"""
Success: Tables dropped.
"""
When I run `wp core install --title="WP-CLI Test" --url=example.com --admin_user=admin --admin_password=admin --admin_email=admin@example.com`
Then STDOUT should not be empty
When I try `wp db clean --yes --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
When I run `wp db tables custom_table --all-tables`
Then STDOUT should be:
"""
custom_table
"""
And the return code should be 0
Scenario: DB Operations
Given a WP install
When I run `wp db optimize`
Then STDOUT should not be empty
When I run `wp db repair`
Then STDOUT should not be empty
Scenario: DB Operations with passed-in options
Given a WP install
When I run `wp db optimize --dbuser=wp_cli_test`
Then STDOUT should not be empty
When I try `wp db optimize --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
When I try `wp db optimize --verbose`
Then the return code should be 0
And STDOUT should not be empty
When I run `wp db repair --dbpass=password1`
Then STDOUT should not be empty
When I try `wp db repair --dbpass=no_such_pass`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
# Verbose option prints to STDERR.
When I try `wp db repair --verbose`
Then the return code should be 0
And STDERR should contain:
"""
Connecting
"""
And STDOUT should not be empty
Scenario: DB Query
Given a WP install
When I run `wp db query 'SELECT COUNT(*) as total FROM wp_posts'`
Then STDOUT should contain:
"""
total
"""
Given a debug.sql file:
"""
SELECT COUNT(*) as total FROM wp_posts
"""
When I run `wp db query < debug.sql`
Then STDOUT should contain:
"""
total
"""
When I run `wp db query 'SELECT * FROM wp_options WHERE option_name="home"' --skip-column-names`
Then STDOUT should not contain:
"""
option_name
"""
And STDOUT should contain:
"""
home
"""
Scenario: DB export/import
Given a WP install
When I run `wp post list --format=count`
Then STDOUT should be:
"""
1
"""
When I run `wp db export /tmp/wp-cli-behat.sql`
Then STDOUT should contain:
"""
Success: Exported
"""
When I run `wp db export wp-cli-behat.sql --porcelain`
Then STDOUT should be:
"""
wp-cli-behat.sql
"""
When I try `wp db export - --porcelain`
Then STDERR should be:
"""
Error: Porcelain is not allowed when output mode is STDOUT.
"""
When I run `wp db reset --yes`
Then STDOUT should contain:
"""
Success: Database reset.
"""
When I try `wp post list --format=count`
Then STDERR should not be empty
When I run `wp db import /tmp/wp-cli-behat.sql`
Then STDOUT should contain:
"""
Success: Imported
"""
When I run `wp post list --format=count`
Then STDOUT should contain:
"""
1
"""
Scenario: DB export no charset
Given an empty directory
And WP files
When I run `wp core config {CORE_CONFIG_SETTINGS} --dbcharset=""`
Then STDOUT should not be empty
When I run `cat wp-config.php`
Then STDOUT should contain:
"""
define( 'DB_CHARSET', '' );
"""
When I run `wp db create`
Then STDOUT should not be empty
When I run `wp db export /tmp/wp-cli-behat.sql`
Then STDOUT should contain:
"""
Success: Exported
"""
Scenario: Persist DB charset and collation
Given an empty directory
And WP files
When I run `wp core config {CORE_CONFIG_SETTINGS} --dbcharset=latin1 --dbcollate=latin1_spanish_ci`
Then STDOUT should not be empty
When I run `wp db create`
Then STDOUT should not be empty
When I run `wp core install --title="WP-CLI Test" --url=example.com --admin_user=admin --admin_password=admin --admin_email=admin@example.com`
Then STDOUT should not be empty
When I run `wp db query 'SHOW variables LIKE "character_set_database";'`
Then STDOUT should contain:
"""
latin1
"""
When I run `wp db query 'SHOW variables LIKE "collation_database";'`
Then STDOUT should contain:
"""
latin1_spanish_ci
"""
When I run `wp db reset --yes`
Then STDOUT should not be empty
When I run `wp core install --title="WP-CLI Test" --url=example.com --admin_user=admin --admin_password=admin --admin_email=admin@example.com`
Then STDOUT should not be empty
When I run `wp db query 'SHOW variables LIKE "character_set_database";'`
Then STDOUT should contain:
"""
latin1
"""
When I run `wp db query 'SHOW variables LIKE "collation_database";'`
Then STDOUT should contain:
"""
latin1_spanish_ci
"""