Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions features/behat-steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions src/Context/GivenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading