From c5f28f8758dc4833b8e312fbd55cee7f1d962580 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 30 Oct 2026 19:12:27 +0100 Subject: [PATCH 1/2] Cache multisite installations like single site installations Co-Authored-By: Claude Opus 5.5 --- features/behat-steps.feature | 46 ++++++++++++++++++++++++++++ src/Context/FeatureContext.php | 13 ++++++-- src/Context/GivenStepDefinitions.php | 10 +----- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 1620e011..81990646 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -498,6 +498,52 @@ Feature: Test that WP-CLI Behat steps work as expected When I run `wp core is-installed --network` Then the return code should be 0 + @require-wp + Scenario: Create a site on a cached multisite subdomain installation + Given a WP multisite subdomain installation + When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'` + Then STDOUT should be: + """ + subdomain + """ + + When I run `wp eval 'wp_insert_site( [ "domain" => "first.example.com", "path" => "/" ] );'` + And I run `wp eval 'echo get_sites( [ "count" => true ] );'` + Then STDOUT should be: + """ + 2 + """ + + @require-wp + Scenario: Restore a cached multisite subdirectory installation + Given a WP multisite subdirectory installation + When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'` + Then STDOUT should be: + """ + subdirectory + """ + + When I run `wp eval 'echo get_sites( [ "count" => true ] );'` + Then STDOUT should be: + """ + 1 + """ + + @require-wp + Scenario: Restore a cached multisite subdomain installation without earlier changes + Given a WP multisite subdomain installation + When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'` + Then STDOUT should be: + """ + subdomain + """ + + When I run `wp eval 'echo get_sites( [ "count" => true ] );'` + Then STDOUT should be: + """ + 1 + """ + @require-wp Scenario: Test misconfigured WP_CONTENT_DIR Given a WP installation diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index ba8ae9f5..99b8cda2 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1913,8 +1913,9 @@ public function create_config( $subdir = '', $extra_php = false ): void { /** * @param string $subdir * @param string $version + * @param string $network Multisite type to install on top, either 'subdirectory' or 'subdomain'. Empty for a single site. */ - public function install_wp( $subdir = '', $version = '' ): void { + public function install_wp( $subdir = '', $version = '', $network = '' ): void { $wp_version = $version ?: getenv( 'WP_VERSION' ); $wp_version_suffix = $wp_version ? "-$wp_version" : ''; self::$install_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-install-cache' . $wp_version_suffix; @@ -1951,7 +1952,7 @@ public function install_wp( $subdir = '', $version = '' ): void { $run_dir = '' !== $subdir ? ( $this->variables['RUN_DIR'] . "/$subdir" ) : $this->variables['RUN_DIR']; - $install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir . ':object_cache=' . getenv( 'WP_CLI_TEST_OBJECT_CACHE' ) ); + $install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir . ':object_cache=' . getenv( 'WP_CLI_TEST_OBJECT_CACHE' ) . ( $network ? ':network=' . $network : '' ) ); // The cache includes the SQLite database, stored under "wp-content/database". if ( is_dir( $install_cache_path ) ) { @@ -1964,6 +1965,14 @@ public function install_wp( $subdir = '', $version = '' ): void { } else { $this->proc( 'wp core install', $install_args, $subdir )->run_check(); + if ( $network ) { + $network_args = [ + 'title' => 'WP CLI Network', + 'subdomains' => 'subdomain' === $network ? 1 : 0, + ]; + $this->proc( 'wp core install-network', $network_args, $subdir )->run_check(); + } + if ( ! is_dir( $install_cache_path ) ) { mkdir( $install_cache_path ); } diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index 03a87493..05e23b5f 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -393,15 +393,7 @@ public function given_a_wp_installation_with_composer_and_a_custom_vendor_folder * @param string $type Multisite installation type. */ public function given_a_wp_multisite_installation( $type = 'subdirectory' ): void { - $this->install_wp(); - $subdomains = ! empty( $type ) && 'subdomain' === $type ? 1 : 0; - $this->proc( - 'wp core install-network', - array( - 'title' => 'WP CLI Network', - 'subdomains' => $subdomains, - ) - )->run_check(); + $this->install_wp( '', '', 'subdomain' === $type ? 'subdomain' : 'subdirectory' ); } /** From b88b1c329985a86dfc8f6d02816bee2a2cf7fa36 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sat, 31 Oct 2026 04:03:39 +0100 Subject: [PATCH 2/2] Make the multisite cache scenarios work on WordPress 4.9 and Windows Co-Authored-By: Claude Opus 5.5 --- features/behat-steps.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 81990646..11bb0df1 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -507,8 +507,8 @@ Feature: Test that WP-CLI Behat steps work as expected subdomain """ - When I run `wp eval 'wp_insert_site( [ "domain" => "first.example.com", "path" => "/" ] );'` - And I run `wp eval 'echo get_sites( [ "count" => true ] );'` + When I run `wp eval 'wpmu_create_blog( "first.example.com", "/", "First", 1 );'` + And I run `wp eval 'echo get_sites( "count=1" );'` Then STDOUT should be: """ 2 @@ -523,7 +523,7 @@ Feature: Test that WP-CLI Behat steps work as expected subdirectory """ - When I run `wp eval 'echo get_sites( [ "count" => true ] );'` + When I run `wp eval 'echo get_sites( "count=1" );'` Then STDOUT should be: """ 1 @@ -538,7 +538,7 @@ Feature: Test that WP-CLI Behat steps work as expected subdomain """ - When I run `wp eval 'echo get_sites( [ "count" => true ] );'` + When I run `wp eval 'echo get_sites( "count=1" );'` Then STDOUT should be: """ 1