124124 if ( 'default-native ' !== $ scenario ) {
125125 mkdir ( $ database_dir , 0755 , true );
126126 }
127- if ( in_array ( $ scenario , array ( 'default-legacy-sqlite ' , 'default-legacy-php ' , 'default-db-dir ' , 'default-fqdbdir ' , 'default-missing-db-path ' , 'default-missing-fqdb ' , 'default-missing-db-file ' , 'default-interrupted-migration ' , 'mdi-native ' , 'mysql-content ' , 'mysql-full ' ), true ) ) {
128- file_put_contents ( $ database_dir . ( 'default-legacy-php ' === $ scenario ? '/.ht.sqlite.php ' : '/.ht.sqlite ' ), 'legacy database ' );
127+ if ( in_array ( $ scenario , array ( 'default-legacy-sqlite ' , 'default-db-dir ' , 'default-fqdbdir ' , 'default-missing-db-path ' , 'default-missing-fqdb ' , 'default-missing-db-file ' , 'default-interrupted-migration ' , 'mdi-native ' , 'mysql-content ' , 'mysql-full ' ), true ) ) {
128+ file_put_contents ( $ database_dir . '/.ht.sqlite ' , "SQLite format 3 \0" . str_repeat ( "\0" , 16 ) );
129+ $ expected_backend = 'sqlite ' ;
130+ }
131+ if ( 'default-legacy-php ' === $ scenario ) {
132+ file_put_contents ( $ database_dir . '/.ht.sqlite.php ' , "SQLite format 3 \0" . str_repeat ( "\0" , 16 ) );
129133 $ expected_backend = 'sqlite ' ;
130134 }
131135 if ( in_array ( $ scenario , array ( 'default-randomized ' , 'default-missing-recorded ' , 'default-interrupted-migration ' ), true ) ) {
137141 file_put_contents ( $ recorded , 'managed database ' );
138142 }
139143 }
144+ if ( 'default-empty-ht ' === $ scenario || 'default-nonsqlite-ht ' === $ scenario ) {
145+ file_put_contents ( $ database_dir . '/.ht.sqlite ' , 'default-empty-ht ' === $ scenario ? '' : 'not sqlite ' );
146+ }
140147 if ( 'default-unread-metadata ' === $ scenario ) {
141148 file_put_contents ( $ database_dir . '/db-path.php ' , '<?php throw new RuntimeException( "Detection read metadata." ); ' );
142149 $ expected_backend = 'sqlite ' ;
143150 }
144- if ( in_array ( $ scenario , array ( 'default-db-path ' , 'default-conflicting-paths ' , 'default-fqdb ' , 'default-db-file ' ), true ) ) {
151+ if ( in_array ( $ scenario , array ( 'default-db-path ' , 'default-conflicting-paths ' , 'default-fqdb ' , 'default-db-file ' , ' default-empty-fqdb ' ), true ) ) {
145152 $ constant = match ( $ scenario ) {
146- 'default-fqdb ' => 'FQDB ' ,
153+ 'default-fqdb ' , ' default-empty-fqdb ' => 'FQDB ' ,
147154 'default-db-file ' => 'DB_FILE ' ,
148155 default => 'DB_PATH ' ,
149156 };
150157 define ( $ constant , 'DB_FILE ' === $ constant ? 'custom.sqlite ' : $ database_dir . '/custom.sqlite ' );
151- file_put_contents ( $ database_dir . '/custom.sqlite ' , 'configured database ' );
152- $ expected_backend = 'sqlite ' ;
158+ file_put_contents ( $ database_dir . '/custom.sqlite ' , 'default-empty-fqdb ' === $ scenario ? '' : " SQLite format 3 \0" . str_repeat ( "\0" , 16 ) );
159+ $ expected_backend = 'default-empty-fqdb ' === $ scenario ? ' mdi-native ' : ' sqlite ' ;
153160 if ( 'default-conflicting-paths ' === $ scenario ) {
154161 define ( 'FQDB ' , $ database_dir . '/missing.sqlite ' );
155162 }
179186 if ( 'mysql-content ' === $ scenario ) {
180187 define ( 'MARKDOWN_DB_BACKEND ' , 'mysql-content ' );
181188 }
182- if ( 'unknown ' === $ scenario ) {
189+ if ( 'explicit-empty-sqlite ' === $ scenario ) {
190+ define ( 'MARKDOWN_DB_BACKEND ' , 'sqlite ' );
191+ file_put_contents ( $ database_dir . '/.ht.sqlite ' , '' );
192+ $ storage_before = $ snapshot ();
193+ } elseif ( 'unknown ' === $ scenario ) {
183194 define ( 'MARKDOWN_DB_BACKEND ' , 'unknown ' );
184195 } elseif ( 'incomplete ' === $ scenario ) {
185196 define ( 'MARKDOWN_DB_BACKEND ' , 'incomplete ' );
@@ -297,7 +308,7 @@ class wpdb { public string $prefix = 'wp_'; public string $base_prefix = 'wp_';
297308 echo "PASS: {$ scenario } explicitly falls back to stock wpdb. \n" ;
298309 exit ( 0 );
299310 }
300- if ( 'sqlite ' !== $ scenario || ! isset ( $ GLOBALS ['wpdb ' ] ) ) {
311+ if ( ! in_array ( $ scenario , array ( 'sqlite ' , ' explicit-empty-sqlite ' ), true ) || ! isset ( $ GLOBALS ['wpdb ' ] ) ) {
301312 throw new RuntimeException ( 'Expected backend bootstrap failure. ' );
302313 }
303314 echo "PASS: an explicitly configured SQLite backend keeps the SQLite drop-in path. \n" ;
@@ -317,7 +328,7 @@ class wpdb { public string $prefix = 'wp_'; public string $base_prefix = 'wp_';
317328}
318329
319330$ failed = 0 ;
320- foreach ( array ( 'sqlite ' , 'primary-cold-index ' , 'primary-warm-index ' , 'default-native ' , 'default-legacy-sqlite ' , 'default-legacy-php ' , 'default-db-dir ' , 'default-fqdbdir ' , 'default-randomized ' , 'default-missing-recorded ' , 'default-interrupted-migration ' , 'default-unread-metadata ' , 'default-db-path ' , 'default-fqdb ' , 'default-db-file ' , 'default-conflicting-paths ' , 'default-missing-db-path ' , 'default-missing-fqdb ' , 'default-missing-db-file ' , 'mdi-native ' , 'mysql-content ' , 'mysql-full ' , 'mysql-full-shadow ' , 'mysql-full-no-sink ' , 'mysql-full-prior-outbox ' , 'mysql-full-incompatible ' , 'mysql-full-outbox-incompatible ' , 'unknown ' , 'incomplete ' ) as $ scenario ) {
331+ foreach ( array ( 'sqlite ' , 'explicit-empty-sqlite ' , ' default-empty-ht ' , ' default-nonsqlite-ht ' , ' default-empty-fqdb ' , ' primary-cold-index ' , 'primary-warm-index ' , 'default-native ' , 'default-legacy-sqlite ' , 'default-legacy-php ' , 'default-db-dir ' , 'default-fqdbdir ' , 'default-randomized ' , 'default-missing-recorded ' , 'default-interrupted-migration ' , 'default-unread-metadata ' , 'default-db-path ' , 'default-fqdb ' , 'default-db-file ' , 'default-conflicting-paths ' , 'default-missing-db-path ' , 'default-missing-fqdb ' , 'default-missing-db-file ' , 'mdi-native ' , 'mysql-content ' , 'mysql-full ' , 'mysql-full-shadow ' , 'mysql-full-no-sink ' , 'mysql-full-prior-outbox ' , 'mysql-full-incompatible ' , 'mysql-full-outbox-incompatible ' , 'unknown ' , 'incomplete ' ) as $ scenario ) {
321332 passthru ( escapeshellarg ( PHP_BINARY ) . ' ' . escapeshellarg ( __FILE__ ) . ' ' . escapeshellarg ( $ scenario ), $ status );
322333 if ( 0 !== $ status ) {
323334 ++$ failed ;
0 commit comments