|
| 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 `php -r 'echo md5_file( "other.sqlite" );'` |
| 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 `php -r 'echo md5_file( "other.sqlite" );'` |
| 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 | / | |
0 commit comments