Skip to content

Commit 1128ff9

Browse files
committed
Test failure fixes
1 parent 0f6e7d6 commit 1128ff9

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

‎features/block-search.feature‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Search posts by block usage
55
Given a WP install
66

77
Scenario: Search posts by block type usage
8-
When I run `wp post create --post_title='Quote Post' --post_status=publish --post_type=post --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Hello world</p></blockquote><!-- /wp:quote -->' --porcelain`
8+
When I run `wp post --post_type=post create --post_title='Quote Post' --post_status=publish --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Hello world</p></blockquote><!-- /wp:quote -->' --porcelain`
99
Then STDOUT should be a number
1010
And save STDOUT as {QUOTE_POST_ID}
1111

@@ -16,7 +16,7 @@ Feature: Search posts by block usage
1616
"""
1717

1818
Scenario: Search posts by block namespace
19-
When I run `wp post create --post_title='Core Namespace Post' --post_status=publish --post_type=post --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Hello core</p></blockquote><!-- /wp:quote -->' --porcelain`
19+
When I run `wp post --post_type=post create --post_title='Core Namespace Post' --post_status=publish --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Hello core</p></blockquote><!-- /wp:quote -->' --porcelain`
2020
Then STDOUT should be a number
2121
And save STDOUT as {CORE_NAMESPACE_POST_ID}
2222

@@ -27,7 +27,7 @@ Feature: Search posts by block usage
2727
"""
2828

2929
Scenario: Search nested block usage
30-
When I run `wp post create --post_title='Nested Image Post' --post_status=publish --post_type=page --post_content='<!-- wp:group --><div class="wp-block-group"><!-- wp:image {"sizeSlug":"large"} --><figure class="wp-block-image size-large"><img alt="" /></figure><!-- /wp:image --></div><!-- /wp:group -->' --porcelain`
30+
When I run `wp post --post_type=page create --post_title='Nested Image Post' --post_status=publish --post_content='<!-- wp:group --><div class="wp-block-group"><!-- wp:image {"sizeSlug":"large"} --><figure class="wp-block-image size-large"><img alt="" /></figure><!-- /wp:image --></div><!-- /wp:group -->' --porcelain`
3131
Then STDOUT should be a number
3232
And save STDOUT as {NESTED_POST_ID}
3333

@@ -38,14 +38,14 @@ Feature: Search posts by block usage
3838
"""
3939

4040
Scenario: Search block usage by style
41-
When I run `wp post create --post_title='Rounded Image Post' --post_status=publish --post_type=post --post_content='<!-- wp:image {"className":"is-style-rounded"} --><figure class="wp-block-image is-style-rounded"><img alt="" /></figure><!-- /wp:image -->' --porcelain`
41+
When I run `wp post --post_type=post create --post_title='Rounded Image Post' --post_status=publish --post_content='<!-- wp:image {"className":"is-style-rounded"} --><figure class="wp-block-image is-style-rounded"><img alt="" /></figure><!-- /wp:image -->' --porcelain`
4242
Then STDOUT should be a number
4343
And save STDOUT as {ROUNDED_IMAGE_POST_ID}
4444

45-
When I run `wp post create --post_title='Plain Image Post' --post_status=publish --post_type=post --post_content='<!-- wp:image --><figure class="wp-block-image"><img alt="" /></figure><!-- /wp:image -->' --porcelain`
45+
When I run `wp post --post_type=post create --post_title='Plain Image Post' --post_status=publish --post_content='<!-- wp:image --><figure class="wp-block-image"><img alt="" /></figure><!-- /wp:image -->' --porcelain`
4646
Then STDOUT should be a number
4747

48-
When I run `wp post create --post_title='Rounded Quote Post' --post_status=publish --post_type=post --post_content='<!-- wp:quote {"className":"is-style-rounded"} --><blockquote class="wp-block-quote is-style-rounded"><p>Hello quote</p></blockquote><!-- /wp:quote -->' --porcelain`
48+
When I run `wp post --post_type=post create --post_title='Rounded Quote Post' --post_status=publish --post_content='<!-- wp:quote {"className":"is-style-rounded"} --><blockquote class="wp-block-quote is-style-rounded"><p>Hello quote</p></blockquote><!-- /wp:quote -->' --porcelain`
4949
Then STDOUT should be a number
5050
And save STDOUT as {ROUNDED_QUOTE_POST_ID}
5151

@@ -67,11 +67,11 @@ Feature: Search posts by block usage
6767
"""
6868

6969
Scenario: Search block usage count
70-
When I run `wp post create --post_title='Counted Quote One' --post_status=publish --post_type=post --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>One</p></blockquote><!-- /wp:quote -->' --porcelain`
70+
When I run `wp post --post_type=post create --post_title='Counted Quote One' --post_status=publish --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>One</p></blockquote><!-- /wp:quote -->' --porcelain`
7171
Then STDOUT should be a number
7272
And save STDOUT as {COUNTED_QUOTE_ONE_ID}
7373

