mirror of
https://gh.wpcy.net/https://github.com/wp-cli/scaffold-command.git
synced 2026-05-03 06:05:35 +08:00
157 lines
5.5 KiB
Gherkin
157 lines
5.5 KiB
Gherkin
Feature: WordPress block code scaffolding
|
|
|
|
Background:
|
|
Given a WP install
|
|
Given I run `wp scaffold plugin movies`
|
|
And I run `wp plugin path movies --dir`
|
|
And save STDOUT as {PLUGIN_DIR}
|
|
Given I run `wp theme install p2 --activate`
|
|
And I run `wp theme path p2 --dir`
|
|
And save STDOUT as {THEME_DIR}
|
|
|
|
|
|
Scenario: Scaffold a block with an invalid slug
|
|
When I try `wp scaffold block The_Godfather`
|
|
Then STDERR should be:
|
|
"""
|
|
Error: Invalid block slug specified. Block slugs can contain only lowercase alphanumeric characters or dashes, and start with a letter.
|
|
"""
|
|
|
|
Scenario: Scaffold a block with a missing plugin and theme
|
|
When I try `wp scaffold block the-godfather`
|
|
Then STDERR should be:
|
|
"""
|
|
Error: No plugin or theme selected.
|
|
"""
|
|
|
|
Scenario: Scaffold a block for an invalid plugin
|
|
When I try `wp scaffold block the-godfather --plugin=unknown`
|
|
Then STDERR should be:
|
|
"""
|
|
Error: Can't find 'unknown' plugin.
|
|
"""
|
|
|
|
Scenario: Scaffold a block for a specific plugin
|
|
When I run `wp scaffold block the-green-mile --plugin=movies`
|
|
Then the {PLUGIN_DIR}/blocks/the-green-mile.php file should exist
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
|
|
"""
|
|
function the_green_mile_block_init() {
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
|
|
"""
|
|
$block_js = 'the-green-mile/block.js';
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
|
|
"""
|
|
$editor_css = 'the-green-mile/editor.css';
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
|
|
"""
|
|
$style_css = 'the-green-mile/style.css';
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
|
|
"""
|
|
register_block_type( 'movies/the-green-mile', array(
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain:
|
|
"""
|
|
add_action( 'init', 'the_green_mile_block_init' );
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should exist
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
|
|
"""
|
|
registerBlockType( 'movies/the-green-mile', {
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
|
|
"""
|
|
title: __( 'The green mile' ),
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
|
|
"""
|
|
category: 'widgets',
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
|
|
"""
|
|
__( 'Hello from the editor!' )
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain:
|
|
"""
|
|
__( 'Hello from the saved content!' )
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/editor.css file should exist
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/editor.css file should contain:
|
|
"""
|
|
.wp-block-movies-the-green-mile {
|
|
"""
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/style.css file should exist
|
|
And the {PLUGIN_DIR}/blocks/the-green-mile/style.css file should contain:
|
|
"""
|
|
.wp-block-movies-the-green-mile {
|
|
"""
|
|
And STDOUT should be:
|
|
"""
|
|
Success: Created block 'The green mile'.
|
|
"""
|
|
|
|
Scenario: Scaffold a block with a specific title provided
|
|
When I run `wp scaffold block shawshank-redemption --plugin=movies --title="The Shawshank Redemption"`
|
|
Then the {PLUGIN_DIR}/blocks/shawshank-redemption/block.js file should contain:
|
|
"""
|
|
title: __( 'The Shawshank Redemption' ),
|
|
"""
|
|
And STDOUT should be:
|
|
"""
|
|
Success: Created block 'The Shawshank Redemption'.
|
|
"""
|
|
|
|
Scenario: Scaffold a block with a specific dashicon provided
|
|
When I run `wp scaffold block forrest-gump --plugin=movies --dashicon=movie`
|
|
Then the {PLUGIN_DIR}/blocks/forrest-gump/block.js file should contain:
|
|
"""
|
|
icon: 'movie',
|
|
"""
|
|
And STDOUT should be:
|
|
"""
|
|
Success: Created block 'Forrest gump'.
|
|
"""
|
|
|
|
Scenario: Scaffold a block with a specific category provided
|
|
When I run `wp scaffold block pulp-fiction --plugin=movies --category=embed`
|
|
Then the {PLUGIN_DIR}/blocks/pulp-fiction/block.js file should contain:
|
|
"""
|
|
category: 'embed',
|
|
"""
|
|
And STDOUT should be:
|
|
"""
|
|
Success: Created block 'Pulp fiction'.
|
|
"""
|
|
|
|
Scenario: Scaffold a block for an active theme
|
|
When I run `wp scaffold block fight-club --theme`
|
|
Then the {THEME_DIR}/blocks/fight-club.php file should exist
|
|
And the {THEME_DIR}/blocks/fight-club/block.js file should exist
|
|
And the {THEME_DIR}/blocks/fight-club/editor.css file should exist
|
|
And the {THEME_DIR}/blocks/fight-club/style.css file should exist
|
|
And STDOUT should be:
|
|
"""
|
|
Success: Created block 'Fight club'.
|
|
"""
|
|
|
|
Scenario: Scaffold a block for an invalid theme
|
|
When I try `wp scaffold block intouchables --theme=unknown`
|
|
Then STDERR should be:
|
|
"""
|
|
Error: Can't find 'unknown' theme.
|
|
"""
|
|
|
|
Scenario: Scaffold a block for a specific theme
|
|
When I run `wp scaffold block intouchables --theme=p2`
|
|
Then the {THEME_DIR}/blocks/intouchables.php file should exist
|
|
And the {THEME_DIR}/blocks/intouchables/block.js file should exist
|
|
And the {THEME_DIR}/blocks/intouchables/editor.css file should exist
|
|
And the {THEME_DIR}/blocks/intouchables/style.css file should exist
|
|
And STDOUT should be:
|
|
"""
|
|
Success: Created block 'Intouchables'.
|
|
"""
|