diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 1620e011..11bb0df1 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 'wpmu_create_blog( "first.example.com", "/", "First", 1 );'` + And I run `wp eval 'echo get_sites( "count=1" );'` + 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=1" );'` + 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=1" );'` + 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' ); } /**