74-
When I run `wp post create --post_title='Counted Quote Two' --post_status=publish --post_type=post --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Two</p></blockquote><!-- /wp:quote -->' --porcelain`
74+
When I run `wp post --post_type=post create --post_title='Counted Quote Two' --post_status=publish --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Two</p></blockquote><!-- /wp:quote -->' --porcelain`
7575
Then STDOUT should be a number
7676
And save STDOUT as {COUNTED_QUOTE_TWO_ID}
7777

@@ -93,7 +93,7 @@ Feature: Search posts by block usage
9393
"""
9494

9595
Scenario: Search block usage with selected fields in JSON
96-
When I run `wp post create --post_title='Double Quote Post' --post_status=publish --post_type=post --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>One</p></blockquote><!-- /wp:quote --><!-- wp:quote --><blockquote class="wp-block-quote"><p>Two</p></blockquote><!-- /wp:quote -->' --porcelain`
96+
When I run `wp post --post_type=post create --post_title='Double Quote Post' --post_status=publish --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>One</p></blockquote><!-- /wp:quote --><!-- wp:quote --><blockquote class="wp-block-quote"><p>Two</p></blockquote><!-- /wp:quote -->' --porcelain`
9797
Then STDOUT should be a number
9898
And save STDOUT as {DOUBLE_QUOTE_POST_ID}
9999

@@ -104,11 +104,11 @@ Feature: Search posts by block usage
104104
"""
105105

106106
Scenario: Search blocks embedded from a specific pattern
107-
When I run `wp post create --post_title='Pattern RSVP Post' --post_status=publish --post_type=post --post_content='<!-- wp:group {"metadata":{"categories":["call-to-action"],"patternName":"twentytwentyfive/event-rsvp","name":"Event RSVP"}} --><div class="wp-block-group"><!-- wp:paragraph --><p>RSVP now</p><!-- /wp:paragraph --></div><!-- /wp:group -->' --porcelain`
107+
When I run `wp post --post_type=post create --post_title='Pattern RSVP Post' --post_status=publish --post_content='<!-- wp:group {"metadata":{"categories":["call-to-action"],"patternName":"twentytwentyfive/event-rsvp","name":"Event RSVP"}} --><div class="wp-block-group"><!-- wp:paragraph --><p>RSVP now</p><!-- /wp:paragraph --></div><!-- /wp:group -->' --porcelain`
108108
Then STDOUT should be a number
109109
And save STDOUT as {PATTERN_RSVP_POST_ID}
110110

111-
When I run `wp post create --post_title='Pattern Header Post' --post_status=publish --post_type=post --post_content='<!-- wp:group {"metadata":{"categories":["header"],"patternName":"twentytwentyfive/site-header","name":"Site Header"}} --><div class="wp-block-group"><!-- wp:paragraph --><p>Header block</p><!-- /wp:paragraph --></div><!-- /wp:group -->' --porcelain`
111+
When I run `wp post --post_type=post create --post_title='Pattern Header Post' --post_status=publish --post_content='<!-- wp:group {"metadata":{"categories":["header"],"patternName":"twentytwentyfive/site-header","name":"Site Header"}} --><div class="wp-block-group"><!-- wp:paragraph --><p>Header block</p><!-- /wp:paragraph --></div><!-- /wp:group -->' --porcelain`
112112
Then STDOUT should be a number
113113
And save STDOUT as {PATTERN_HEADER_POST_ID}
114114

@@ -136,7 +136,7 @@ Feature: Search posts by block usage
136136
"""
137137

138138
Scenario: Search pattern blocks with an additional block filter
139-
When I run `wp post create --post_title='Patterned Image Post' --post_status=publish --post_type=post --post_content='<!-- wp:group {"metadata":{"categories":["media"],"patternName":"twentytwentyfive/media-highlight","name":"Media Highlight"}} --><div class="wp-block-group"><!-- wp:image --><figure class="wp-block-image"><img alt="" /></figure><!-- /wp:image --></div><!-- /wp:group -->' --porcelain`
139+
When I run `wp post --post_type=post create --post_title='Patterned Image Post' --post_status=publish --post_content='<!-- wp:group {"metadata":{"categories":["media"],"patternName":"twentytwentyfive/media-highlight","name":"Media Highlight"}} --><div class="wp-block-group"><!-- wp:image --><figure class="wp-block-image"><img alt="" /></figure><!-- /wp:image --></div><!-- /wp:group -->' --porcelain`
140140
Then STDOUT should be a number
141141
And save STDOUT as {PATTERN_IMAGE_POST_ID}
142142

@@ -147,7 +147,7 @@ Feature: Search posts by block usage
147147
"""
148148

