/
theme.feature
608 lines (493 loc) · 16.8 KB
/
theme.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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
Feature: Manage WordPress themes
Scenario: Installing and deleting theme
Given a WP install
When I run `wp theme install p2`
Then STDOUT should not be empty
When I run `wp theme status p2`
Then STDOUT should contain:
"""
Theme p2 details:
Name: P2
"""
When I run `wp theme path p2`
Then STDOUT should contain:
"""
/themes/p2/style.css
"""
When I run `wp option get stylesheet`
Then save STDOUT as {PREVIOUS_THEME}
When I run `wp theme activate p2`
Then STDOUT should be:
"""
Success: Switched to 'P2' theme.
"""
When I try `wp theme delete p2`
Then STDERR should be:
"""
Warning: Can't delete the currently active theme: p2
Error: No themes deleted.
"""
And STDOUT should be empty
And the return code should be 1
When I run `wp theme activate {PREVIOUS_THEME}`
Then STDOUT should not be empty
When I run `wp theme delete p2`
Then STDOUT should not be empty
When I try the previous command again
Then STDERR should be:
"""
Warning: The 'p2' theme could not be found.
"""
And STDOUT should be:
"""
Success: Theme already deleted.
"""
And the return code should be 0
When I run `wp theme list`
Then STDOUT should not be empty
Scenario: Checking theme status without theme parameter
Given a WP install
When I run `wp theme install classic --activate`
And I run `wp theme list --field=name --status=inactive | xargs wp theme delete`
And I run `wp theme status`
Then STDOUT should be:
"""
1 installed theme:
A classic 1.6
Legend: A = Active
"""
Scenario: Install a theme, activate, then force install an older version of the theme
Given a WP install
When I run `wp theme install p2 --version=1.4.2`
Then STDOUT should not be empty
When I run `wp theme list --name=p2 --field=update_version`
Then STDOUT should not be empty
And save STDOUT as {UPDATE_VERSION}
When I run `wp theme list`
Then STDOUT should be a table containing rows:
| name | status | update | version | update_version | auto_update |
| p2 | inactive | available | 1.4.2 | {UPDATE_VERSION} | off |
When I run `wp theme activate p2`
Then STDOUT should not be empty
# Ensure no other themes interfere with update.
When I run `wp theme list --status=inactive --field=name | xargs wp theme delete`
Then STDOUT should contain:
"""
Success: Deleted
"""
When I run `wp theme install p2 --version=1.4.1 --force`
Then STDOUT should not be empty
When I run `wp theme list`
Then STDOUT should be a table containing rows:
| name | status | update | version | update_version | auto_update |
| p2 | active | available | 1.4.1 | {UPDATE_VERSION} | off |
When I try `wp theme update`
Then STDERR should be:
"""
Error: Please specify one or more themes, or use --all.
"""
And the return code should be 1
When I run `wp theme update --all --format=summary | grep 'updated successfully from'`
Then STDOUT should contain:
"""
P2 updated successfully from version 1.4.1 to version
"""
When I run `wp theme install p2 --version=1.4.1 --force`
Then STDOUT should not be empty
When I run `wp theme update --all`
Then STDOUT should contain:
"""
Success: Updated 1 of 1 themes.
"""
Scenario: Exclude theme from bulk updates.
Given a WP install
When I run `wp theme install p2 --version=1.4.1 --force`
Then STDOUT should contain:
"""
Downloading install
"""
And STDOUT should contain:
"""
package from https://downloads.wordpress.org/theme/p2.1.4.1.zip...
"""
When I run `wp theme activate p2`
Then STDOUT should not be empty
# Ensure no other themes interfere with update.
When I run `wp theme list --status=inactive --field=name | xargs wp theme delete`
Then STDOUT should contain:
"""
Success: Deleted
"""
When I run `wp theme status p2`
Then STDOUT should contain:
"""
Update available
"""
When I run `wp theme update --all --exclude=p2 | grep 'Skipped'`
Then STDOUT should contain:
"""
p2
"""
When I run `wp theme status p2`
Then STDOUT should contain:
"""
Update available
"""
Scenario: Get the path of an installed theme
Given a WP install
When I run `wp theme install p2`
Then STDOUT should not be empty
When I run `wp theme path p2 --dir`
Then STDOUT should contain:
"""
wp-content/themes/p2
"""
Scenario: Activate an already active theme
Given a WP install
When I run `wp theme install p2`
Then STDOUT should not be empty
When I run `wp theme activate p2`
Then STDOUT should be:
"""
Success: Switched to 'P2' theme.
"""
When I try `wp theme activate p2`
Then STDERR should be:
"""
Warning: The 'P2' theme is already active.
"""
And STDOUT should be empty
And the return code should be 0
Scenario: Flag `--skip-update-check` skips update check when running `wp theme list`
Given a WP install
When I run `wp theme install astra --version=1.0.0`
Then STDOUT should contain:
"""
Theme installed successfully.
"""
When I run `wp theme list --fields=name,status,update`
Then STDOUT should be a table containing rows:
| name | status | update |
| astra | inactive | available |
When I run `wp transient delete update_themes --network`
Then STDOUT should be:
"""
Success: Transient deleted.
"""
When I run `wp theme list --fields=name,status,update --skip-update-check`
Then STDOUT should be a table containing rows:
| name | status | update |
| astra | inactive | none |
Scenario: Install a theme when the theme directory doesn't yet exist
Given a WP install
When I run `rm -rf wp-content/themes`
And I run `if test -d wp-content/themes; then echo "fail"; fi`
Then STDOUT should be empty
When I run `wp theme install p2 --activate`
Then STDOUT should not be empty
When I run `wp theme list --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| p2 | active |
Scenario: Attempt to activate or fetch a broken theme
Given a WP install
When I run `mkdir -pv wp-content/themes/myth`
Then the wp-content/themes/myth directory should exist
When I try `wp theme activate myth`
Then STDERR should contain:
"""
Error: Stylesheet is missing.
"""
And STDOUT should be empty
And the return code should be 1
When I try `wp theme get myth`
Then STDERR should contain:
"""
Error: Stylesheet is missing.
"""
And STDOUT should be empty
And the return code should be 1
When I try `wp theme status myth`
Then STDERR should be:
"""
Error: Stylesheet is missing.
"""
And STDOUT should be empty
And the return code should be 1
When I run `wp theme install myth --force`
Then STDOUT should contain:
"""
Theme updated successfully.
"""
Scenario: Enabling and disabling a theme
Given a WP multisite install
And I run `wp theme install moina`
And I run `wp theme install moina-blog`
When I try `wp option get allowedthemes`
Then the return code should be 1
# STDERR may or may not be empty, depending on WP-CLI version.
And STDOUT should be empty
When I run `wp theme enable moina-blog`
Then STDOUT should contain:
"""
Success: Enabled the 'Moina Blog' theme.
"""
When I run `wp option get allowedthemes`
Then STDOUT should contain:
"""
'moina-blog' => true
"""
When I run `wp theme disable moina-blog`
Then STDOUT should contain:
"""
Success: Disabled the 'Moina Blog' theme.
"""
When I run `wp option get allowedthemes`
Then STDOUT should not contain:
"""
'moina-blog' => true
"""
When I run `wp theme enable moina-blog --activate`
Then STDOUT should contain:
"""
Success: Enabled the 'Moina Blog' theme.
Success: Switched to 'Moina Blog' theme.
"""
# Hybrid_Registry throws warning for PHP 8+.
When I try `wp network-meta get 1 allowedthemes`
Then STDOUT should not contain:
"""
'moina-blog' => true
"""
# Hybrid_Registry throws warning for PHP 8+.
When I try `wp theme enable moina-blog --network`
Then STDOUT should contain:
"""
Success: Network enabled the 'Moina Blog' theme.
"""
# Hybrid_Registry throws warning for PHP 8+.
When I try `wp network-meta get 1 allowedthemes`
Then STDOUT should contain:
"""
'moina-blog' => true
"""
# Hybrid_Registry throws warning for PHP 8+.
When I try `wp theme disable moina-blog --network`
Then STDOUT should contain:
"""
Success: Network disabled the 'Moina Blog' theme.
"""
# Hybrid_Registry throws warning for PHP 8+.
When I try `wp network-meta get 1 allowedthemes`
Then STDOUT should not contain:
"""
'moina-blog' => true
"""
Scenario: Enabling and disabling a theme without multisite
Given a WP install
When I try `wp theme enable p2`
Then STDERR should contain:
"""
Error: This is not a multisite install
"""
And STDOUT should be empty
And the return code should be 1
When I try `wp theme disable p2`
Then STDERR should contain:
"""
Error: This is not a multisite install
"""
And STDOUT should be empty
And the return code should be 1
Scenario: Install and attempt to activate a child theme without its parent
Given a WP install
And I run `wp theme install moina-blog`
And I run `rm -rf wp-content/themes/moina`
When I try `wp theme activate moina-blog`
Then STDERR should contain:
"""
Error: The parent theme is missing. Please install the "moina" parent theme.
"""
And STDOUT should be empty
And the return code should be 1
Scenario: List an active theme with its parent
Given a WP install
And I run `wp theme install moina`
And I run `wp theme install --activate moina-blog`
# Hybrid_Registry throws warning for PHP 8+.
When I try `wp theme list --fields=name,status`
Then STDOUT should be a table containing rows:
| name | status |
| moina-blog | active |
| moina | parent |
Scenario: When updating a theme --format should be the same when using --dry-run
Given a WP install
When I run `wp theme install --force twentytwelve --version=1.0`
Then STDOUT should not be empty
When I run `wp theme list --name=twentytwelve --field=update_version`
And save STDOUT as {UPDATE_VERSION}
When I run `wp theme update twentytwelve --format=summary --dry-run`
Then STDOUT should contain:
"""
Available theme updates:
Twenty Twelve update from version 1.0 to version {UPDATE_VERSION}
"""
When I run `wp theme update twentytwelve --format=json --dry-run`
Then STDOUT should be JSON containing:
"""
[{"name":"twentytwelve","status":"inactive","version":"1.0","update_version":"{UPDATE_VERSION}"}]
"""
When I run `wp theme update twentytwelve --format=csv --dry-run`
Then STDOUT should contain:
"""
name,status,version,update_version
twentytwelve,inactive,1.0,{UPDATE_VERSION}
"""
Scenario: When updating a theme --dry-run cannot be used when specifying a specific version.
Given a WP install
When I try `wp theme update --all --version=whatever --dry-run`
Then STDERR should be:
"""
Error: --dry-run cannot be used together with --version.
"""
And the return code should be 1
Scenario: Check json and csv formats when updating a theme
Given a WP install
When I run `wp theme install --force twentytwelve --version=1.0`
Then STDOUT should not be empty
When I run `wp theme list --name=twentytwelve --field=update_version`
And save STDOUT as {UPDATE_VERSION}
When I run `wp theme update twentytwelve --format=json`
Then STDOUT should contain:
"""
[{"name":"twentytwelve","old_version":"1.0","new_version":"{UPDATE_VERSION}","status":"Updated"}]
"""
When I run `wp theme install --force twentytwelve --version=1.0`
Then STDOUT should not be empty
When I run `wp theme update twentytwelve --format=csv`
Then STDOUT should contain:
"""
name,old_version,new_version,status
twentytwelve,1.0,{UPDATE_VERSION},Updated
"""
Scenario: Automatically install parent theme for a child theme
Given a WP install
When I try `wp theme status moina`
Then STDERR should contain:
"""
Error: The 'moina' theme could not be found.
"""
And STDOUT should be empty
And the return code should be 1
When I run `wp theme install moina-blog`
Then STDOUT should contain:
"""
This theme requires a parent theme. Checking if it is installed
"""
When I run `wp theme status moina`
Then STDOUT should contain:
"""
Theme moina details:
"""
And STDERR should be empty
Scenario: Get status field in theme detail
Given a WP install
When I run `wp theme install p2`
Then STDOUT should not be empty
When I run `wp theme get p2`
Then STDOUT should be a table containing rows:
| Field | Value |
| status | inactive |
When I run `wp theme get p2 --field=status`
Then STDOUT should be:
"""
inactive
"""
When I run `wp theme activate p2`
Then STDOUT should not be empty
When I run `wp theme get p2 --field=status`
Then STDOUT should be:
"""
active
"""
Scenario: Theme activation fails when slug does not match exactly
Given a WP install
When I run `wp theme install p2`
Then the return code should be 0
When I try `wp theme activate P2`
Then STDERR should contain:
"""
Error: The 'P2' theme could not be found. Did you mean 'p2'?
"""
And STDOUT should be empty
And the return code should be 1
When I try `wp theme activate p3`
Then STDERR should contain:
"""
Error: The 'p3' theme could not be found. Did you mean 'p2'?
"""
And STDOUT should be empty
And the return code should be 1
When I try `wp theme activate pb2`
Then STDERR should contain:
"""
Error: The 'pb2' theme could not be found. Did you mean 'p2'?
"""
And STDOUT should be empty
And the return code should be 1
When I try `wp theme activate completelyoff`
Then STDERR should contain:
"""
Error: The 'completelyoff' theme could not be found.
"""
And STDERR should not contain:
"""
Did you mean
"""
And STDOUT should be empty
And the return code should be 1
Scenario: Only valid status filters are accepted when listing themes
Given a WP install
When I run `wp theme list`
Then STDERR should be empty
When I run `wp theme list --status=active`
Then STDERR should be empty
When I try `wp theme list --status=invalid-status`
Then STDERR should be:
"""
Error: Parameter errors:
Invalid value specified for 'status' (Filter the output by theme status.)
"""
Scenario: Parent theme is active when its child is active
Given a WP install
And I run `wp theme install p2`
And I run `wp theme install moina-blog --activate`
When I run `wp theme is-active moina-blog`
Then the return code should be 0
When I run `wp theme is-active moina`
Then the return code should be 0
When I try `wp theme is-active p2`
Then the return code should be 1
Scenario: Excluding a missing theme should not throw an error
Given a WP install
And I run `wp theme delete --all --force`
And I run `wp theme install p2 --version=1.5.5 --activate`
And I run `wp theme update --all --exclude=missing-theme`
Then STDERR should be empty
And STDOUT should contain:
"""
Success:
"""
And the return code should be 0
@require-wp-5.5
Scenario: Listing themes should include auto_update
Given a WP install
When I run `wp theme list --fields=auto_update`
Then STDOUT should be a table containing rows:
| auto_update |
| off |
When I run `wp theme auto-updates enable --all`
And I try `wp theme list --fields=auto_update`
Then STDOUT should be a table containing rows:
| auto_update |
| on |