File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3333 "yoast/phpunit-polyfills" : " ^2.0 || ^3.0 || ^4.0"
3434 },
3535 "require-dev" : {
36- "roave/security-advisories" : " dev-latest"
36+ "roave/security-advisories" : " dev-latest" ,
37+ "wp-cli/entity-command" : " ^1 || ^2 || ^3"
3738 },
3839 "config" : {
3940 "allow-plugins" : {
Original file line number Diff line number Diff line change @@ -495,6 +495,27 @@ Feature: Test that WP-CLI Behat steps work as expected
495495 'WP_CLI_TEST_CONSTANT', 'a value'
496496 """
497497
498+ @require-wp
499+ Scenario : Create several sites at once
500+ Given a WP multisite installation
501+ And these sites:
502+ | slug | title | save |
503+ | first | First site | FIRST_ID |
504+ | second | | SECOND_ID |
505+
506+ When I run `wp site list --fields=blog_id,url --format=csv`
507+ Then STDOUT should contain:
508+ """
509+ {FIRST_ID},https://example.com/first/
510+ {SECOND_ID},https://example.com/second/
511+ """
512+
513+ When I run `wp eval 'echo get_blog_option( {FIRST_ID}, "blogname" ) . "|" . get_blog_option( {SECOND_ID}, "blogname" );' `
514+ Then STDOUT should be:
515+ """
516+ First site|Second
517+ """
518+
498519 @require-wp
499520 Scenario : Test custom wp-content directory
500521 Given a WP installation
Original file line number Diff line number Diff line change @@ -430,6 +430,45 @@ public function given_these_installed_and_active_plugins( $stream ): void {
430430 $ this ->proc ( "wp plugin install $ plugins --activate " )->run_check ();
431431 }
432432
433+ /**
434+ * Creates one or more sites on a multisite installation in a single process.
435+ *
436+ * The `slug` column is required. The optional `title` column sets the site title, and the
437+ * optional `save` column names a variable to save the new site's ID into.
438+ *
439+ * ```
440+ * Scenario: My example scenario
441+ * Given a WP multisite installation
442+ * And these sites:
443+ * | slug | title | save |
444+ * | first | First site | FIRST_ID |
445+ * | second | | SECOND_ID |
446+ * ```
447+ *
448+ * @access public
449+ *
450+ * @Given these sites:
451+ *
452+ * @param TableNode $table
453+ */
454+ public function given_these_sites ( TableNode $ table ): void {
455+ $ commands = [];
456+ foreach ( $ table ->getHash () as $ row ) {
457+ if ( empty ( $ row ['slug ' ] ) ) {
458+ throw new RuntimeException ( 'The sites table needs a "slug" column. ' );
459+ }
460+
461+ $ command = 'wp site create --slug= ' . $ row ['slug ' ] . ' --porcelain ' ;
462+ if ( isset ( $ row ['title ' ] ) && '' !== $ row ['title ' ] ) {
463+ $ command .= ' --title=" ' . addcslashes ( $ row ['title ' ], '" \\' ) . '" ' ;
464+ }
465+
466+ $ commands [] = [ $ command , trim ( $ row ['save ' ] ?? '' , '{} ' ) ];
467+ }
468+
469+ $ this ->run_commands_in_single_process ( $ commands );
470+ }
471+
433472 /**
434473 * Runs several setup commands in a single process.
435474 *
You can’t perform that action at this time.
0 commit comments