149149
Scenario: Search uses the nearest pattern ancestor for nested patterns
150-
When I run `wp post create --post_title='Nested Pattern Image Post' --post_status=publish --post_type=post --post_content='<!-- wp:group {"metadata":{"categories":["outer"],"patternName":"twentytwentyfive/outer-shell","name":"Outer Shell"}} --><div class="wp-block-group"><!-- wp:group {"metadata":{"categories":["inner"],"patternName":"twentytwentyfive/inner-media","name":"Inner Media"}} --><div class="wp-block-group"><!-- wp:image --><figure class="wp-block-image"><img alt="" /></figure><!-- /wp:image --></div><!-- /wp:group --></div><!-- /wp:group -->' --porcelain`
150+
When I run `wp post --post_type=post create --post_title='Nested Pattern Image Post' --post_status=publish --post_content='<!-- wp:group {"metadata":{"categories":["outer"],"patternName":"twentytwentyfive/outer-shell","name":"Outer Shell"}} --><div class="wp-block-group"><!-- wp:group {"metadata":{"categories":["inner"],"patternName":"twentytwentyfive/inner-media","name":"Inner Media"}} --><div class="wp-block-group"><!-- wp:image --><figure class="wp-block-image"><img alt="" /></figure><!-- /wp:image --></div><!-- /wp:group --></div><!-- /wp:group -->' --porcelain`
151151
Then STDOUT should be a number
152152
And save STDOUT as {NESTED_PATTERN_IMAGE_POST_ID}
153153

@@ -172,11 +172,11 @@ Feature: Search posts by block usage
172172
Then STDOUT should be a number
173173
And save STDOUT as {SYNCED_PATTERN_ID}
174174

175-
When I run `wp post create --post_title='Reusable Pattern Post' --post_status=publish --post_type=post --post_content='<!-- wp:block {"ref":{SYNCED_PATTERN_ID}} /-->' --porcelain`
175+
When I run `wp post --post_type=post create --post_title='Reusable Pattern Post' --post_status=publish --post_content='<!-- wp:block {"ref":{SYNCED_PATTERN_ID}} /-->' --porcelain`
176176
Then STDOUT should be a number
177177
And save STDOUT as {SYNCED_PATTERN_POST_ID}
178178

179-
When I run `wp post create --post_title='Different Reusable Pattern Post' --post_status=publish --post_type=post --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Not reusable</p></blockquote><!-- /wp:quote -->' --porcelain`
179+
When I run `wp post --post_type=post create --post_title='Different Reusable Pattern Post' --post_status=publish --post_content='<!-- wp:quote --><blockquote class="wp-block-quote"><p>Not reusable</p></blockquote><!-- /wp:quote -->' --porcelain`
180180
Then STDOUT should be a number
181181

182182
When I run `wp block search --synced-pattern={SYNCED_PATTERN_ID} --field=ID`

‎src/Block_Search_Command.php‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,19 @@ public function __invoke( $args, $assoc_args ) {
131131
$style_name = Utils\get_flag_value( $assoc_args, 'style', '' );
132132
$pattern_name = Utils\get_flag_value( $assoc_args, 'pattern', null );
133133
$pattern_ns = Utils\get_flag_value( $assoc_args, 'pattern-namespace', null );
134-
$synced_pattern = Utils\get_flag_value( $assoc_args, 'synced-pattern', null );
134+
$synced_pattern = null;
135135

136-
if ( null !== $synced_pattern && '' !== $synced_pattern ) {
137-
$synced_pattern = (int) $synced_pattern;
136+
$synced_pattern_raw = Utils\get_flag_value( $assoc_args, 'synced-pattern', null );
137+
138+
if ( null !== $synced_pattern_raw && '' !== $synced_pattern_raw ) {
139+
$synced_pattern = (int) $synced_pattern_raw;
138140

139141
if ( $synced_pattern <= 0 ) {
140142
WP_CLI::error( 'The --synced-pattern parameter must be a positive integer post ID.' );
141143
}
142144
}
143145

144-
if ( ( null === $block_name || '' === $block_name ) && ( null === $block_namespace || '' === $block_namespace ) && '' === $style_name && ( null === $pattern_name || '' === $pattern_name ) && ( null === $pattern_ns || '' === $pattern_ns ) && ( null === $synced_pattern || '' === $synced_pattern ) ) {
146+
if ( ( null === $block_name || '' === $block_name ) && ( null === $block_namespace || '' === $block_namespace ) && '' === $style_name && ( null === $pattern_name || '' === $pattern_name ) && ( null === $pattern_ns || '' === $pattern_ns ) && null === $synced_pattern ) {
145147
WP_CLI::error( 'At least one block filter is required: --block, --block-namespace, --style, --pattern, --pattern-namespace, or --synced-pattern.' );
146148
}
147149

@@ -189,6 +191,10 @@ public function __invoke( $args, $assoc_args ) {
189191
$query = new \WP_Query( $query_args );
190192

191193
foreach ( $query->posts as $post ) {
194+
if ( ! $post instanceof \WP_Post ) {
195+
continue;
196+
}
197+
192198
if ( $this->can_use_has_block_fast_path( $block_name, $block_namespace, $style_name, $pattern_name, $pattern_ns, $synced_pattern ) && ! has_block( $block_name, $post ) ) {
193199
continue;
194200
}

0 commit comments

Comments
 (0)