Skip to content

Commit 946ad54

Browse files
committed
Add basic site generator tests
1 parent 5f279bf commit 946ad54

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

features/site-generate.feature

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Feature: Generate new WordPress sites
2+
3+
Scenario: Generate on single site
4+
Given a WP install
5+
When I try `wp site generate`
6+
Then STDERR should contain:
7+
"""
8+
This is not a multisite installation.
9+
"""
10+
And STDOUT should be empty
11+
And the return code should be 1
12+
13+
Scenario: Generate a specific number of sites
14+
Given a WP multisite install
15+
When I run `wp site generate --count=10`
16+
And I run `wp site list --format=count`
17+
Then STDOUT should be:
18+
"""
19+
11
20+
"""
21+
22+
Scenario: Generate sites assigned to a specific network
23+
Given a WP multisite install
24+
When I try `wp site generate --count=4 --network_id=2`
25+
Then STDERR should contain:
26+
"""
27+
Network with id 2 does not exist.
28+
"""
29+
And STDOUT should be empty
30+
And the return code should be 1
31+
32+
Scenario: Generate sites and output ids
33+
Given a WP multisite install
34+
When I run `wp site generate --count=3 --format=ids`
35+
When I run `wp site list --format=ids`
36+
Then STDOUT should be:
37+
"""
38+
1 2 3 4
39+
"""
40+
And STDERR should be empty
41+
And the return code should be 0
42+
43+
Scenario: Generate subdomain sites
44+
Given a WP multisite subdomain install
45+
46+
When I run `wp site generate --count=1`
47+
Then STDOUT should be empty
48+
49+
When I run `wp site list --fields=blog_id,url`
50+
Then STDOUT should be a table containing rows:
51+
| blog_id | url |
52+
| 1 | https://example.com/ |
53+
| 2 | http://site1.example.com/ |
54+
When I run `wp site list --format=ids`
55+
Then STDOUT should be:
56+
"""
57+
1 2
58+
"""
59+
60+
Scenario: Generate subdirectory sites
61+
Given a WP multisite subdirectory install
62+
63+
When I run `wp site generate --count=1`
64+
Then STDOUT should be empty
65+
66+
When I run `wp site list --fields=blog_id,url`
67+
Then STDOUT should be a table containing rows:
68+
| blog_id | url |
69+
| 1 | https://example.com/ |
70+
| 2 | https://example.com/site1/ |
71+
When I run `wp site list --format=ids`
72+
Then STDOUT should be:
73+
"""
74+
1 2
75+
"""

src/Site_Command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,10 @@ public function generate( $args, $assoc_args ) {
620620
if ( 'progress' === $format ) {
621621
$notify->tick();
622622
} else {
623-
WP_CLI::line( $id );
623+
echo $id;
624+
if ( $index < $limit -1 ) {
625+
echo ' ';
626+
}
624627
}
625628
}
626629

0 commit comments

Comments
 (0)