Skip to content

Commit c5f28f8

Browse files
schlesseraclaude
andcommitted
Cache multisite installations like single site installations
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b533a56 commit c5f28f8

3 files changed

Lines changed: 58 additions & 11 deletions

File tree

‎features/behat-steps.feature‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,52 @@ Feature: Test that WP-CLI Behat steps work as expected
498498
When I run `wp core is-installed --network`
499499
Then the return code should be 0
500500

501+
@require-wp
502+
Scenario: Create a site on a cached multisite subdomain installation
503+
Given a WP multisite subdomain installation
504+
When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'`
505+
Then STDOUT should be:
506+
"""
507+
subdomain
508+
"""
509+
510+
When I run `wp eval 'wp_insert_site( [ "domain" => "first.example.com", "path" => "/" ] );'`
511+
And I run `wp eval 'echo get_sites( [ "count" => true ] );'`
512+
Then STDOUT should be:
513+
"""
514+
2
515+
"""
516+
517+
@require-wp
518+
Scenario: Restore a cached multisite subdirectory installation
519+
Given a WP multisite subdirectory installation
520+
When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'`
521+
Then STDOUT should be:
522+
"""
523+
subdirectory
524+
"""
525+
526+
When I run `wp eval 'echo get_sites( [ "count" => true ] );'`
527+
Then STDOUT should be:
528+
"""
529+
1
530+
"""
531+
532+
@require-wp
533+
Scenario: Restore a cached multisite subdomain installation without earlier changes
534+
Given a WP multisite subdomain installation
535+
When I run `wp eval 'echo is_subdomain_install() ? "subdomain" : "subdirectory";'`
536+
Then STDOUT should be:
537+
"""
538+
subdomain
539+
"""
540+
541+
When I run `wp eval 'echo get_sites( [ "count" => true ] );'`
542+
Then STDOUT should be:
543+
"""
544+
1
545+
"""
546+
501547
@require-wp
502548
Scenario: Test misconfigured WP_CONTENT_DIR
503549
Given a WP installation

‎src/Context/FeatureContext.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,9 @@ public function create_config( $subdir = '', $extra_php = false ): void {
19131913
/**
19141914
* @param string $subdir
19151915
* @param string $version
1916+
* @param string $network Multisite type to install on top, either 'subdirectory' or 'subdomain'. Empty for a single site.
19161917
*/
1917-
public function install_wp( $subdir = '', $version = '' ): void {
1918+
public function install_wp( $subdir = '', $version = '', $network = '' ): void {
19181919
$wp_version = $version ?: getenv( 'WP_VERSION' );
19191920
$wp_version_suffix = $wp_version ? "-$wp_version" : '';
19201921
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 {
19511952

19521953
$run_dir = '' !== $subdir ? ( $this->variables['RUN_DIR'] . "/$subdir" ) : $this->variables['RUN_DIR'];
19531954

1954-
$install_cache_path = self::$install_cache_dir . '/install_' . md5( implode( ':', $install_args ) . ':subdir=' . $subdir . ':object_cache=' . getenv( 'WP_CLI_TEST_OBJECT_CACHE' ) );
1955+
$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 : '' ) );
19551956

19561957
// The cache includes the SQLite database, stored under "wp-content/database".
19571958
if ( is_dir( $install_cache_path ) ) {
@@ -1964,6 +1965,14 @@ public function install_wp( $subdir = '', $version = '' ): void {
19641965
} else {
19651966
$this->proc( 'wp core install', $install_args, $subdir )->run_check();
19661967

1968+
if ( $network ) {
1969+
$network_args = [
1970+
'title' => 'WP CLI Network',
1971+
'subdomains' => 'subdomain' === $network ? 1 : 0,
1972+
];
1973+
$this->proc( 'wp core install-network', $network_args, $subdir )->run_check();
1974+
}
1975+
19671976
if ( ! is_dir( $install_cache_path ) ) {
19681977
mkdir( $install_cache_path );
19691978
}

‎src/Context/GivenStepDefinitions.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,7 @@ public function given_a_wp_installation_with_composer_and_a_custom_vendor_folder
393393
* @param string $type Multisite installation type.
394394
*/
395395
public function given_a_wp_multisite_installation( $type = 'subdirectory' ): void {
396-
$this->install_wp();
397-
$subdomains = ! empty( $type ) && 'subdomain' === $type ? 1 : 0;
398-
$this->proc(
399-
'wp core install-network',
400-
array(
401-
'title' => 'WP CLI Network',
402-
'subdomains' => $subdomains,
403-
)
404-
)->run_check();
396+
$this->install_wp( '', '', 'subdomain' === $type ? 'subdomain' : 'subdirectory' );
405397
}
406398

407399
/**

0 commit comments

Comments
 (0)