|
| 1 | +Feature: WordPress block code scaffolding |
| 2 | + |
| 3 | + Background: |
| 4 | + Given a WP install |
| 5 | + Given I run `wp scaffold plugin movies` |
| 6 | + And I run `wp plugin path movies --dir` |
| 7 | + And save STDOUT as {PLUGIN_DIR} |
| 8 | + Given I run `wp theme install p2 --activate` |
| 9 | + And I run `wp theme path p2 --dir` |
| 10 | + And save STDOUT as {THEME_DIR} |
| 11 | + |
| 12 | + |
| 13 | + Scenario: Scaffold a block with an invalid slug |
| 14 | + When I try `wp scaffold block The_Godfather` |
| 15 | + Then STDERR should be: |
| 16 | + """ |
| 17 | + Error: Invalid block slug specified. Block slugs can contain only lowercase alphanumeric characters or dashes, and start with a letter. |
| 18 | + """ |
| 19 | + |
| 20 | + Scenario: Scaffold a block with a missing plugin and theme |
| 21 | + When I try `wp scaffold block the-godfather` |
| 22 | + Then STDERR should be: |
| 23 | + """ |
| 24 | + Error: No plugin or theme selected. |
| 25 | + """ |
| 26 | + |
| 27 | + Scenario: Scaffold a block for an invalid plugin |
| 28 | + When I try `wp scaffold block the-godfather --plugin=unknown` |
| 29 | + Then STDERR should be: |
| 30 | + """ |
| 31 | + Error: Can't find 'unknown' plugin. |
| 32 | + """ |
| 33 | + |
| 34 | + Scenario: Scaffold a block for a specific plugin |
| 35 | + When I run `wp scaffold block the-green-mile --plugin=movies` |
| 36 | + Then the {PLUGIN_DIR}/blocks/the-green-mile.php file should exist |
| 37 | + And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain: |
| 38 | + """ |
| 39 | + function the_green_mile_enqueue_block_editor_assets() { |
| 40 | + """ |
| 41 | + And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain: |
| 42 | + """ |
| 43 | + $block_js = 'the-green-mile/block.js'; |
| 44 | + """ |
| 45 | + And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain: |
| 46 | + """ |
| 47 | + $editor_css = 'the-green-mile/editor.css'; |
| 48 | + """ |
| 49 | + And the {PLUGIN_DIR}/blocks/the-green-mile.php file should contain: |
| 50 | + """ |
| 51 | + add_action( 'enqueue_block_editor_assets', 'the_green_mile_enqueue_block_editor_assets' ); |
| 52 | + """ |
| 53 | + And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should exist |
| 54 | + And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain: |
| 55 | + """ |
| 56 | + wp.blocks.registerBlockType( 'movies/the-green-mile', { |
| 57 | + """ |
| 58 | + And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain: |
| 59 | + """ |
| 60 | + title: __( 'The green mile', 'movies' ), |
| 61 | + """ |
| 62 | + And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain: |
| 63 | + """ |
| 64 | + category: 'widgets', |
| 65 | + """ |
| 66 | + And the {PLUGIN_DIR}/blocks/the-green-mile/block.js file should contain: |
| 67 | + """ |
| 68 | + __( 'Replace with your content!', 'movies' ) |
| 69 | + """ |
| 70 | + And the {PLUGIN_DIR}/blocks/the-green-mile/editor.css file should exist |
| 71 | + And the {PLUGIN_DIR}/blocks/the-green-mile/editor.css file should contain: |
| 72 | + """ |
| 73 | + .wp-block-movies-the-green-mile { |
| 74 | + """ |
| 75 | + And STDOUT should be: |
| 76 | + """ |
| 77 | + Success: Created block 'The green mile'. |
| 78 | + """ |
| 79 | + |
| 80 | + Scenario: Scaffold a block with a specific title provided |
| 81 | + When I run `wp scaffold block shawshank-redemption --plugin=movies --title="The Shawshank Redemption"` |
| 82 | + Then the {PLUGIN_DIR}/blocks/shawshank-redemption/block.js file should contain: |
| 83 | + """ |
| 84 | + title: __( 'The Shawshank Redemption', 'movies' ), |
| 85 | + """ |
| 86 | + And STDOUT should be: |
| 87 | + """ |
| 88 | + Success: Created block 'The Shawshank Redemption'. |
| 89 | + """ |
| 90 | + |
| 91 | + Scenario: Scaffold a block with a specific dashicon provided |
| 92 | + When I run `wp scaffold block forrest-gump --plugin=movies --dashicon=movie` |
| 93 | + Then the {PLUGIN_DIR}/blocks/forrest-gump/block.js file should contain: |
| 94 | + """ |
| 95 | + icon: 'movie', |
| 96 | + """ |
| 97 | + And STDOUT should be: |
| 98 | + """ |
| 99 | + Success: Created block 'Forrest gump'. |
| 100 | + """ |
| 101 | + |
| 102 | + Scenario: Scaffold a block with a specific category provided |
| 103 | + When I run `wp scaffold block pulp-fiction --plugin=movies --category=embed` |
| 104 | + Then the {PLUGIN_DIR}/blocks/pulp-fiction/block.js file should contain: |
| 105 | + """ |
| 106 | + category: 'embed', |
| 107 | + """ |
| 108 | + And STDOUT should be: |
| 109 | + """ |
| 110 | + Success: Created block 'Pulp fiction'. |
| 111 | + """ |
| 112 | + |
| 113 | + Scenario: Scaffold a block with a specific textdomain provided |
| 114 | + When I run `wp scaffold block inception --plugin=movies --textdomain=MY-MOVIES` |
| 115 | + Then the {PLUGIN_DIR}/blocks/inception/block.js file should contain: |
| 116 | + """ |
| 117 | + __( 'Replace with your content!', 'MY-MOVIES' ) |
| 118 | + """ |
| 119 | + And STDOUT should be: |
| 120 | + """ |
| 121 | + Success: Created block 'Inception'. |
| 122 | + """ |
| 123 | + |
| 124 | + Scenario: Scaffold a block for an active theme |
| 125 | + When I run `wp scaffold block fight-club --theme` |
| 126 | + Then the {THEME_DIR}/blocks/fight-club.php file should exist |
| 127 | + And the {THEME_DIR}/blocks/fight-club/block.js file should exist |
| 128 | + And the {THEME_DIR}/blocks/fight-club/editor.css file should exist |
| 129 | + And STDOUT should be: |
| 130 | + """ |
| 131 | + Success: Created block 'Fight club'. |
| 132 | + """ |
| 133 | + |
| 134 | + Scenario: Scaffold a block for an invalid theme |
| 135 | + When I try `wp scaffold block intouchables --theme=unknown` |
| 136 | + Then STDERR should be: |
| 137 | + """ |
| 138 | + Error: Can't find 'unknown' theme. |
| 139 | + """ |
| 140 | + |
| 141 | + Scenario: Scaffold a block for a specific theme |
| 142 | + When I run `wp scaffold block intouchables --theme=p2` |
| 143 | + Then the {THEME_DIR}/blocks/intouchables.php file should exist |
| 144 | + And the {THEME_DIR}/blocks/intouchables/block.js file should exist |
| 145 | + And the {THEME_DIR}/blocks/intouchables/editor.css file should exist |
| 146 | + And STDOUT should be: |
| 147 | + """ |
| 148 | + Success: Created block 'Intouchables'. |
| 149 | + """ |
0 commit comments