Skip to content

Commit 0f5c31a

Browse files
Copilotswissspidy
andcommitted
Add comprehensive Behat tests for block and pattern commands
Co-authored-by: swissspidy <[email protected]>
1 parent a337f73 commit 0f5c31a

File tree

3 files changed

+237
-0
lines changed

3 files changed

+237
-0
lines changed

features/block.feature

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Feature: Manage WordPress block types
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-5.0
7+
Scenario: Listing block types
8+
When I run `wp block list --format=csv`
9+
Then STDOUT should contain:
10+
"""
11+
name,title
12+
"""
13+
And STDOUT should contain:
14+
"""
15+
core/paragraph
16+
"""
17+
18+
@require-wp-5.0
19+
Scenario: Listing block types with specific fields
20+
When I run `wp block list --fields=name,title,category`
21+
Then STDOUT should be a table containing rows:
22+
| name | title | category |
23+
| core/paragraph | Paragraph | text |
24+
25+
@require-wp-5.0
26+
Scenario: Getting a specific block type
27+
When I run `wp block get core/paragraph --fields=name,title,category`
28+
Then STDOUT should be a table containing rows:
29+
| Field | Value |
30+
| name | core/paragraph |
31+
| title | Paragraph |
32+
| category | text |
33+
34+
@require-wp-5.0
35+
Scenario: Getting a non-existent block type
36+
When I try `wp block get core/nonexistent-block`
37+
Then STDERR should contain:
38+
"""
39+
Error: Block type 'core/nonexistent-block' is not registered.
40+
"""
41+
And the return code should be 1
42+
43+
@require-wp-5.0
44+
Scenario: Getting a specific field from a block type
45+
When I run `wp block get core/paragraph --field=title`
46+
Then STDOUT should be:
47+
"""
48+
Paragraph
49+
"""
50+
51+
@require-wp-5.0
52+
Scenario: Listing block types in JSON format
53+
When I run `wp block list --format=json`
54+
Then STDOUT should be JSON containing:
55+
"""
56+
[{"name":"core/paragraph"}]
57+
"""
58+
59+
@require-wp-5.0
60+
Scenario: Count block types
61+
When I run `wp block list --format=count`
62+
Then STDOUT should match /^\d+$/
63+
64+
@require-wp-4.9
65+
Scenario: Block commands require WordPress 5.0+
66+
When I try `wp block list`
67+
Then STDERR should contain:
68+
"""
69+
Error: The block commands require WordPress 5.0 or greater.
70+
"""
71+
And the return code should be 1

features/pattern.feature

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Feature: Manage WordPress block patterns
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-5.5
7+
Scenario: Listing block patterns
8+
When I run `wp pattern list --format=csv`
9+
Then STDOUT should contain:
10+
"""
11+
name,title
12+
"""
13+
14+
@require-wp-5.5
15+
Scenario: Getting a specific block pattern
16+
Given I run `wp pattern list --format=ids`
17+
And save STDOUT as {PATTERN_NAME}
18+
19+
When I run `wp pattern get {PATTERN_NAME}`
20+
Then STDOUT should contain:
21+
"""
22+
name
23+
"""
24+
And STDOUT should contain:
25+
"""
26+
title
27+
"""
28+
29+
@require-wp-5.5
30+
Scenario: Getting a non-existent block pattern
31+
When I try `wp pattern get nonexistent/pattern`
32+
Then STDERR should contain:
33+
"""
34+
Error: Block pattern 'nonexistent/pattern' is not registered.
35+
"""
36+
And the return code should be 1
37+
38+
@require-wp-5.5
39+
Scenario: Listing block patterns in JSON format
40+
When I run `wp pattern list --format=json`
41+
Then STDOUT should be valid JSON
42+
43+
@require-wp-5.5
44+
Scenario: Count block patterns
45+
When I run `wp pattern list --format=count`
46+
Then STDOUT should match /^\d+$/
47+
48+
@require-wp-4.9
49+
Scenario: Pattern commands require WordPress 5.5+
50+
When I try `wp pattern list`
51+
Then STDERR should contain:
52+
"""
53+
Error: The pattern commands require WordPress 5.5 or greater.
54+
"""
55+
And the return code should be 1

