|
| 1 | +@require-sqlite |
| 2 | +Feature: SQLite database storage |
| 3 | + Commands use the same database as WordPress before its database drop-in loads. |
| 4 | + |
| 5 | + Background: |
| 6 | + Given a WP installation |
| 7 | + |
| 8 | + Scenario: Use an existing legacy database without migrating storage |
| 9 | + Given a SQL dump file named "test_import.sql" with content: |
| 10 | + """ |
| 11 | + CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT); |
| 12 | + INSERT INTO test_table VALUES (1, 'Imported data'); |
| 13 | + """ |
| 14 | + When I run `wp eval 'echo FQDB;'` |
| 15 | + Then save STDOUT as {DATABASE_PATH} |
| 16 | + When I run `cp "{DATABASE_PATH}" original.sqlite` |
| 17 | + And I run `rm -r wp-content/database` |
| 18 | + And I run `mkdir wp-content/database` |
| 19 | + And I run `mv original.sqlite wp-content/database/.ht.sqlite` |
| 20 | + And I run `wp sqlite export backup.sql` |
| 21 | + Then the backup.sql file should contain: |
| 22 | + """ |
| 23 | + WP CLI Site |
| 24 | + """ |
| 25 | + When I run `wp sqlite import test_import.sql` |
| 26 | + And I run `wp sqlite export -` |
| 27 | + Then STDOUT should contain: |
| 28 | + """ |
| 29 | + Imported data |
| 30 | + """ |
| 31 | + And the wp-content/database/.ht.sqlite file should exist |
| 32 | + And the wp-content/database/db-path.php file should not exist |
| 33 | + |
| 34 | + Scenario: Only import initializes fresh default storage |
| 35 | + When I run `wp sqlite export backup.sql` |
| 36 | + And I run `rm -r wp-content/database` |
| 37 | + And I try `wp sqlite export missing.sql` |
| 38 | + Then the return code should be 1 |
| 39 | + And the missing.sql file should not exist |
| 40 | + When I try `wp sqlite tables` |
| 41 | + Then the return code should be 1 |
| 42 | + And the wp-content/database directory should not exist |
| 43 | + When I run `mkdir wp-content/database` |
| 44 | + And I run `wp sqlite import backup.sql` |
| 45 | + Then STDOUT should contain: |
| 46 | + """ |
| 47 | + Success: Imported from 'backup.sql'. |
| 48 | + """ |
| 49 | + When I run `wp sqlite tables` |
| 50 | + Then STDOUT should contain: |
| 51 | + """ |
| 52 | + wp_options |
| 53 | + """ |
| 54 | + When I run `wp eval 'echo get_option( "blogname" );'` |
| 55 | + Then STDOUT should be: |
| 56 | + """ |
| 57 | + WP CLI Site |
| 58 | + """ |
| 59 | + |
| 60 | + Scenario: Use DB_PATH without changing existing storage |
| 61 | + When I run `wp eval 'echo FQDB;'` |
| 62 | + Then save STDOUT as {DATABASE_PATH} |
| 63 | + When I run `mkdir custom-database` |
| 64 | + And I run `cp "{DATABASE_PATH}" 'custom-database/custom;database.sqlite'` |
| 65 | + And I run `wp config set DB_PATH "dirname( __FILE__ ) . '/custom-database/custom;database.sqlite'" --raw` |
| 66 | + And I run `wp sqlite export backup.sql` |
| 67 | + And I run `wp sqlite import backup.sql` |
| 68 | + Then the custom-database/db-path.php file should not exist |
| 69 | + And the custom-database/.htaccess file should not exist |
| 70 | + And the custom-database/.ht.sqlite.lock file should not exist |
| 71 | + When I run `wp sqlite export -` |
| 72 | + Then STDOUT should contain: |
| 73 | + """ |
| 74 | + WP CLI Site |
| 75 | + """ |
| 76 | + |
| 77 | + Scenario: Only import creates a missing explicit database |
| 78 | + Given a SQL dump file named "test_import.sql" with content: |
| 79 | + """ |
| 80 | + CREATE TABLE test_table (id INTEGER PRIMARY KEY, name TEXT); |
| 81 | + INSERT INTO test_table VALUES (1, 'Imported data'); |
| 82 | + """ |
| 83 | + When I run `wp config set DB_PATH '{RUN_DIR}/new.sqlite'` |
| 84 | + And I try `wp sqlite export backup.sql` |
| 85 | + Then the return code should be 1 |
| 86 | + And STDERR should contain: |
| 87 | + """ |
| 88 | + The SQLite database does not exist. |
| 89 | + """ |
| 90 | + And the new.sqlite file should not exist |
| 91 | + And the backup.sql file should not exist |
| 92 | + When I try `wp sqlite tables` |
| 93 | + Then the return code should be 1 |
| 94 | + And the new.sqlite file should not exist |
| 95 | + When I run `wp sqlite import test_import.sql` |
| 96 | + And I run `wp sqlite tables` |
| 97 | + Then STDOUT should contain: |
| 98 | + """ |
| 99 | + test_table |
| 100 | + """ |
| 101 | + When I run `wp sqlite export -` |
| 102 | + Then STDOUT should contain: |
| 103 | + """ |
| 104 | + Imported data |
| 105 | + """ |
| 106 | + |
| 107 | + Scenario: Use the legacy FQDB override |
| 108 | + When I run `wp eval 'echo FQDB;'` |
| 109 | + Then save STDOUT as {DB_PATH} |
| 110 | + When I run `cp "{DB_PATH}" custom.sqlite` |
| 111 | + And I run `wp config set FQDB '{RUN_DIR}/custom.sqlite'` |
| 112 | + And I run `wp sqlite export backup.sql` |
| 113 | + And I run `wp sqlite import backup.sql` |
| 114 | + When I run `wp eval 'echo get_option( "blogname" );'` |
| 115 | + Then STDOUT should be: |
| 116 | + """ |
| 117 | + WP CLI Site |
| 118 | + """ |
| 119 | + |
| 120 | + Scenario: Reject an invalid DB_PATH without falling back to existing storage |
| 121 | + Given a SQL dump file named "test_import.sql" with content: |
| 122 | + """ |
| 123 | + CREATE TABLE test_table (id INTEGER PRIMARY KEY); |
| 124 | + """ |
| 125 | + When I run `wp config set DB_PATH null --raw` |
| 126 | + And I try `wp sqlite import test_import.sql` |
| 127 | + Then the return code should be 1 |
| 128 | + And STDERR should contain: |
| 129 | + """ |
| 130 | + Error: Could not open the SQLite database: |
| 131 | + """ |
| 132 | + When I try `wp sqlite export backup.sql` |
| 133 | + Then the return code should be 1 |
| 134 | + And the backup.sql file should not exist |
| 135 | + When I try `wp sqlite tables` |
| 136 | + Then the return code should be 1 |
| 137 | + When I run `wp config delete DB_PATH` |
| 138 | + And I run `wp sqlite tables` |
| 139 | + Then STDOUT should not contain: |
| 140 | + """ |
| 141 | + test_table |
| 142 | + """ |
0 commit comments