-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathdb-query.feature
More file actions
137 lines (114 loc) · 4.19 KB
/
db-query.feature
File metadata and controls
137 lines (114 loc) · 4.19 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
Feature: Query the database with WordPress' MySQL config
Scenario: Database querying shouldn't load any plugins
Given a WP install
And a wp-content/mu-plugins/error.php file:
"""
<?php
WP_CLI::error( "Plugin loaded." );
"""
When I try `wp option get home`
Then STDERR should be:
"""
Error: Plugin loaded.
"""
When I run `wp db query "SELECT COUNT(ID) FROM wp_users;"`
Then STDOUT should be:
"""
COUNT(ID)
1
"""
# SQLite doesn't support the --html option nor different dbuser.
@require-mysql-or-mariadb
Scenario: Database querying with passed-in options
Given a WP install
When I run `wp db query "SELECT COUNT(ID) FROM wp_posts;" --dbuser=wp_cli_test --html`
Then STDOUT should contain:
"""
<TABLE
"""
When I try `wp db query "SELECT COUNT(ID) FROM wp_posts;" --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
# SQLite doesn't support the --html option nor different dbuser.
@require-mysql-or-mariadb
Scenario: Database querying with MySQL defaults and passed-in options
Given a WP install
When I run `wp db query --defaults "SELECT COUNT(ID) FROM wp_posts;" --dbuser=wp_cli_test --html`
Then STDOUT should contain:
"""
<TABLE
"""
When I try `wp db query --defaults "SELECT COUNT(ID) FROM wp_posts;" --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
# SQLite doesn't support the --html option nor different dbuser.
@require-mysql-or-mariadb
Scenario: Database querying with --nodefaults and passed-in options
Given a WP install
When I run `wp db query --no-defaults "SELECT COUNT(ID) FROM wp_posts;" --dbuser=wp_cli_test --html`
Then STDOUT should contain:
"""
<TABLE
"""
When I try `wp db query --no-defaults "SELECT COUNT(ID) FROM wp_posts;" --dbuser=no_such_user`
Then the return code should not be 0
And STDERR should contain:
"""
Access denied
"""
And STDOUT should be empty
@require-mysql-or-mariadb
Scenario: MySQL defaults are available as appropriate with --defaults flag
Given a WP install
When I try `wp db query --defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-auto-rehash#
When I try `wp db query --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
When I try `wp db query --no-defaults --debug`
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
Scenario: SQL mode discovery respects --defaults flag
Given a WP install
When I try `wp db query "SELECT 1;" --defaults --debug`
Then STDERR should match #Running shell command: /usr/bin/env (mysql|mariadb) --no-auto-rehash#
And STDERR should not match #Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults#
When I try `wp db query "SELECT 1;" --debug`
Then STDERR should match #Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
Scenario: SQL mode discovery preserves MySQL connection arguments
Given a WP install
When I try `wp db query "SELECT 1;" --host=testhost --port=3307 --debug`
Then STDERR should match #Running shell command: .* --host=testhost.*--port=3307#
Scenario: SQL modes do not include any of the modes incompatible with WordPress
Given a WP install
When I try `wp db query 'SELECT @@SESSION.sql_mode;' --debug`
Then STDOUT should not contain:
"""
NO_ZERO_DATE
"""
And STDOUT should not contain:
"""
ONLY_FULL_GROUP_BY
"""
And STDOUT should not contain:
"""
STRICT_TRANS_TABLES
"""
And STDOUT should not contain:
"""
STRICT_ALL_TABLES
"""
And STDOUT should not contain:
"""
TRADITIONAL
"""
And STDOUT should not contain:
"""
ANSI
"""