Skip to content

Commit d573631

Browse files
committed
Test fixes
1 parent 94f6828 commit d573631

File tree

5 files changed

+41
-48
lines changed

5 files changed

+41
-48
lines changed

entity-command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
array(
101101
'before_invoke' => function () {
102102
if ( Utils\wp_version_compare( '5.0', '<' ) ) {
103-
WP_CLI::error( 'The block commands require WordPress 5.0 or greater.' );
103+
WP_CLI::error( 'Requires WordPress 5.0 or greater.' );
104104
}
105105
},
106106
)
@@ -112,7 +112,7 @@
112112
array(
113113
'before_invoke' => function () {
114114
if ( Utils\wp_version_compare( '5.5', '<' ) ) {
115-
WP_CLI::error( 'The pattern commands require WordPress 5.5 or greater.' );
115+
WP_CLI::error( 'Requires WordPress 5.5 or greater.' );
116116
}
117117
},
118118
)

features/block.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ Feature: Manage WordPress block types
5151
@require-wp-5.0
5252
Scenario: Listing block types in JSON format
5353
When I run `wp block list --format=json`
54-
Then STDOUT should be JSON containing:
54+
Then STDOUT should contain:
5555
"""
56-
[{"name":"core/paragraph"}]
56+
{"name":"core\/paragraph","title":"Paragraph","description":"Start with the basic building block of all narrative.","category":"text"}
5757
"""
5858

5959
@require-wp-5.0
6060
Scenario: Count block types
6161
When I run `wp block list --format=count`
6262
Then STDOUT should match /^\d+$/
6363

64-
@require-wp-4.9
64+
@less-than-wp-5.0
6565
Scenario: Block commands require WordPress 5.0+
6666
When I try `wp block list`
6767
Then STDERR should contain:
6868
"""
69-
Error: The block commands require WordPress 5.0 or greater.
69+
Error: Requires WordPress 5.0 or greater.
7070
"""
7171
And the return code should be 1

features/pattern.feature

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Feature: Manage WordPress block patterns
1111
name,title
1212
"""
1313

14+
When I run `wp pattern list --format=json`
15+
Then STDOUT should be JSON containing:
16+
"""
17+
[{"name":"core\/query-standard-posts","title":"Standard"}]
18+
"""
19+
1420
@require-wp-5.5
1521
Scenario: Getting a specific block pattern
1622
When I run `wp pattern list --format=csv --fields=name`
@@ -31,21 +37,16 @@ Feature: Manage WordPress block patterns
3137
"""
3238
And the return code should be 1
3339

34-
@require-wp-5.5
35-
Scenario: Listing block patterns in JSON format
36-
When I run `wp pattern list --format=json`
37-
Then STDOUT should be valid JSON
38-
3940
@require-wp-5.5
4041
Scenario: Count block patterns
4142
When I run `wp pattern list --format=count`
4243
Then STDOUT should match /^\d+$/
4344

44-
@require-wp-4.9
45+
@less-than-wp-5.0
4546
Scenario: Pattern commands require WordPress 5.5+
4647
When I try `wp pattern list`
4748
Then STDERR should contain:
4849
"""
49-
Error: The pattern commands require WordPress 5.5 or greater.
50+
Error: Requires WordPress 5.5 or greater.
5051
"""
5152
And the return code should be 1

features/post-blocks.feature

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ Feature: Manage WordPress post blocks
2323
And save STDOUT as {POST_ID}
2424

2525
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-
"""
26+
Then STDERR should be empty
3027
And the return code should be 1
3128

3229
@require-wp-5.0
@@ -42,17 +39,8 @@ Feature: Manage WordPress post blocks
4239
"""
4340
And the return code should be 0
4441

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-
5142
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-
"""
43+
Then STDERR should be empty
5644
And the return code should be 1
5745

5846
@require-wp-5.0
@@ -62,18 +50,21 @@ Feature: Manage WordPress post blocks
6250
And save STDOUT as {POST_ID}
6351

6452
When I run `wp post parse-blocks {POST_ID}`
65-
Then STDOUT should be valid JSON
66-
And STDOUT should contain:
53+
Then STDOUT should be JSON containing:
6754
"""
68-
"blockName": "core/paragraph"
55+
[
56+
{
57+
"blockName": "core/paragraph",
58+
"attrs": [],
59+
"innerBlocks": [],
60+
"innerHTML": "<p>Hello World</p>",
61+
"innerContent": [
62+
"<p>Hello World</p>"
63+
]
64+
}
65+
]
6966
"""
7067

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-
7768
When I run `wp post parse-blocks {POST_ID} --format=yaml`
7869
Then STDOUT should contain:
7970
"""
@@ -105,11 +96,11 @@ Feature: Manage WordPress post blocks
10596
When I run `wp post get {POST_ID} --field=block_version`
10697
Then STDOUT should match /^\d+$/
10798

108-
@require-wp-4.9
99+
@less-than-wp-5.0
109100
Scenario: Post block commands require WordPress 5.0+
110101
When I try `wp post has-blocks 1`
111102
Then STDERR should contain:
112103
"""
113-
Error: This command requires WordPress 5.0 or greater.
104+
Error: Requires WordPress 5.0 or greater.
114105
"""
115106
And the return code should be 1

src/Post_Command.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ public function has_blocks( $args, $assoc_args ) {
10901090
if ( has_blocks( $post->post_content ) ) {
10911091
WP_CLI::success( "Post {$post->ID} has blocks." );
10921092
} else {
1093-
WP_CLI::error( "Post {$post->ID} does not have blocks." );
1093+
WP_CLI::halt( 1 );
10941094
}
10951095
}
10961096

@@ -1124,7 +1124,7 @@ public function has_block( $args, $assoc_args ) {
11241124
if ( has_block( $block_name, $post->post_content ) ) {
11251125
WP_CLI::success( "Post {$post->ID} contains the block '{$block_name}'." );
11261126
} else {
1127-
WP_CLI::error( "Post {$post->ID} does not contain the block '{$block_name}'." );
1127+
WP_CLI::halt( 1 );
11281128
}
11291129
}
11301130

@@ -1164,15 +1164,16 @@ public function parse_blocks( $args, $assoc_args ) {
11641164
$post = $this->fetcher->get_check( $args[0] );
11651165
$blocks = parse_blocks( $post->post_content );
11661166

1167-
$format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'json';
1167+
$fields = [
1168+
'blockName',
1169+
'attrs',
1170+
'innerBlocks',
1171+
'innerHTML',
1172+
'innerContent',
1173+
];
11681174

1169-
if ( 'json' === $format ) {
1170-
WP_CLI::line( json_encode( $blocks, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
1171-
} elseif ( 'yaml' === $format ) {
1172-
foreach ( $blocks as $block ) {
1173-
WP_CLI::line( \Spyc::YAMLDump( $block ) );
1174-
}
1175-
}
1175+
$formatter = new \WP_CLI\Formatter( $assoc_args, $fields );
1176+
$formatter->display_items( $blocks );
11761177
}
11771178

11781179
/**

0 commit comments

Comments
 (0)