Skip to content

Commit 16d46e2

Browse files
committed
Add acceptance tests for multi-statement queries, zero-date imports, and fallback behavior
1 parent 66c44fa commit 16d46e2

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

features/db-import.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,34 @@ Feature: Import a WordPress database
9797
MySQL/MariaDB binary not available, falling back to wpdb for import.
9898
"""
9999

100+
@require-mysql-or-mariadb
101+
Scenario: Database import falls back to wpdb and handles zero-date column defaults
102+
Given a WP install
103+
And a fake-bin/mysql file:
104+
"""
105+
#!/bin/sh
106+
exit 127
107+
"""
108+
And a fake-bin/mariadb file:
109+
"""
110+
#!/bin/sh
111+
exit 127
112+
"""
113+
And a zero_date.sql file:
114+
"""
115+
CREATE TABLE IF NOT EXISTS wp_zero_date_test (
116+
id INT AUTO_INCREMENT PRIMARY KEY,
117+
created_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
118+
);
119+
"""
120+
121+
When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
122+
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db import zero_date.sql --debug`
123+
Then STDOUT should be:
124+
"""
125+
Success: Imported from 'zero_date.sql'.
126+
"""
127+
100128
# SQLite doesn't support the --dbuser flag.
101129
@require-mysql-or-mariadb
102130
Scenario: Import from database name path by default with passed-in dbuser/dbpass

features/db-query.feature

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,44 @@ Feature: Query the database with WordPress' MySQL config
181181
"""
182182
MySQL/MariaDB binary not available, falling back to wpdb.
183183
"""
184+
185+
@require-mysql-or-mariadb
186+
Scenario: Database querying falls back to wpdb for multi-statement queries when mysql binary is unavailable
187+
Given a WP install
188+
And a fake-bin/mysql file:
189+
"""
190+
#!/bin/sh
191+
exit 127
192+
"""
193+
And a fake-bin/mariadb file:
194+
"""
195+
#!/bin/sh
196+
exit 127
197+
"""
198+
199+
When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
200+
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db query "SELECT 1 as num; SELECT 2 as num;" --debug`
201+
Then STDOUT should contain:
202+
"""
203+
num
204+
1
205+
"""
206+
And STDOUT should contain:
207+
"""
208+
num
209+
2
210+
"""
211+
212+
Scenario: Database querying falls back to wpdb when PATH contains no binaries
213+
Given a WP install
214+
215+
When I try `env PATH=/empty_path wp db query "SELECT COUNT(ID) FROM wp_users;" --debug`
216+
Then STDOUT should be:
217+
"""
218+
COUNT(ID)
219+
1
220+
"""
221+
And STDERR should contain:
222+
"""
223+
MySQL/MariaDB binary not available, falling back to wpdb.
224+
"""

0 commit comments

Comments
 (0)