Skip to content

Commit 8dc15fb

Browse files
authored
Merge pull request #82 from wp-cli/issue-73-wp_get_table_names
Adjust tests for wp_get_table_names changes.
2 parents 896b270 + f01e40d commit 8dc15fb

File tree

3 files changed

+160
-23
lines changed

3 files changed

+160
-23
lines changed

features/db-search.feature

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ Feature: Search through the database
5757
And STDERR should be empty
5858

5959
When I run `wp db search example.com wp_options wp_not --before_context=0 --after_context=0`
60+
Then STDOUT should contain:
61+
"""
62+
wp_options:option_value
63+
1:example.com
64+
"""
65+
And STDOUT should not contain:
66+
"""
67+
wp_not
68+
"""
69+
And STDOUT should not contain:
70+
"""
71+
pw_options
72+
"""
73+
And STDOUT should not contain:
74+
"""
75+
e_ample.c%m
76+
"""
77+
78+
When I run `wp db search example.com wp_options wp_not --before_context=0 --after_context=0 --all-tables`
6079
Then STDOUT should contain:
6180
"""
6281
wp_options:option_value
@@ -236,23 +255,23 @@ Feature: Search through the database
236255
When I try `wp db search example.com no_such_table`
237256
Then STDERR should be:
238257
"""
239-
Error: No such table 'no_such_table'.
258+
Error: Couldn't find any tables matching: no_such_table
240259
"""
241260
And STDOUT should be empty
242261
And the return code should be 1
243262

244263
When I run `wp db query "CREATE TABLE no_key ( awesome_stuff TEXT );"`
245264
And I run `wp db query "CREATE TABLE no_text ( id int(11) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) );"`
246265

247-
When I try `wp db search example.com no_key`
266+
When I try `wp db search example.com no_key --all-tables`
248267
Then STDOUT should be empty
249268
And STDERR should be:
250269
"""
251270
Warning: No primary key for table 'no_key'. No row ids will be outputted.
252271
"""
253272
And the return code should be 0
254273

255-
When I try `wp db search example.com no_text`
274+
When I try `wp db search example.com no_text --all-tables`
256275
Then STDOUT should be empty
257276
And STDERR should be:
258277
"""
@@ -966,7 +985,7 @@ Feature: Search through the database
966985
When I run `wp db query "SOURCE esc_sql_ident.sql;"`
967986
Then STDERR should be empty
968987

