@@ -23,6 +23,7 @@ export interface PhpunitRunCodeOptions {
2323 projectBootstrap : string
2424 multisite : boolean
2525 databaseType : "sqlite" | "mysql"
26+ managedMultisitePreinstalled ?: boolean
2627 /**
2728 * Sandbox-internal, writable path for the structured diagnostics log. Defaults
2829 * to a /tmp path so diagnostics survive read-only plugin mounts and a mid-install
@@ -466,6 +467,7 @@ $bootstrap_mode = ${JSON.stringify(options.bootstrapMode || "managed")};
466467$project_bootstrap = ${ JSON . stringify ( options . projectBootstrap ) } ;
467468$multisite = ${ JSON . stringify ( options . multisite ) } ;
468469$database_type = ${ JSON . stringify ( options . databaseType ) } ;
470+ $managed_multisite_preinstalled = ${ JSON . stringify ( options . managedMultisitePreinstalled ?? false ) } ;
469471
470472function pg_build_phpunit_argv($raw): array {
471473 $phpunit_argv = array('phpunit');
@@ -1032,6 +1034,36 @@ function pg_run_install_stage(array $cfg) {
10321034 }
10331035}
10341036
1037+ function pg_run_preinstalled_wordpress_stage(array $cfg): void {
1038+ global $argv, $pg_stage_output_buffering, $wp_rewrite;
1039+ pg_stage_begin('install');
1040+ try {
1041+ $config_path = $cfg['config_path'];
1042+ $tests_dir = $cfg['tests_dir'];
1043+ require_once $config_path;
1044+ tests_reset__SERVER();
1045+ $GLOBALS['PHP_SELF'] = '/index.php';
1046+ $_SERVER['PHP_SELF'] = '/index.php';
1047+ tests_add_filter('wp_die_handler', '_wp_die_handler_filter_exit');
1048+ $pg_stage_output_buffering = true;
1049+ ob_start();
1050+ require_once ABSPATH . 'wp-settings.php';
1051+ while (ob_get_level() > 0) {
1052+ @ob_end_clean();
1053+ }
1054+ $pg_stage_output_buffering = false;
1055+ if (is_dir($tests_dir . '/data/themedir1')) {
1056+ register_theme_directory($tests_dir . '/data/themedir1');
1057+ }
1058+ pg_log('NOTICE:using canonical preinstalled multisite schema');
1059+ pg_stage_ok('install');
1060+ } catch (Throwable $e) {
1061+ $pg_stage_output_buffering = false;
1062+ pg_stage_fail('install', $e);
1063+ exit(1);
1064+ }
1065+ }
1066+
10351067function pg_run_load_deps_stage(array $cfg): array {
10361068 pg_stage_begin('load_deps');
10371069 try {
@@ -1261,7 +1293,11 @@ tests_add_filter('muplugins_loaded', function () use ($plugin_slug, $plugin_path
12611293 $deferred_install_init_callbacks = pg_defer_new_wordpress_hook_callbacks('init', $pre_component_init_callbacks);
12621294});
12631295
1264- pg_run_install_stage(array('config_path' => $config_path, 'tests_dir' => $tests_dir, 'multisite' => $multisite));
1296+ if ($managed_multisite_preinstalled) {
1297+ pg_run_preinstalled_wordpress_stage(array('config_path' => $config_path, 'tests_dir' => $tests_dir));
1298+ } else {
1299+ pg_run_install_stage(array('config_path' => $config_path, 'tests_dir' => $tests_dir, 'multisite' => $multisite));
1300+ }
12651301pg_remove_new_wordpress_hook_callbacks('shutdown', $pre_component_shutdown_callbacks);
12661302$pre_dependency_plugins_loaded_callbacks = pg_snapshot_wordpress_hook_callbacks('plugins_loaded');
12671303$pre_dependency_init_callbacks = pg_snapshot_wordpress_hook_callbacks('init');
0 commit comments