forked from wp-cli/wp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliases.feature
582 lines (510 loc) · 13.9 KB
/
aliases.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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
Feature: Create shortcuts to specific WordPress installs
Scenario: Alias for a path to a specific WP installation
Given a WP installation in 'foo'
And I run `mkdir bar`
And a wp-cli.yml file:
"""
@foo:
path: foo
"""
When I try `wp core is-installed`
Then STDERR should contain:
"""
Error: This does not seem to be a WordPress installation.
"""
And the return code should be 1
When I run `wp @foo core is-installed`
Then the return code should be 0
When I run `cd bar; wp @foo core is-installed`
Then the return code should be 0
Scenario: Error when invalid alias provided
Given an empty directory
When I try `wp @test option get home`
Then STDERR should be:
"""
Error: Alias '@test' not found.
"""
Scenario: Provide suggestion when invalid alias is provided
Given an empty directory
And a wp-cli.yml file:
"""
@test2:
path: foo
"""
When I try `wp @test option get home`
Then STDERR should be:
"""
Error: Alias '@test' not found.
Did you mean '@test2'?
"""
Scenario: Treat global params as local when included in alias
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
path: foo
"""
When I run `wp @foo option get home`
Then STDOUT should be:
"""
https://example.com
"""
When I try `wp @foo option get home --path=foo`
Then STDERR should contain:
"""
Parameter errors:
"""
And STDERR should contain:
"""
unknown --path parameter
"""
When I run `wp @foo eval 'echo get_current_user_id();' --user=admin`
Then STDOUT should be:
"""
1
"""
Given a wp-cli.yml file:
"""
@foo:
path: foo
user: admin
"""
When I run `wp @foo eval 'echo get_current_user_id();'`
Then STDOUT should be:
"""
1
"""
When I try `wp @foo eval 'echo get_current_user_id();' --user=admin`
Then STDERR should contain:
"""
Parameter errors:
"""
And STDERR should contain:
"""
unknown --user parameter
"""
Scenario: Support global params specific to the WordPress install, not WP-CLI generally
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
path: foo
debug: true
"""
When I run `wp @foo option get home`
Then STDOUT should be:
"""
https://example.com
"""
And STDERR should be empty
Scenario: List available aliases
Given an empty directory
And a wp-cli.yml file:
"""
@foo:
path: foo
"""
When I run `wp eval --skip-wordpress 'echo realpath( getenv( "RUN_DIR" ) );'`
Then save STDOUT as {TEST_DIR}
When I run `wp cli alias list`
Then STDOUT should be YAML containing:
"""
@all: Run command against every registered alias.
@foo:
path: {TEST_DIR}/foo
"""
When I run `wp cli aliases`
Then STDOUT should be YAML containing:
"""
@all: Run command against every registered alias.
@foo:
path: {TEST_DIR}/foo
"""
When I run `wp cli alias list --format=json`
Then STDOUT should be JSON containing:
"""
{"@all":"Run command against every registered alias.","@foo":{"path":"{TEST_DIR}/foo"}}
"""
When I run `wp cli aliases --format=json`
Then STDOUT should be JSON containing:
"""
{"@all":"Run command against every registered alias.","@foo":{"path":"{TEST_DIR}/foo"}}
"""
Scenario: Get alias information
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
ssh: user@host:/path/to/wordpress
"""
When I run `wp cli alias get @foo`
Then STDOUT should be:
"""
ssh: user@host:/path/to/wordpress
"""
When I try `wp cli alias get @someotherfoo`
Then STDERR should be:
"""
Error: No alias found with key '@someotherfoo'.
"""
Scenario: Add an alias
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
ssh: [email protected]:2222
"""
When I run `wp cli alias add @dev --set-user=wpcli --set-path=/path/to/wordpress --config=project`
Then STDOUT should be:
"""
Success: Added '@dev' alias.
"""
When I run `wp cli alias list`
Then STDOUT should be YAML containing:
"""
@all: Run command against every registered alias.
@foo:
ssh: [email protected]:2222
@dev:
user: wpcli
path: /path/to/wordpress
"""
When I try `wp cli alias add @something --config=project`
Then STDERR should be:
"""
Error: No valid arguments passed.
"""
When I try `wp cli alias add @something --set-user= --config=project`
Then STDERR should be:
"""
Error: No value passed to arguments.
"""
When I try `wp cli alias add @something --set-path=/new/path --grouping=foo,dev --config=project`
Then STDERR should be:
"""
Error: --grouping argument works alone. Found invalid arg(s) 'set-path'.
"""
Scenario: Delete an alias
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
ssh: foo@bar:/path/to/wordpress
@dev:
ssh: user@hostname:/path/to/wordpress
"""
When I run `wp cli alias delete @dev --config=project`
Then STDOUT should be:
"""
Success: Deleted '@dev' alias.
"""
When I run `wp cli alias list`
Then STDOUT should be YAML containing:
"""
@all: Run command against every registered alias.
@foo:
ssh: foo@bar:/path/to/wordpress
"""
When I try `wp cli alias delete @dev`
Then STDERR should be:
"""
Error: No alias found with key '@dev'.
"""
When I try `wp cli alias update @foo`
Then STDERR should be:
"""
Error: No valid arguments passed.
"""
Scenario: Update an alias
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
user: wpcli
@foopath:
path: /home/wpcli/sites/wpcli
@foogroup:
- @foo
- @foopath
"""
When I run `wp cli alias update @foo --set-user=newuser --config=project`
Then STDOUT should be:
"""
Success: Updated '@foo' alias.
"""
When I run `wp cli alias list`
Then STDOUT should be YAML containing:
"""
@all: Run command against every registered alias.
@foo:
user: newuser
@foopath:
path: /home/wpcli/sites/wpcli
@foogroup:
- @foo
- @foopath
"""
When I try `wp cli alias update @otherfoo --set-ssh=foo@host --set-path=/some/path`
Then STDERR should be:
"""
Error: No alias found with key '@otherfoo'.
"""
When I try `wp cli alias update @foogroup --set-ssh=foo@host`
Then STDERR should be:
"""
Error: Trying to update group alias with invalid arguments.
"""
When I try `wp cli alias update @foo --grouping=foo@host --set-user=wpcli`
Then STDERR should be:
"""
Error: --grouping argument works alone. Found invalid arg(s) 'set-user'.
"""
When I try `wp cli alias update @foo --grouping=foo@host`
Then STDERR should be:
"""
Error: Trying to update simple alias with invalid --grouping argument.
"""
When I try `wp cli alias update @foo --set-path=/new/path`
Then STDOUT should be:
"""
Success: Updated '@foo' alias.
"""
When I run `wp cli alias list`
Then STDOUT should be YAML containing:
"""
@all: Run command against every registered alias.
@foo:
user: newuser
path: /new/path
@foopath:
path: /home/wpcli/sites/wpcli
@foogroup:
- @foo
- @foopath
"""
Scenario: Defining a project alias completely overrides a global alias
Given a WP installation in 'foo'
And a config.yml file:
"""
@foo:
path: foo
"""
When I run `WP_CLI_CONFIG_PATH=config.yml wp @foo option get home`
Then STDOUT should be:
"""
https://example.com
"""
Given a wp-cli.yml file:
"""
@foo:
path: none-existent-install
"""
When I try `WP_CLI_CONFIG_PATH=config.yml wp @foo option get home`
Then STDERR should contain:
"""
Error: This does not seem to be a WordPress installation.
"""
Scenario: Use a group of aliases to run a command against multiple installs
Given a WP installation in 'foo'
And a WP installation in 'bar'
And a wp-cli.yml file:
"""
@both:
- @foo
- @bar
@invalid:
- @foo
- @baz
@foo:
path: foo
@bar:
path: bar
"""
When I run `wp @foo option update home 'http://apple.com'`
And I run `wp @foo option get home`
Then STDOUT should contain:
"""
http://apple.com
"""
When I run `wp @bar option update home 'http://google.com'`
And I run `wp @bar option get home`
Then STDOUT should contain:
"""
http://google.com
"""
When I try `wp @invalid option get home`
Then STDERR should be:
"""
Error: Group '@invalid' contains one or more invalid aliases: @baz
"""
When I run `wp @both option get home`
Then STDOUT should be:
"""
@foo
http://apple.com
@bar
http://google.com
"""
When I run `wp @both option get home --quiet`
Then STDOUT should be:
"""
http://apple.com
http://google.com
"""
Scenario: Register '@all' alias for running on one or more aliases
Given a WP installation in 'foo'
And a WP installation in 'bar'
And a wp-cli.yml file:
"""
@foo:
path: foo
@bar:
path: bar
"""
When I run `wp @foo option update home 'http://apple.com'`
And I run `wp @foo option get home`
Then STDOUT should contain:
"""
http://apple.com
"""
When I run `wp @bar option update home 'http://google.com'`
And I run `wp @bar option get home`
Then STDOUT should contain:
"""
http://google.com
"""
When I run `wp @all option get home`
Then STDOUT should be:
"""
@foo
http://apple.com
@bar
http://google.com
"""
When I run `wp @all option get home --quiet`
Then STDOUT should be:
"""
http://apple.com
http://google.com
"""
Scenario: Don't register '@all' when its already set
Given a WP installation in 'foo'
And a WP installation in 'bar'
And a wp-cli.yml file:
"""
@all:
path: foo
@bar:
path: bar
"""
When I run `wp @all option get home | wc -l | tr -d ' '`
Then STDOUT should be:
"""
1
"""
Scenario: Error when '@all' is used without aliases defined
Given an empty directory
When I try `wp @all option get home`
Then STDERR should be:
"""
Error: Cannot use '@all' when no aliases are registered.
"""
Scenario: Alias for a subsite of a multisite install
Given a WP multisite subdomain installation
And a wp-cli.yml file:
"""
url: https://example.com
@subsite:
url: https://subsite.example.com
"""
When I run `wp site create --slug=subsite`
Then STDOUT should not be empty
When I run `wp option get siteurl`
Then STDOUT should be:
"""
https://example.com
"""
# TODO: The HTTPS default is currently not forwarded to subsite creation.
When I run `wp @subsite option get siteurl`
Then STDOUT should be:
"""
http://subsite.example.com
"""
When I try `wp @subsite option get siteurl --url=subsite.example.com`
Then STDERR should be:
"""
Error: Parameter errors:
unknown --url parameter
"""
Scenario: Global parameters should be passed to grouped aliases
Given a WP installation in 'foo'
And a WP installation in 'bar'
And a wp-cli.yml file:
"""
@foo:
path: foo
@bar:
path: bar
@foobar:
- @foo
- @bar
"""
When I try `wp core is-installed --allow-root --debug`
Then STDERR should contain:
"""
Error: This does not seem to be a WordPress installation.
"""
And STDERR should contain:
"""
core is-installed --allow-root --debug
"""
And the return code should be 1
When I try `wp @foo core is-installed --allow-root --debug`
Then the return code should be 0
And STDERR should contain:
"""
@foo core is-installed --allow-root --debug
"""
When I try `cd bar; wp @bar core is-installed --allow-root --debug`
Then the return code should be 0
And STDERR should contain:
"""
@bar core is-installed --allow-root --debug
"""
When I try `wp @foobar core is-installed --allow-root --debug`
Then the return code should be 0
And STDERR should contain:
"""
@foobar core is-installed --allow-root --debug
"""
And STDERR should contain:
"""
@foo core is-installed --allow-root --debug
"""
And STDERR should contain:
"""
@bar core is-installed --allow-root --debug
"""
Scenario Outline: Check that proc_open() and proc_close() aren't disabled for grouped aliases
Given a WP installation in 'foo'
And a WP installation in 'bar'
And a wp-cli.yml file:
"""
@foo:
path: foo
@bar:
path: bar
@foobar:
- @foo
- @bar
"""
When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--ddisable_functions=<func>} @foobar core is-installed`
Then STDERR should contain:
"""
Error: Cannot do 'group alias': The PHP functions `proc_open()` and/or `proc_close()` are disabled
"""
And the return code should be 1
Examples:
| func |
| proc_open |
| proc_close |