969-
When I run `wp db search 'v_v' TABLE`
988+
When I run `wp db search 'v_v' TABLE --all-tables`
970989
Then STDOUT should be:
971990
"""
972991
TABLE:VALUES

features/db-tables.feature

Lines changed: 135 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ Feature: List database tables
66
When I run `wp db tables`
77
Then STDOUT should contain:
88
"""
9-
wp_users
10-
wp_usermeta
11-
wp_posts
9+
wp_commentmeta
1210
wp_comments
1311
wp_links
1412
wp_options
1513
wp_postmeta
16-
wp_terms
17-
wp_term_taxonomy
14+
wp_posts
1815
wp_term_relationships
16+
wp_term_taxonomy
17+
"""
18+
# Leave out wp_termmeta for old WP compat.
19+
And STDOUT should contain:
20+
"""
21+
wp_terms
22+
wp_usermeta
23+
wp_users
1924
"""
2025

2126
When I run `wp db tables --format=csv`
2227
Then STDOUT should contain:
2328
"""
24-
wp_users,wp_usermeta,wp_posts,wp_comments,
29+
,wp_terms,wp_usermeta,wp_users
2530
"""
2631

2732
When I run `wp db tables 'wp_post*' --format=csv`
@@ -37,33 +42,41 @@ Feature: List database tables
3742
When I run `wp db tables`
3843
Then STDOUT should contain:
3944
"""
40-
wp_users
41-
wp_usermeta
42-
wp_posts
45+
wp_blog_versions
46+
wp_blogs
47+
wp_commentmeta
4348
wp_comments
4449
wp_links
4550
wp_options
4651
wp_postmeta
47-
wp_terms
48-
wp_term_taxonomy
52+
wp_posts
53+
wp_registration_log
54+
wp_signups
55+
wp_site
56+
wp_sitemeta
4957
wp_term_relationships
58+
wp_term_taxonomy
5059
"""
60+
# Leave out wp_termmeta for old WP compat.
5161
And STDOUT should contain:
5262
"""
53-
wp_blogs
54-
wp_signups
55-
wp_site
56-
wp_sitemeta
57-
wp_registration_log
58-
wp_blog_versions
63+
wp_terms
64+
wp_usermeta
65+
wp_users
5966
"""
6067

6168
When I run `wp site create --slug=foo`
6269
And I run `wp db tables --url=example.com/foo`
6370
Then STDOUT should contain:
6471
"""
6572
wp_users
73+
"""
74+
And STDOUT should contain:
75+
"""
6676
wp_usermeta
77+
"""
78+
And STDOUT should contain:
79+
"""
6780
wp_2_posts
6881
"""
6982

@@ -130,3 +143,108 @@ Feature: List database tables
130143
"""
131144
wp_21_posts
132145
"""
146+
147+
Scenario: List database tables with wildcards on a single WordPress install with custom table prefix
148+
Given a WP install
149+
And "$table_prefix = 'wp_';" replaced with "$table_prefix = 'as_wp_';" in the wp-config.php file
150+
And I try `wp core install --url=example.com --title=example --admin_user=wpcli --admin_email=wpcli@example.com`
151+
Then STDOUT should contain:
152+
"""
153+
Success:
154+
"""
155+
And the return code should be 0
156+
157+
When I run `wp db tables '*_posts'`
158+
Then STDOUT should be:
159+
"""
160+
as_wp_posts
161+
"""
162+
163+
When I run `wp db tables '*_posts' --network`
164+
Then STDOUT should be:
165+
"""
166+
as_wp_posts
167+
"""
168+
169+
When I run `wp db tables '*_posts' --scope=blog`
170+
Then STDOUT should be:
171+
"""
172+
as_wp_posts
173+
"""
174+
175+
When I try `wp db tables '*_posts' --scope=global`
176+
Then STDERR should not be empty
177+
And STDOUT should be empty
178+
And the return code should be 1
179+
180+
When I run `wp db tables '*_users' --scope=global`
181+
Then STDOUT should be:
182+
"""
183+
as_wp_users
184+
"""
185+
186+
Scenario: List database tables with wildcards on a multisite WordPress install with custom table prefix
187+
Given a WP multisite install
188+
And "$table_prefix = 'wp_';" replaced with "$table_prefix = 'as_wp_';" in the wp-config.php file
189+
# Use try to cater for wp-db errors in old WPs.
190+
And I try `wp core multisite-install --url=example.com --title=example --admin_user=wpcli --admin_email=wpcli@example.com`
191+
Then STDOUT should contain:
192+
"""
193+
Success:
194+
"""
195+
And the return code should be 0
196+
And I run `wp site create --slug=foo`
197+
198+
When I run `wp db tables '*_posts'`
199+
Then STDOUT should be:
200+
"""
201+
as_wp_posts
202+
"""
203+
204+
When I run `wp db tables '*_posts' --url=example.com/foo`
205+
Then STDOUT should be:
206+
"""
207+
as_wp_2_posts
208+
"""
209+
210+
When I run `wp db tables '*_posts' --network`
211+
Then STDOUT should be:
212+
"""
213+
as_wp_2_posts
214+
as_wp_posts
215+
"""
216+
217+
When I run `wp db tables '*_posts' --scope=blog`
218+
Then STDOUT should be:
219+
"""
220+
as_wp_posts
221+
"""
222+
223+
When I run `wp db tables '*_posts' --scope=blog --network`
224+
Then STDOUT should be:
225+
"""
226+
as_wp_2_posts
227+
as_wp_posts
228+
"""
229+
230+
When I try `wp db tables '*_posts' --scope=global`
231+
Then STDERR should not be empty
232+
And STDOUT should be empty
233+
And the return code should be 1
234+
235+
When I try `wp db tables '*_posts' --scope=global --network`
236+
Then STDERR should not be empty
237+
And STDOUT should be empty
238+
And the return code should be 1
239+
240+
When I run `wp db tables '*_users' --scope=global`
241+
Then STDOUT should be:
242+
"""
243+
as_wp_users
244+
"""
245+
246+
When I run `wp db tables '*_users' --scope=global --network`
247+
Then STDOUT should be:
248+
"""
249+
as_wp_users
250+
"""

src/DB_Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public function import( $args, $assoc_args ) {
517517
* : Can be all, global, ms_global, blog, or old tables. Defaults to all.
518518
*
519519
* [--network]
520-
* : List all the tables in a multisite install. Overrides --scope=<scope>.
520+
* : List all the tables in a multisite install.
521521
*
522522
* [--all-tables-with-prefix]
523523
* : List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.
@@ -611,7 +611,7 @@ public function tables( $args, $assoc_args ) {
611611
* : Can be all, global, ms_global, blog, or old tables. Defaults to all.
612612
*
613613
* [--network]
614-
* : List all the tables in a multisite install. Overrides --scope=<scope>.
614+
* : List all the tables in a multisite install.
615615
*
616616
* [--all-tables-with-prefix]
617617
* : List all tables that match the table prefix even if not registered on $wpdb. Overrides --network.

0 commit comments

Comments
 (0)