forked from wp-cli/scaffold-command
/
scaffold.feature
526 lines (468 loc) · 16.4 KB
/
scaffold.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
Feature: WordPress code scaffolding
@theme
Scenario: Scaffold a child theme
Given a WP install
Given I run `wp theme path`
And save STDOUT as {THEME_DIR}
When I run `wp scaffold child-theme zombieland --parent_theme=umbrella --theme_name=Zombieland --author=Tallahassee --author_uri=https://wp-cli.org --theme_uri=http://www.zombieland.com`
Then the {THEME_DIR}/zombieland/style.css file should exist
And the {THEME_DIR}/zombieland/functions.php file should exist
And STDOUT should be:
"""
Success: Created '{THEME_DIR}/zombieland'.
"""
And the {THEME_DIR}/zombieland/.editorconfig file should exist
Scenario: Scaffold a child theme with only --parent_theme parameter
Given a WP install
Given I run `wp theme path`
And save STDOUT as {THEME_DIR}
When I run `wp scaffold child-theme hello-world --parent_theme=simple-life`
Then STDOUT should not be empty
And the {THEME_DIR}/hello-world/style.css file should exist
And the {THEME_DIR}/hello-world/style.css file should contain:
"""
Theme Name: Hello-world
"""
Scenario: Scaffold a child theme with non existing parent theme and also activate parameter
Given a WP install
When I try `wp scaffold child-theme hello-world --parent_theme=just-test --activate --quiet`
Then STDERR should contain:
"""
Error: The parent theme is missing. Please install the "just-test" parent theme.
"""
And the return code should be 1
Scenario: Scaffold a child theme with non existing parent theme and also network activate parameter
Given a WP install
When I try `wp scaffold child-theme hello-world --parent_theme=just-test --enable-network --quiet`
Then STDERR should contain:
"""
Error: This is not a multisite install.
"""
And the return code should be 1
Scenario: Scaffold a child theme and network enable it
Given a WP multisite install
When I run `wp scaffold child-theme zombieland --parent_theme=umbrella --theme_name=Zombieland --author=Tallahassee --author_uri=https://wp-cli.org --theme_uri=http://www.zombieland.com --enable-network`
Then STDOUT should contain:
"""
Success: Network enabled the 'Zombieland' theme.
"""
Scenario: Scaffold a child theme with invalid slug
Given a WP install
When I try `wp scaffold child-theme . --parent_theme=simple-life`
Then STDERR should contain:
"""
Error: Invalid theme slug specified.
"""
And the return code should be 1
When I try `wp scaffold child-theme ../ --parent_theme=simple-life`
Then STDERR should contain:
"""
Error: Invalid theme slug specified.
"""
And the return code should be 1
@tax @cpt
Scenario: Scaffold a Custom Taxonomy and Custom Post Type and write it to active theme
Given a WP install
Given I run `wp eval 'echo STYLESHEETPATH;'`
And save STDOUT as {STYLESHEETPATH}
When I run `wp scaffold taxonomy zombie-speed --theme`
Then the {STYLESHEETPATH}/taxonomies/zombie-speed.php file should exist
When I run `wp scaffold post-type zombie --theme`
Then the {STYLESHEETPATH}/post-types/zombie.php file should exist
And STDOUT should be:
"""
Success: Created '{STYLESHEETPATH}/post-types/zombie.php'.
"""
When I run `wp scaffold post-type zombie`
Then STDOUT should contain:
"""
register_post_type( 'zombie'
"""
And STDOUT should contain:
"""
add_filter( 'post_updated_messages'
"""
When I run `wp scaffold post-type zombie --raw`
Then STDOUT should not contain:
"""
add_filter( 'post_updated_messages'
"""
# Test for all flags but --label, --theme, --plugin and --raw
@tax
Scenario: Scaffold a Custom Taxonomy and attach it to CPTs including one that is prefixed and has a text domain
Given a WP install
When I run `wp scaffold taxonomy zombie-speed --post_types="prefix-zombie,wraith" --textdomain=zombieland`
Then STDOUT should contain:
"""
__( 'Zombie speeds'
"""
And STDOUT should contain:
"""
array( 'prefix-zombie', 'wraith' )
"""
And STDOUT should contain:
"""
__( 'Zombie speeds', 'zombieland'
"""
@tax
Scenario: Scaffold a Custom Taxonomy with label "Speed"
Given a WP install
When I run `wp scaffold taxonomy zombie-speed --label="Speed"`
Then STDOUT should contain:
"""
__( 'Speeds'
"""
And STDOUT should contain:
"""
_x( 'Speed', 'taxonomy general name',
"""
# Test for all flags but --label, --theme, --plugin and --raw
@cpt
Scenario: Scaffold a Custom Post Type
Given a WP install
When I run `wp scaffold post-type zombie --textdomain=zombieland`
Then STDOUT should contain:
"""
__( 'Zombies'
"""
And STDOUT should contain:
"""
__( 'Zombies', 'zombieland'
"""
And STDOUT should contain:
"""
'menu_icon' => 'dashicons-admin-post',
"""
Scenario: CPT slug is too long
Given a WP install
When I try `wp scaffold post-type slugiswaytoolonginfact`
Then STDERR should be:
"""
Error: Post type slugs cannot exceed 20 characters in length.
"""
And the return code should be 1
@cpt
Scenario: Scaffold a Custom Post Type with label
Given a WP install
When I run `wp scaffold post-type zombie --label="Brain eater"`
Then STDOUT should contain:
"""
__( 'Brain eaters'
"""
Scenario: Scaffold a Custom Post Type with dashicon
Given a WP install
When I run `wp scaffold post-type zombie --dashicon="art"`
Then STDOUT should contain:
"""
'menu_icon' => 'dashicons-art',
"""
Scenario: Scaffold a Custom Post Type with dashicon in the case of passing "dashicon-info"
Given a WP install
When I run `wp scaffold post-type zombie --dashicon="dashicon-info"`
Then STDOUT should contain:
"""
'menu_icon' => 'dashicons-info',
"""
Scenario: Scaffold a Custom Post Type with dashicon in the case of passing "dashicons-info"
Given a WP install
When I run `wp scaffold post-type zombie --dashicon="dashicons-info"`
Then STDOUT should contain:
"""
'menu_icon' => 'dashicons-info',
"""
Scenario: Scaffold a plugin
Given a WP install
Given I run `wp plugin path`
And save STDOUT as {PLUGIN_DIR}
Given I run `wp core version`
And save STDOUT as {WP_VERSION}
When I run `wp scaffold plugin hello-world --plugin_author="Hello World Author"`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/hello-world/.gitignore file should exist
And the {PLUGIN_DIR}/hello-world/.editorconfig file should exist
And the {PLUGIN_DIR}/hello-world/hello-world.php file should exist
And the {PLUGIN_DIR}/hello-world/readme.txt file should exist
And the {PLUGIN_DIR}/hello-world/package.json file should exist
And the {PLUGIN_DIR}/hello-world/Gruntfile.js file should exist
And the {PLUGIN_DIR}/hello-world/.gitignore file should contain:
"""
.DS_Store
phpcs.xml
phpunit.xml
Thumbs.db
wp-cli.local.yml
node_modules/
"""
And the {PLUGIN_DIR}/hello-world/.distignore file should contain:
"""
.git
.gitignore
"""
And the {PLUGIN_DIR}/hello-world/.phpcs.xml.dist file should contain:
"""
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-"/>
"""
And the {PLUGIN_DIR}/hello-world/hello-world.php file should contain:
"""
* Plugin Name: Hello World
"""
And the {PLUGIN_DIR}/hello-world/hello-world.php file should contain:
"""
* Version: 0.1.0
"""
And the {PLUGIN_DIR}/hello-world/hello-world.php file should contain:
"""
* @package Hello_World
"""
And the {PLUGIN_DIR}/hello-world/readme.txt file should contain:
"""
Stable tag: 0.1.0
"""
And the {PLUGIN_DIR}/hello-world/readme.txt file should contain:
"""
Tested up to: {WP_VERSION}
"""
When I run `cat {PLUGIN_DIR}/hello-world/package.json`
Then STDOUT should be JSON containing:
"""
{"author":"Hello World Author"}
"""
And STDOUT should be JSON containing:
"""
{"version":"0.1.0"}
"""
Scenario: Scaffold a plugin by prompting
Given a WP install
And a session file:
"""
hello-world
Hello World
An awesome introductory plugin for WordPress
WP-CLI
https://wp-cli.org
https://wp-cli.org
n
travis
Y
n
n
"""
When I run `wp scaffold plugin --prompt < session`
Then STDOUT should not be empty
And the wp-content/plugins/hello-world/hello-world.php file should exist
And the wp-content/plugins/hello-world/readme.txt file should exist
And the wp-content/plugins/hello-world/tests directory should exist
When I run `wp plugin status hello-world`
Then STDOUT should contain:
"""
Status: Active
"""
And STDOUT should contain:
"""
Name: Hello World
"""
And STDOUT should contain:
"""
Description: An awesome introductory plugin for WordPress
"""
Scenario: Scaffold a plugin and activate it
Given a WP install
When I run `wp scaffold plugin hello-world --activate`
Then STDOUT should contain:
"""
Plugin 'hello-world' activated.
"""
Scenario: Scaffold a plugin and network activate it
Given a WP multisite install
When I run `wp scaffold plugin hello-world --activate-network`
Then STDOUT should contain:
"""
Plugin 'hello-world' network activated.
"""
Scenario: Scaffold a plugin with invalid slug
Given a WP install
When I try `wp scaffold plugin .`
Then STDERR should contain:
"""
Error: Invalid plugin slug specified.
"""
And the return code should be 1
When I try `wp scaffold plugin ../`
Then STDERR should contain:
"""
Error: Invalid plugin slug specified.
"""
And the return code should be 1
Scenario: Scaffold starter code for a theme
Given a WP install
Given I run `wp theme path`
And save STDOUT as {THEME_DIR}
When I run `wp scaffold _s starter-theme`
Then STDOUT should contain:
"""
Success: Created theme 'Starter-theme'.
"""
And the {THEME_DIR}/starter-theme/style.css file should exist
And the {THEME_DIR}/starter-theme/.editorconfig file should exist
Scenario: Scaffold starter code for a theme with sass
Given a WP install
Given I run `wp theme path`
And save STDOUT as {THEME_DIR}
When I run `wp scaffold _s starter-theme --sassify`
Then STDOUT should contain:
"""
Success: Created theme 'Starter-theme'.
"""
And the {THEME_DIR}/starter-theme/sass directory should exist
Scenario: Scaffold starter code for a WooCommerce theme
Given a WP install
Given I run `wp theme path`
And save STDOUT as {THEME_DIR}
When I run `wp scaffold _s starter-theme --woocommerce`
Then STDOUT should contain:
"""
Success: Created theme 'Starter-theme'.
"""
And the {THEME_DIR}/starter-theme/woocommerce.css file should exist
And the {THEME_DIR}/starter-theme/inc/woocommerce.php file should exist
Scenario: Scaffold starter code for a theme and activate it
Given a WP install
When I run `wp scaffold _s starter-theme --activate`
Then STDOUT should contain:
"""
Success: Switched to 'Starter-theme' theme.
"""
Scenario: Scaffold starter code for a theme with invalid slug
Given a WP install
When I try `wp scaffold _s .`
Then STDERR should contain:
"""
Error: Invalid theme slug specified.
"""
And the return code should be 1
When I try `wp scaffold _s ../`
Then STDERR should contain:
"""
Error: Invalid theme slug specified.
"""
And the return code should be 1
When I try `wp scaffold _s 1themestartingwithnumber`
Then STDERR should contain:
"""
Error: Invalid theme slug specified. Theme slugs can only contain letters, numbers, underscores and hyphens, and can only start with a letter or underscore.
"""
And the return code should be 1
Scenario: Scaffold plugin and tests for non-standard plugin directory
Given a WP install
When I run `wp scaffold plugin custom-plugin --dir=wp-content/mu-plugins --skip-tests`
Then STDOUT should not be empty
And the wp-content/mu-plugins/custom-plugin/custom-plugin.php file should exist
And the wp-content/mu-plugins/custom-plugin/tests directory should not exist
When I try `wp scaffold plugin-tests --dir=wp-content/mu-plugins/incorrect-custom-plugin`
Then STDERR should contain:
"""
Error: Invalid plugin directory specified.
"""
And the return code should be 1
When I run `wp scaffold plugin-tests --dir=wp-content/mu-plugins/custom-plugin`
Then STDOUT should contain:
"""
Success: Created test files.
"""
And the wp-content/mu-plugins/custom-plugin/tests directory should exist
And the wp-content/mu-plugins/custom-plugin/tests/bootstrap.php file should exist
And the wp-content/mu-plugins/custom-plugin/tests/bootstrap.php file should contain:
"""
require dirname( dirname( __FILE__ ) ) . '/custom-plugin.php';
"""
Scenario: Scaffold tests for a plugin with a different slug than plugin directory
Given a WP install
And a wp-content/mu-plugins/custom-plugin2/custom-plugin-slug.php file:
"""
<?php
/**
* Plugin Name: Handbook
* Description: Features for a handbook, complete with glossary and table of contents
* Author: Nacin
*/
"""
When I run `wp scaffold plugin-tests custom-plugin-slug --dir=wp-content/mu-plugins/custom-plugin2`
Then STDOUT should contain:
"""
Success: Created test files.
"""
And the wp-content/mu-plugins/custom-plugin2/tests directory should exist
And the wp-content/mu-plugins/custom-plugin2/tests/bootstrap.php file should exist
And the wp-content/mu-plugins/custom-plugin2/tests/bootstrap.php file should contain:
"""
require dirname( dirname( __FILE__ ) ) . '/custom-plugin-slug.php';
"""
Scenario: Scaffold tests parses plugin readme.txt
Given a WP install
When I run `wp core version`
Then save STDOUT as {WP_VERSION}
When I run `wp plugin path`
Then save STDOUT as {PLUGIN_DIR}
When I run `wp scaffold plugin hello-world`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/hello-world/readme.txt file should exist
And the {PLUGIN_DIR}/hello-world/.travis.yml file should exist
And the {PLUGIN_DIR}/hello-world/.travis.yml file should contain:
"""
matrix:
include:
- php: 7.2
env: WP_VERSION=latest
- php: 7.1
env: WP_VERSION=latest
- php: 7.0
env: WP_VERSION=latest
- php: 5.6
env: WP_VERSION=4.5
- php: 5.6
env: WP_VERSION=latest
- php: 5.6
env: WP_VERSION=trunk
- php: 5.6
env: WP_TRAVISCI=phpcs
- php: 5.3
env: WP_VERSION=latest
"""
Scenario: Scaffold starter code for a theme and network enable it
Given a WP multisite install
When I run `wp scaffold _s starter-theme --enable-network`
Then STDOUT should contain:
"""
Success: Network enabled the 'Starter-theme' theme.
"""
Scenario: Scaffold starter code for a theme, but can't unzip theme files
Given a WP install
And a misconfigured WP_CONTENT_DIR constant directory
When I try `wp scaffold _s starter-theme`
Then STDERR should contain:
"""
Error: Could not decompress your theme files
"""
And the return code should be 1
Scenario: Overwrite existing files
Given a WP install
When I run `wp scaffold plugin test`
And I try `wp scaffold plugin test --force`
Then STDERR should contain:
"""
already exists
"""
And STDOUT should contain:
"""
Replacing
"""
And the return code should be 0
Scenario: Scaffold tests for invalid plugin directory
Given a WP install
When I try `wp scaffold plugin-tests incorrect-custom-plugin`
Then STDERR should contain:
"""
Error: Invalid plugin slug specified.
"""
And the return code should be 1