|
| 1 | +@require-sqlite |
| 2 | +Feature: Select the configured SQLite database for file operations |
| 3 | + |
| 4 | + Scenario Outline: Use the effective database path without changing another database |
| 5 | + Given a WP install |
| 6 | + When I run `wp eval 'copy( defined( "DB_PATH" ) ? DB_PATH : FQDB, "selected.sqlite" ); copy( "selected.sqlite", "other.sqlite" );'` |
| 7 | + And I run `sqlite3 selected.sqlite "CREATE TABLE path_marker (value TEXT); INSERT INTO path_marker VALUES ('selected');"` |
| 8 | + And I run `sqlite3 other.sqlite "CREATE TABLE path_marker (value TEXT); INSERT INTO path_marker VALUES ('other');"` |
| 9 | + |
| 10 | + Given a paths.php file: |
| 11 | + """ |
| 12 | + <?php |
| 13 | + if ( '' !== '<db_path>' ) { |
| 14 | + define( 'DB_PATH', __DIR__ . '/<db_path>' ); |
| 15 | + } |
| 16 | + if ( '' !== '<fqdb>' ) { |
| 17 | + define( 'FQDB', __DIR__ . '/<fqdb>' ); |
| 18 | + } |
| 19 | + if ( '' !== '<db_dir>' ) { |
| 20 | + define( 'DB_DIR', __DIR__ . '/<db_dir>' ); |
| 21 | + } |
| 22 | + if ( '' !== '<db_file>' ) { |
| 23 | + define( 'DB_FILE', '<db_file>' ); |
| 24 | + } |
| 25 | + if ( '' !== '<fqdbdir>' ) { |
| 26 | + define( 'FQDBDIR', __DIR__ . '/<fqdbdir>' ); |
| 27 | + } |
| 28 | + """ |
| 29 | + When I run `wp config set path_constants "require __DIR__ . '/paths.php'" --type=variable --raw` |
| 30 | + And I try `wp eval 'echo "ready";'` |
| 31 | + Then the return code should be 0 |
| 32 | + |
| 33 | + When I run `wp eval 'echo md5_file( "other.sqlite" );' --skip-wordpress` |
| 34 | + Then save STDOUT as {OTHER_HASH} |
| 35 | + |
| 36 | + When I try `wp db export selected.sql` |
| 37 | + Then the return code should be 0 |
| 38 | + And the selected.sql file should contain: |
| 39 | + """ |
| 40 | + INSERT INTO path_marker VALUES('selected'); |
| 41 | + """ |
| 42 | + And the selected.sql file should not contain: |
| 43 | + """ |
| 44 | + INSERT INTO path_marker VALUES('other'); |
| 45 | + """ |
| 46 | + |
| 47 | + When I try `wp db drop --yes` |
| 48 | + Then the return code should be 0 |
| 49 | + And the selected.sqlite file should not exist |
| 50 | + |
| 51 | + When I run `wp eval 'echo md5_file( "other.sqlite" );' --skip-wordpress` |
| 52 | + Then STDOUT should be: |
| 53 | + """ |
| 54 | + {OTHER_HASH} |
| 55 | + """ |
| 56 | + |
| 57 | + Examples: |
| 58 | + | db_path | fqdb | db_dir | db_file | fqdbdir | |
| 59 | + | selected.sqlite | other.sqlite | other | other.sqlite | other/ | |
| 60 | + | selected.sqlite | selected.sqlite | / | selected.sqlite | / | |
| 61 | + | | selected.sqlite | | | | |
| 62 | + | | | | selected.sqlite | / | |
| 63 | + |
| 64 | + Scenario Outline: Reject file operations on an in-memory SQLite database |
| 65 | + Given a WP install |
| 66 | + And an input.sql file: |
| 67 | + """ |
| 68 | + SELECT 1; |
| 69 | + """ |
| 70 | + When I run `wp config set <constant> :memory:` |
| 71 | + And I run `wp db query "SELECT 1 AS value" --skip-column-names` |
| 72 | + Then STDOUT should be: |
| 73 | + """ |
| 74 | + 1 |
| 75 | + """ |
| 76 | + |
| 77 | + When I try `wp db <command>` |
| 78 | + Then the return code should be 1 |
| 79 | + And STDERR should be: |
| 80 | + """ |
| 81 | + Error: This command does not support in-memory SQLite databases. |
| 82 | + """ |
| 83 | + And STDOUT should be empty |
| 84 | + |
| 85 | + Examples: |
| 86 | + | constant | command | |
| 87 | + | DB_PATH | create | |
| 88 | + | DB_PATH | drop --yes | |
| 89 | + | DB_PATH | reset --yes | |
| 90 | + | DB_PATH | export output.sql | |
| 91 | + | DB_PATH | import input.sql | |
| 92 | + | FQDB | create | |
| 93 | + | FQDB | drop --yes | |
| 94 | + | FQDB | reset --yes | |
| 95 | + | FQDB | export output.sql | |
| 96 | + | FQDB | import input.sql | |
0 commit comments