Repository navigation
Expand file tree
/
Copy pathsqlite-storage.feature
More file actions
195 lines (186 loc) · 6.57 KB
/
Copy pathsqlite-storage.feature
File metadata and controls
195 lines (186 loc) · 6.57 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
@require-sqlite
Feature: SQLite database storage
Commands use the same database as WordPress before its database drop-in loads.
Background:
Given a WP installation
Scenario: Use an existing legacy database without migrating storage
Given a SQL dump file named "test_import.sql" with content:
"""
CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO test_table VALUES (1, 'Imported data');
"""
When I run `wp eval 'echo defined( "DB_PATH" ) ? DB_PATH : FQDB;'`
Then save STDOUT as {DATABASE_PATH}
When I run `cp "{DATABASE_PATH}" original.sqlite`
And I run `rm -r wp-content/database`
And I run `mkdir wp-content/database`
And I run `mv original.sqlite wp-content/database/.ht.sqlite`
And I run `wp sqlite export backup.sql`
Then the backup.sql file should contain:
"""
WP CLI Site
"""
When I run `wp sqlite import test_import.sql`
And I run `wp sqlite export -`
Then STDOUT should contain:
"""
Imported data
"""
And the wp-content/database/.ht.sqlite file should exist
And the wp-content/database/db-path.php file should not exist
Scenario: Only import initializes fresh default storage
When I run `wp sqlite export backup.sql`
And I run `rm -r wp-content/database`
And I try `wp sqlite export missing.sql`
Then the return code should be 1
And the missing.sql file should not exist
When I try `wp sqlite tables`
Then the return code should be 1
And the wp-content/database directory should not exist
When I try `wp sqlite import missing.sql`
Then the return code should be 1
And STDERR should contain:
"""
Unable to open file: missing.sql
"""
And the wp-content/database directory should not exist
When I run `mkdir wp-content/database`
And I run `wp sqlite import backup.sql`
Then STDOUT should contain:
"""
Success: Imported from 'backup.sql'.
"""
When I run `wp sqlite tables`
Then STDOUT should contain:
"""
wp_options
"""
When I run `wp eval 'echo get_option( "blogname" );'`
Then STDOUT should be:
"""
WP CLI Site
"""
Scenario: Use DB_PATH without changing existing storage
When I run `wp eval 'echo defined( "DB_PATH" ) ? DB_PATH : FQDB;'`
Then save STDOUT as {DATABASE_PATH}
When I run `mkdir custom-database`
And I run `cp "{DATABASE_PATH}" 'custom-database/custom;database.sqlite'`
And I run `wp config set DB_PATH "dirname( __FILE__ ) . '/custom-database/custom;database.sqlite'" --raw`
And I run `wp sqlite export backup.sql`
And I run `wp sqlite import backup.sql`
Then the custom-database/db-path.php file should not exist
And the custom-database/.htaccess file should not exist
And the custom-database/.ht.sqlite.lock file should not exist
When I run `wp sqlite export -`
Then STDOUT should contain:
"""
WP CLI Site
"""
Scenario: Only import creates a missing explicit database
Given a SQL dump file named "test_import.sql" with content:
"""
CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO test_table VALUES (1, 'Imported data');
"""
When I run `wp config set DB_PATH '{RUN_DIR}/new.sqlite'`
And I try `wp sqlite export backup.sql`
Then the return code should be 1
And STDERR should contain:
"""
The SQLite database does not exist.
"""
And the new.sqlite file should not exist
And the backup.sql file should not exist
When I try `wp sqlite tables`
Then the return code should be 1
And the new.sqlite file should not exist
When I try `wp sqlite import missing.sql`
Then the return code should be 1
And STDERR should contain:
"""
Unable to open file: missing.sql
"""
And the new.sqlite file should not exist
When I run `wp sqlite import test_import.sql`
And I run `wp sqlite tables`
Then STDOUT should contain:
"""
test_table
"""
When I run `wp sqlite export -`
Then STDOUT should contain:
"""
Imported data
"""
Scenario: Use the legacy FQDB override
When I run `wp eval 'echo defined( "DB_PATH" ) ? DB_PATH : FQDB;'`
Then save STDOUT as {DB_PATH}
When I run `cp "{DB_PATH}" custom.sqlite`
And I run `wp config set FQDB '{RUN_DIR}/custom.sqlite'`
And I run `wp sqlite export backup.sql`
And I run `wp sqlite import backup.sql`
And I run `wp eval 'echo get_option( "blogname" );'`
Then STDOUT should be:
"""
WP CLI Site
"""
Scenario: Reject an invalid DB_PATH without falling back to existing storage
Given a SQL dump file named "test_import.sql" with content:
"""
CREATE TABLE test_table (id INTEGER PRIMARY KEY);
"""
When I run `wp config set DB_PATH null --raw`
And I try `wp sqlite import test_import.sql`
Then the return code should be 1
And STDERR should contain:
"""
Error: Could not open the SQLite database:
"""
When I try `wp sqlite export backup.sql`
Then the return code should be 1
And the backup.sql file should not exist
When I try `wp sqlite tables`
Then the return code should be 1
When I run `wp config delete DB_PATH`
And I run `wp sqlite tables`
Then STDOUT should not contain:
"""
test_table
"""
Scenario: Reject an in-memory database
Given a SQL dump file named "test_import.sql" with content:
"""
CREATE TABLE test_table (id INTEGER PRIMARY KEY);
"""
When I run `wp config set DB_PATH ':memory:'`
And I try `wp sqlite import test_import.sql`
Then the return code should be 1
And STDERR should contain:
"""
In-memory databases are not supported.
"""
When I try `wp sqlite export backup.sql`
Then the return code should be 1
And STDERR should contain:
"""
In-memory databases are not supported.
"""
And the backup.sql file should not exist
When I try `wp sqlite tables`
Then the return code should be 1
And STDERR should contain:
"""
In-memory databases are not supported.
"""
Scenario: Report a database that cannot be opened
Given a SQL dump file named "test_import.sql" with content:
"""
CREATE TABLE test_table (id INTEGER PRIMARY KEY);
"""
When I run `wp config set DB_PATH '{RUN_DIR}/missing-directory/database.sqlite'`
And I try `wp sqlite import test_import.sql`
Then the return code should be 1
And STDERR should contain:
"""
Error: Could not open the SQLite database:
"""