Add site generator command by i-am-chitti · Pull Request #498 · wp-cli/entity-command · GitHub
Skip to content
Merged
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
1 change: 1 addition & 0 deletions composer.json
107 changes: 107 additions & 0 deletions features/site-generate.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Feature: Generate new WordPress sites

Scenario: Generate on single site
Given a WP install
When I try `wp site generate`
Then STDERR should contain:
"""
This is not a multisite installation.
"""
And STDOUT should be empty
And the return code should be 1

Scenario: Generate a specific number of sites
Given a WP multisite install
When I run `wp site generate --count=10`
And I run `wp site list --format=count`
Then STDOUT should be:
"""
11
"""

Scenario: Generate sites assigned to a specific network
Given a WP multisite install
When I try `wp site generate --count=4 --network_id=2`
Then STDERR should contain:
"""
Network with id 2 does not exist.
"""
And STDOUT should be empty
And the return code should be 1

Scenario: Generate sites and output ids
Given a WP multisite install
When I run `wp site generate --count=3 --format=ids`
When I run `wp site list --format=ids`
Then STDOUT should be:
"""
1 2 3 4
"""
And STDERR should be empty
And the return code should be 0

Scenario: Generate subdomain sites
Given a WP multisite subdomain install

When I run `wp site generate --count=1`
Then STDOUT should be empty

When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | https://example.com/ |
| 2 | http://site1.example.com/ |
When I run `wp site list --format=ids`
Then STDOUT should be:
"""
1 2
"""

Scenario: Generate subdirectory sites
Given a WP multisite subdirectory install
When I run `wp site generate --count=1`
Then STDOUT should be empty
And I run `wp site list --site__in=2 --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SCHEME}

When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | https://example.com/ |
| 2 | {SCHEME}://example.com/site1/ |
When I run `wp site list --format=ids`
Then STDOUT should be:
"""
1 2
"""

Scenario: Generate sites with a slug
Given a WP multisite subdirectory install
When I run `wp site generate --count=2 --slug=subsite`
Then STDOUT should be empty
And I run `wp site list --site__in=2 --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SCHEME1}
And I run `wp site list --site__in=3 --field=url | sed -e's,^\(.*\)://.*,\1,g'`
And save STDOUT as {SCHEME2}

When I run `wp site list --fields=blog_id,url`
Then STDOUT should be a table containing rows:
| blog_id | url |
| 1 | https://example.com/ |
| 2 | {SCHEME1}://example.com/subsite1/ |
| 3 | {SCHEME2}://example.com/subsite2/ |
When I run `wp site list --format=ids`
Then STDOUT should be:
"""
1 2 3
"""

Scenario: Generate sites with reserved slug
Given a WP multisite subdirectory install
When I try `wp site generate --count=2 --slug=page`
Then STDERR should contain:
"""
The following words are reserved and cannot be used as blog names: page, comments, blog, files, feed
"""
And STDOUT should be empty
And the return code should be 1
191 changes: 189 additions & 2 deletions src/Site_Command.php