From 321abbbd475a437e4165edccd39d3f33faee17ef Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 30 Oct 2026 20:42:24 +0100 Subject: [PATCH 1/2] Add a step to create several sites at once Co-Authored-By: Claude Opus 5.5 --- composer.json | 3 +++ features/behat-steps.feature | 21 +++++++++++++++ src/Context/GivenStepDefinitions.php | 39 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/composer.json b/composer.json index 2061c6ec..15fb9fd3 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,9 @@ "wp-coding-standards/wpcs": "dev-develop", "yoast/phpunit-polyfills": "^2.0 || ^3.0 || ^4.0" }, + "require-dev": { + "wp-cli/entity-command": "^1 || ^2 || ^3" + }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, diff --git a/features/behat-steps.feature b/features/behat-steps.feature index b8e1f618..aa7619e4 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -495,6 +495,27 @@ Feature: Test that WP-CLI Behat steps work as expected 'WP_CLI_TEST_CONSTANT', 'a value' """ + @require-wp + Scenario: Create several sites at once + Given a WP multisite installation + And these sites: + | slug | title | save | + | first | First site | FIRST_ID | + | second | | SECOND_ID | + + When I run `wp site list --fields=blog_id,url --format=csv` + Then STDOUT should contain: + """ + {FIRST_ID},https://example.com/first/ + {SECOND_ID},https://example.com/second/ + """ + + When I run `wp eval 'echo get_blog_option( {FIRST_ID}, "blogname" ) . "|" . get_blog_option( {SECOND_ID}, "blogname" );'` + Then STDOUT should be: + """ + First site|Second + """ + @require-wp Scenario: Test custom wp-content directory Given a WP installation diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index ef64aae8..3369e64a 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -430,6 +430,45 @@ public function given_these_installed_and_active_plugins( $stream ): void { $this->proc( "wp plugin install $plugins --activate" )->run_check(); } + /** + * Creates one or more sites on a multisite installation in a single process. + * + * The `slug` column is required. The optional `title` column sets the site title, and the + * optional `save` column names a variable to save the new site's ID into. + * + * ``` + * Scenario: My example scenario + * Given a WP multisite installation + * And these sites: + * | slug | title | save | + * | first | First site | FIRST_ID | + * | second | | SECOND_ID | + * ``` + * + * @access public + * + * @Given these sites: + * + * @param TableNode $table + */ + public function given_these_sites( TableNode $table ): void { + $commands = []; + foreach ( $table->getHash() as $row ) { + if ( empty( $row['slug'] ) ) { + throw new RuntimeException( 'The sites table needs a "slug" column.' ); + } + + $command = 'wp site create --slug=' . $row['slug'] . ' --porcelain'; + if ( isset( $row['title'] ) && '' !== $row['title'] ) { + $command .= ' --title="' . addcslashes( $row['title'], '"\\' ) . '"'; + } + + $commands[] = [ $command, trim( $row['save'] ?? '', '{} ' ) ]; + } + + $this->run_commands_in_single_process( $commands ); + } + /** * Runs several setup commands in a single process. * From 69552ac1a30971496ff960874e55f4c901fb44ed Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sat, 31 Oct 2026 04:03:46 +0100 Subject: [PATCH 2/2] Run the checks again with the current workflows Co-Authored-By: Claude Opus 5.5