|
| 1 | +@require-wp-5.0 |
| 2 | +Feature: Search posts by block usage |
| 3 | + |
| 4 | + Background: |
| 5 | + Given a WP install |
| 6 | + |
| 7 | + 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` |
| 9 | + Then STDOUT should be a number |
| 10 | + And save STDOUT as {QUOTE_POST_ID} |
| 11 | + |
| 12 | + When I run `wp block search --block=core/quote --post_type=post --field=ID` |
| 13 | + Then STDOUT should be: |
| 14 | + """ |
| 15 | + {QUOTE_POST_ID} |
| 16 | + """ |
| 17 | + |
| 18 | + 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` |
| 20 | + Then STDOUT should be a number |
| 21 | + And save STDOUT as {CORE_NAMESPACE_POST_ID} |
| 22 | + |
| 23 | + When I run `wp block search --block-namespace=core --post_type=post --field=ID` |
| 24 | + Then STDOUT should contain: |
| 25 | + """ |
| 26 | + {CORE_NAMESPACE_POST_ID} |
| 27 | + """ |
| 28 | + |
| 29 | + 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` |
| 31 | + Then STDOUT should be a number |
| 32 | + And save STDOUT as {NESTED_POST_ID} |
| 33 | + |
| 34 | + When I run `wp block search --block=core/image --post_type=page --field=ID` |
| 35 | + Then STDOUT should be: |
| 36 | + """ |
| 37 | + {NESTED_POST_ID} |
| 38 | + """ |
| 39 | + |
| 40 | + 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` |
| 42 | + Then STDOUT should be a number |
| 43 | + And save STDOUT as {ROUNDED_IMAGE_POST_ID} |
| 44 | + |
| 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` |
| 46 | + Then STDOUT should be a number |
| 47 | + |
| 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` |
| 49 | + Then STDOUT should be a number |
| 50 | + And save STDOUT as {ROUNDED_QUOTE_POST_ID} |
| 51 | + |
| 52 | + When I run `wp block search --block=core/image --style=rounded --field=ID` |
| 53 | + Then STDOUT should be: |
| 54 | + """ |
| 55 | + {ROUNDED_IMAGE_POST_ID} |
| 56 | + """ |
| 57 | + |
| 58 | + When I run `wp block search --style=rounded --field=ID` |
| 59 | + Then STDOUT should contain: |
| 60 | + """ |
| 61 | + {ROUNDED_IMAGE_POST_ID} |
| 62 | + """ |
| 63 | + |
| 64 | + And STDOUT should contain: |
| 65 | + """ |
| 66 | + {ROUNDED_QUOTE_POST_ID} |
| 67 | + """ |
| 68 | + |
| 69 | + 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` |
| 71 | + Then STDOUT should be a number |
| 72 | + And save STDOUT as {COUNTED_QUOTE_ONE_ID} |
| 73 | + |
| 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` |
| 75 | + Then STDOUT should be a number |
| 76 | + And save STDOUT as {COUNTED_QUOTE_TWO_ID} |
| 77 | + |
| 78 | + When I run `wp block search --block=core/quote --post_type=post --format=count` |
| 79 | + Then STDOUT should be: |
| 80 | + """ |
| 81 | + 2 |
| 82 | + """ |
| 83 | + |
| 84 | + When I run `wp block search --block=core/quote --post__in={COUNTED_QUOTE_ONE_ID},{COUNTED_QUOTE_TWO_ID} --format=ids` |
| 85 | + Then STDOUT should contain: |
| 86 | + """ |
| 87 | + {COUNTED_QUOTE_ONE_ID} |
| 88 | + """ |
| 89 | + |
| 90 | + And STDOUT should contain: |
| 91 | + """ |
| 92 | + {COUNTED_QUOTE_TWO_ID} |
| 93 | + """ |
| 94 | + |
| 95 | + 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` |
| 97 | + Then STDOUT should be a number |
| 98 | + And save STDOUT as {DOUBLE_QUOTE_POST_ID} |
| 99 | + |
| 100 | + When I run `wp block search --block=core/quote --post__in={DOUBLE_QUOTE_POST_ID} --fields=ID,occurrences --format=json` |
| 101 | + Then STDOUT should be JSON containing: |
| 102 | + """ |
| 103 | + [{"ID":{DOUBLE_QUOTE_POST_ID},"occurrences":2}] |
| 104 | + """ |
| 105 | + |
| 106 | + 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` |
| 108 | + Then STDOUT should be a number |
| 109 | + And save STDOUT as {PATTERN_RSVP_POST_ID} |
| 110 | + |
| 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` |
| 112 | + Then STDOUT should be a number |
| 113 | + And save STDOUT as {PATTERN_HEADER_POST_ID} |
| 114 | + |
| 115 | + When I run `wp block search --pattern=twentytwentyfive/event-rsvp --field=ID` |
| 116 | + Then STDOUT should be: |
| 117 | + """ |
| 118 | + {PATTERN_RSVP_POST_ID} |
| 119 | + """ |
| 120 | + |
| 121 | + When I run `wp block search --pattern=twentytwentyfive/event-rsvp --field=ID --format=ids` |
| 122 | + Then STDOUT should not contain: |
| 123 | + """ |
| 124 | + {PATTERN_HEADER_POST_ID} |
| 125 | + """ |
| 126 | + |
| 127 | + When I run `wp block search --pattern-namespace=twentytwentyfive --field=ID` |
| 128 | + Then STDOUT should contain: |
| 129 | + """ |
| 130 | + {PATTERN_RSVP_POST_ID} |
| 131 | + """ |
| 132 | + |
| 133 | + And STDOUT should contain: |
| 134 | + """ |
| 135 | + {PATTERN_HEADER_POST_ID} |
| 136 | + """ |
| 137 | + |
| 138 | + 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` |
| 140 | + Then STDOUT should be a number |
| 141 | + And save STDOUT as {PATTERN_IMAGE_POST_ID} |
| 142 | + |
| 143 | + When I run `wp block search --pattern-namespace=twentytwentyfive --block=core/image --field=ID` |
| 144 | + Then STDOUT should be: |
| 145 | + """ |
| 146 | + {PATTERN_IMAGE_POST_ID} |
| 147 | + """ |
| 148 | + |
| 149 | + 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` |
| 151 | + Then STDOUT should be a number |
| 152 | + And save STDOUT as {NESTED_PATTERN_IMAGE_POST_ID} |
| 153 | + |
| 154 | + When I run `wp block search --pattern=twentytwentyfive/inner-media --block=core/image --field=ID` |
| 155 | + Then STDOUT should be: |
| 156 | + """ |
| 157 | + {NESTED_PATTERN_IMAGE_POST_ID} |
| 158 | + """ |
| 159 | + |
| 160 | + When I run `wp block search --pattern=twentytwentyfive/outer-shell --block=core/image --field=ID --format=ids` |
| 161 | + Then STDOUT should not contain: |
| 162 | + """ |
| 163 | + {NESTED_PATTERN_IMAGE_POST_ID} |
| 164 | + """ |
| 165 | + |
| 166 | + Scenario: Search posts by synced pattern reference |
| 167 | + Given a pattern.html file: |
| 168 | + """ |
| 169 | + <!-- wp:paragraph --><p>Reusable</p><!-- /wp:paragraph --> |
| 170 | + """ |
| 171 | + When I run `wp block synced-pattern create pattern.html --title='Reusable Search Pattern' --porcelain` |
| 172 | + Then STDOUT should be a number |
| 173 | + And save STDOUT as {SYNCED_PATTERN_ID} |
| 174 | + |
| 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` |
| 176 | + Then STDOUT should be a number |
| 177 | + And save STDOUT as {SYNCED_PATTERN_POST_ID} |
| 178 | + |
| 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` |
| 180 | + Then STDOUT should be a number |
| 181 | + |
| 182 | + When I run `wp block search --synced-pattern={SYNCED_PATTERN_ID} --field=ID` |
| 183 | + Then STDOUT should be: |
| 184 | + """ |
| 185 | + {SYNCED_PATTERN_POST_ID} |
| 186 | + """ |
| 187 | + |
| 188 | + Scenario: Pattern and pattern namespace are mutually exclusive |
| 189 | + When I try `wp block search --pattern=twentytwentyfive/event-rsvp --pattern-namespace=twentytwentyfive` |
| 190 | + Then STDERR should contain: |
| 191 | + """ |
| 192 | + The --pattern and --pattern-namespace parameters are mutually exclusive. |
| 193 | + """ |
| 194 | + And the return code should be 1 |
| 195 | + |
| 196 | + Scenario: Block name and namespace are mutually exclusive |
| 197 | + When I try `wp block search --block=core/quote --block-namespace=core` |
| 198 | + Then STDERR should contain: |
| 199 | + """ |
| 200 | + The --block and --block-namespace parameters are mutually exclusive. |
| 201 | + """ |
| 202 | + And the return code should be 1 |
| 203 | + |
| 204 | + Scenario: Synced pattern parameter must be a positive integer |
| 205 | + When I try `wp block search --synced-pattern=0` |
| 206 | + Then STDERR should contain: |
| 207 | + """ |
| 208 | + The --synced-pattern parameter must be a positive integer post ID. |
| 209 | + """ |
| 210 | + And the return code should be 1 |
| 211 | + |
| 212 | + Scenario: Search requires at least one filter |
| 213 | + When I try `wp block search` |
| 214 | + Then STDERR should contain: |
| 215 | + """ |
| 216 | + At least one block filter is required: --block, --block-namespace, --style, --pattern, --pattern-namespace, or --synced-pattern. |
| 217 | + """ |
| 218 | + And the return code should be 1 |
0 commit comments