Skip to content

Commit e97b194

Browse files
Copilotswissspidy
andcommitted
Allow underscores in plugin/theme slugs for test scaffolding
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 65d0c45 commit e97b194

4 files changed

Lines changed: 8 additions & 22 deletions

File tree

features/scaffold-block.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Feature: WordPress block code scaffolding
3131
"""
3232

3333
Scenario: Scaffold a block for an invalid plugin slug
34-
When I try `wp scaffold plugin plugin.name.with.dots`
34+
When I run `wp scaffold plugin plugin.name.with.dots`
3535
And I try `wp scaffold block some-block --plugin=plugin.name.with.dots`
3636
Then STDERR should contain:
3737
"""

features/scaffold-plugin-tests.feature

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,14 @@ Feature: Scaffold plugin unit tests
243243
When I try `wp scaffold plugin-tests my-plugin/`
244244
Then STDERR should be:
245245
"""
246-
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes.
246+
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
247247
"""
248248
And the return code should be 1
249249

250250
When I try `wp scaffold plugin-tests my-plugin\\`
251251
Then STDERR should be:
252252
"""
253-
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes.
254-
"""
255-
And the return code should be 1
256-
257-
When I try `wp scaffold plugin-tests my_plugin`
258-
Then STDERR should be:
259-
"""
260-
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters and dashes.
253+
Error: Invalid plugin slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
261254
"""
262255
And the return code should be 1
263256

features/scaffold-theme-tests.feature

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,14 @@ Feature: Scaffold theme unit tests
222222
When I try `wp scaffold theme-tests t12child/`
223223
Then STDERR should be:
224224
"""
225-
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes.
225+
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
226226
"""
227227
And the return code should be 1
228228

229229
When I try `wp scaffold theme-tests t12child\\`
230230
Then STDERR should be:
231231
"""
232-
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes.
233-
"""
234-
And the return code should be 1
235-
236-
When I try `wp scaffold theme-tests t12_child`
237-
Then STDERR should be:
238-
"""
239-
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters and dashes.
232+
Error: Invalid theme slug specified. The slug can only contain alphanumeric characters, underscores, and dashes.
240233
"""
241234
And the return code should be 1
242235

src/Scaffold_Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,9 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
829829
if ( in_array( $slug, [ '.', '..' ], true ) ) {
830830
WP_CLI::error( "Invalid {$type} slug specified. The slug cannot be '.' or '..'." );
831831
}
832-
// Validate slug contains only alphanumeric characters and dashes.
833-
if ( ! preg_match( '/^[a-zA-Z0-9-]+$/', $slug ) ) {
834-
WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters and dashes." );
832+
// Validate slug contains only alphanumeric characters, underscores, and dashes.
833+
if ( ! preg_match( '/^[a-zA-Z0-9_-]+$/', $slug ) ) {
834+
WP_CLI::error( "Invalid {$type} slug specified. The slug can only contain alphanumeric characters, underscores, and dashes." );
835835
}
836836
if ( 'theme' === $type ) {
837837
$theme = wp_get_theme( $slug );

0 commit comments

Comments
 (0)