-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathdb.feature
More file actions
509 lines (425 loc) · 12 KB
/
db.feature
File metadata and controls
509 lines (425 loc) · 12 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
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
Feature: Perform database operations
@skip-sqlite
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.
"""
@skip-sqlite
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
@skip-sqlite
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
@skip-sqlite
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
@skip-sqlite
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
@skip-sqlite
Scenario: db repair with --quiet flag should only show errors
Given a WP install
When I run `wp db repair --quiet`
Then STDOUT should not contain:
"""
error
"""
@skip-sqlite
Scenario: db repair can explicitly pass --silent to mysqlcheck
Given a WP install
When I run `wp db repair --silent`
Then STDOUT should not contain:
"""
error
"""
And STDOUT should contain:
"""
Success: Database repaired.
"""
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
"""
Scenario: DB Query with --skip-column-names
Given a WP install
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
"""
@skip-sqlite
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
"""
@skip-sqlite
Scenario: DB export no charset
Given an empty directory
And WP files
When I run `wp config create {CORE_CONFIG_SETTINGS} --dbcharset="" --skip-check`
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
"""
@skip-sqlite
Scenario: Persist DB charset and collation
Given an empty directory
And WP files
When I run `wp config create {CORE_CONFIG_SETTINGS} --dbcharset=latin1 --dbcollate=latin1_spanish_ci --skip-check`
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
"""
@skip-sqlite
Scenario: Row modifying queries should return the number of affected rows
Given a WP install
When I run `wp db query "UPDATE wp_users SET user_status = 1 WHERE ID = 1"`
Then STDOUT should contain:
"""
Query succeeded. Rows affected: 1
"""
When I run `wp db query "SELECT * FROM wp_users WHERE ID = 1"`
Then STDOUT should not contain:
"""
Rows affected
"""
When I run `wp db query "DELETE FROM wp_users WHERE ID = 1"`
Then STDOUT should contain:
"""
Query succeeded. Rows affected: 1
"""
@require-mysql-or-mariadb
Scenario: Database drop falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""
When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db drop --yes --debug`
Then STDOUT should contain:
"""
Success: Database dropped.
"""
And STDERR should contain:
"""
Query via wpdb:
"""
@require-mysql-or-mariadb
Scenario: Database reset falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""
When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db reset --yes --debug`
Then STDOUT should contain:
"""
Success: Database reset.
"""
And STDERR should contain:
"""
Query via wpdb:
"""
@require-sqlite
Scenario: SQLite DB CRUD operations
Given a WP install
And a session_yes file:
"""
y
"""
When I try `wp db create`
Then the return code should be 1
And STDERR should contain:
"""
Database already exists
"""
When I run `wp db drop < session_yes`
Then STDOUT should contain:
"""
Success: Database dropped.
"""
When I run `wp db reset < session_yes`
Then STDOUT should contain:
"""
Success: Database reset
"""
@require-sqlite
Scenario: SQLite DB query
Given a WP install
When I run `wp db query 'SELECT COUNT(*) as total FROM wp_posts'`
Then STDOUT should contain:
"""
total
"""
@require-sqlite
Scenario: SQLite DB export/import
Given a WP install
And a session_yes file:
"""
y
"""
When I run `wp post list --format=count`
Then STDOUT should contain:
"""
1
"""
When I run `wp db export /tmp/wp-cli-sqlite-behat.sql`
Then STDOUT should contain:
"""
Success: Exported
"""
When I run `wp db reset < session_yes`
Then STDOUT should contain:
"""
Success: Database reset
"""
When I run `wp db import /tmp/wp-cli-sqlite-behat.sql`
Then STDOUT should contain:
"""
Success: Imported
"""
When I run `wp post list --format=count`
Then STDOUT should contain:
"""
1
"""