features/post-blocks.feature

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Feature: Manage WordPress post blocks
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-5.0
7+
Scenario: Check if a post has blocks
8+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
9+
Then STDOUT should be a number
10+
And save STDOUT as {POST_ID}
11+
12+
When I run `wp post has-blocks {POST_ID}`
13+
Then STDOUT should contain:
14+
"""
15+
Success: Post {POST_ID} has blocks.
16+
"""
17+
And the return code should be 0
18+
19+
@require-wp-5.0
20+
Scenario: Check if a post does not have blocks
21+
When I run `wp post create --post_title='Regular post' --post_content='<p>Hello World</p>' --porcelain`
22+
Then STDOUT should be a number
23+
And save STDOUT as {POST_ID}
24+
25+
When I try `wp post has-blocks {POST_ID}`
26+
Then STDERR should contain:
27+
"""
28+
Error: Post {POST_ID} does not have blocks.
29+
"""
30+
And the return code should be 1
31+
32+
@require-wp-5.0
33+
Scenario: Check if a post contains a specific block type
34+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
35+
Then STDOUT should be a number
36+
And save STDOUT as {POST_ID}
37+
38+
When I run `wp post has-block {POST_ID} core/paragraph`
39+
Then STDOUT should contain:
40+
"""
41+
Success: Post {POST_ID} contains the block 'core/paragraph'.
42+
"""
43+
And the return code should be 0
44+
45+
@require-wp-5.0
46+
Scenario: Check if a post does not contain a specific block type
47+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
48+
Then STDOUT should be a number
49+
And save STDOUT as {POST_ID}
50+
51+
When I try `wp post has-block {POST_ID} core/image`
52+
Then STDERR should contain:
53+
"""
54+
Error: Post {POST_ID} does not contain the block 'core/image'.
55+
"""
56+
And the return code should be 1
57+
58+
@require-wp-5.0
59+
Scenario: Parse blocks from a post
60+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
61+
Then STDOUT should be a number
62+
And save STDOUT as {POST_ID}
63+
64+
When I run `wp post parse-blocks {POST_ID}`
65+
Then STDOUT should be valid JSON
66+
And STDOUT should contain:
67+
"""
68+
"blockName": "core/paragraph"
69+
"""
70+
71+
@require-wp-5.0
72+
Scenario: Parse blocks and output as YAML
73+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
74+
Then STDOUT should be a number
75+
And save STDOUT as {POST_ID}
76+
77+
When I run `wp post parse-blocks {POST_ID} --format=yaml`
78+
Then STDOUT should contain:
79+
"""
80+
blockName:
81+
"""
82+
And STDOUT should contain:
83+
"""
84+
core/paragraph
85+
"""
86+
87+
@require-wp-5.0
88+
Scenario: Render blocks from a post
89+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
90+
Then STDOUT should be a number
91+
And save STDOUT as {POST_ID}
92+
93+
When I run `wp post render-blocks {POST_ID}`
94+
Then STDOUT should contain:
95+
"""
96+
<p>Hello World</p>
97+
"""
98+
99+
@require-wp-5.0
100+
Scenario: Post get command includes block_version field
101+
When I run `wp post create --post_title='Block post' --post_content='<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->' --porcelain`
102+
Then STDOUT should be a number
103+
And save STDOUT as {POST_ID}
104+
105+
When I run `wp post get {POST_ID} --field=block_version`
106+
Then STDOUT should match /^\d+$/
107+
108+
@require-wp-4.9
109+
Scenario: Post block commands require WordPress 5.0+
110+
When I try `wp post has-blocks 1`
111+
Then the return code should be 1

0 commit comments

Comments
 (0)