Repository navigation
Expand file tree
/
Copy pathplugin-update.feature
More file actions
606 lines (515 loc) · 19.2 KB
/
Copy pathplugin-update.feature
File metadata and controls
606 lines (515 loc) · 19.2 KB
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
Feature: Update WordPress plugins
@require-wp-5.2
Scenario: Updating plugin with invalid version shouldn't remove the old version
Given a WP install
When I run `wp plugin install wordpress-importer --version=0.5 --force`
Then STDOUT should not be empty
When I run `wp plugin list --name=wordpress-importer --field=update_version`
Then STDOUT should not be empty
And save STDOUT as {UPDATE_VERSION}
When I run `wp plugin list`
Then STDOUT should be a table containing rows:
| name | status | update | version | update_version | auto_update |
| wordpress-importer | inactive | available | 0.5 | {UPDATE_VERSION} | off |
When I try `wp plugin update akismet --version=0.5.3`
Then STDERR should be:
"""
Error: Can't find the requested plugin's version 0.5.3 in the WordPress.org plugin repository (HTTP code 404).
"""
And the return code should be 1
When I run `wp plugin list`
Then STDOUT should be a table containing rows:
| name | status | update | version | update_version | auto_update |
| wordpress-importer | inactive | available | 0.5 | {UPDATE_VERSION} | off |
When I run `wp plugin update wordpress-importer`
Then STDOUT should not be empty
When I run `wp plugin list`
Then STDOUT should be a table containing rows:
| name | status | update | version | update_version | auto_update |
| wordpress-importer | inactive | none | {UPDATE_VERSION} | | off |
@require-wp-5.5
Scenario: Expose the files changed by a plugin update via a hook
Given a WP install
And a hook.php file:
"""
<?php
WP_CLI::add_hook(
'plugin_update_finished',
static function ( $files ) {
WP_CLI::log( 'Hook fired with ' . ( count( $files ) > 0 ? 'files' : 'no files' ) );
foreach ( $files as $file ) {
WP_CLI::log( 'Changed file: ' . $file );
}
}
);
"""
When I run `wp plugin install wordpress-importer --version=0.5 --force`
Then STDOUT should not be empty
When I run `wp plugin update wordpress-importer --require=hook.php`
Then STDOUT should contain:
"""
Hook fired with files
"""
And STDOUT should contain:
"""
Changed file: {PLUGIN_DIR}/wordpress-importer/wordpress-importer.php
"""
And STDOUT should not contain:
"""
Changed file: {PLUGIN_DIR}/wordpress-importer/readme.txt
"""
When I run `wp plugin update wordpress-importer --require=hook.php`
Then STDOUT should not contain:
"""
Hook fired
"""
Scenario: Error when both --minor and --patch are provided
Given a WP install
When I try `wp plugin update --patch --minor --all`
Then STDERR should be:
"""
Error: --minor and --patch cannot be used together.
"""
And the return code should be 1
@require-wp-5.2
Scenario: Exclude plugin updates from bulk updates.
Given a WP install
When I run `wp plugin install wordpress-importer --version=0.5 --force`
Then STDOUT should contain:
"""
Downloading install
"""
And STDOUT should contain:
"""
package from https://downloads.wordpress.org/plugin/wordpress-importer.0.5.zip...
"""
When I try `wp plugin status wordpress-importer`
Then STDOUT should contain:
"""
Update available
"""
When I run `wp plugin update --all --exclude=wordpress-importer | grep 'Skipped'`
Then STDOUT should contain:
"""
wordpress-importer
"""
When I try `wp plugin status wordpress-importer`
Then STDOUT should contain:
"""
Update available
"""
@require-wp-5.2
Scenario: Update a plugin to its latest patch release
Given a WP install
And these installed plugins:
"""
wordpress-importer --version=0.5 --force
"""
When I run `wp plugin update wordpress-importer --patch`
Then STDOUT should contain:
"""
Success: Updated 1 of 1 plugins.
"""
When I run `wp plugin get wordpress-importer --field=version`
Then STDOUT should be:
"""
0.5.2
"""
# Akismet currently requires WordPress 5.8
@require-wp-5.8
Scenario: Update a plugin to its latest minor release
Given a WP install
And these installed plugins:
"""
akismet --version=2.5.4 --force
"""
When I run `wp plugin update akismet --minor`
Then STDOUT should contain:
"""
Success: Updated 1 of 1 plugins.
"""
When I run `wp plugin get akismet --field=version`
Then STDOUT should be:
"""
2.6.1
"""
@require-wp-5.2
Scenario: Not giving a slug on update should throw an error unless --all given
Given a WP install
And an empty {PLUGIN_DIR} directory
# No plugins installed. Don't give an error if --all given for BC.
When I run `wp plugin update --all`
Then STDOUT should be:
"""
Success: No plugins installed.
"""
When I run `wp plugin update --version=0.6 --all`
Then STDOUT should be:
"""
Success: No plugins installed.
"""
# One plugin installed.
Given these installed plugins:
"""
wordpress-importer --version=0.5 --force
"""
When I try `wp plugin update`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more plugins, or use --all.
"""
And STDOUT should be empty
When I run `wp plugin update --all`
Then STDOUT should contain:
"""
Success: Updated
"""
When I run the previous command again
Then STDOUT should be:
"""
Success: Plugin already updated.
"""
# Note: if given version then re-installs.
When I run `wp plugin update --version=0.6 --all`
Then STDOUT should contain:
"""
Success: Installed 1 of 1 plugins.
"""
When I run the previous command again
Then STDOUT should contain:
"""
Success: Installed 1 of 1 plugins.
"""
# Two plugins installed.
Given these installed plugins:
"""
akismet --version=2.5.4
"""
When I run `wp plugin update --all`
Then STDOUT should contain:
"""
Success: Updated
"""
When I run the previous command again
# BUG: note this message should be plural.
Then STDOUT should be:
"""
Success: Plugin already updated.
"""
# Using version with all rarely makes sense and should probably error and do nothing.
When I try `wp plugin update --version=2.5.4 --all`
Then the return code should be 1
And STDOUT should contain:
"""
Success: Installed 1 of 1 plugins.
"""
And STDERR should be:
"""
Error: Can't find the requested plugin's version 2.5.4 in the WordPress.org plugin repository (HTTP code 404).
"""
# Akismet currently requires WordPress 5.8
# Skipped on Windows because chmod does not reliably enforce unwritable files cross-platform
@require-wp-5.8 @skip-windows
Scenario: Plugin updates that error should not report a success
Given a WP install
And these installed plugins:
"""
akismet --version=4.0 --force
"""
When I run `chmod -w wp-content/plugins/akismet`
And I try `wp plugin update akismet`
Then STDERR should contain:
"""
Error:
"""
And STDOUT should not contain:
"""
Success:
"""
When I run `chmod +w wp-content/plugins/akismet`
And I try `wp plugin update akismet`
Then STDERR should not contain:
"""
Error:
"""
And STDOUT should contain:
"""
Success:
"""
# Akismet currently requires WordPress 5.8, so there's a warning because of it.
@require-wp-5.8
Scenario: Excluding a missing plugin should not throw an error
Given a WP install
And I run `wp plugin update --all --exclude=missing-plugin`
Then STDERR should be empty
And STDOUT should contain:
"""
Success:
"""
And the return code should be 0
# Skipped on Windows because of sed usage that would need to be refactored for compatibility.
@require-wp-5.2 @skip-windows
Scenario: Updating all plugins ignores an older no-update version
Given a WP install
And I run `wp plugin delete akismet`
When I run `wp plugin install health-check --version=1.5.0`
Then STDOUT should not be empty
When I run `wp plugin install wordpress-importer --version=0.5`
Then STDOUT should not be empty
When I run `sed -i.bak 's/Version: .*/Version: 10000/' $(wp plugin path health-check)`
Then STDOUT should be empty
And the return code should be 0
When I run `wp plugin update --all`
Then STDERR should be empty
And STDOUT should contain:
"""
Success: Updated 1 of 1 plugins.
"""
# Tests for --auto-update-indicated feature
# Note: These tests verify the flag handling and error cases.
# The actual update behavior when autoupdate is true from the server
# cannot be easily tested as it requires mocking WordPress.org API responses.
# The update functionality itself is handled by the existing update_many method.
@require-wp-5.2
Scenario: Show auto_update_indicated field in plugin list
Given a WP install
When I run `wp plugin install wordpress-importer --version=0.5 --force`
Then STDOUT should not be empty
When I run `wp plugin list --fields=name,version,update,auto_update_indicated`
Then STDOUT should be a table containing rows:
| name | version | update | auto_update_indicated |
| wordpress-importer | 0.5 | available | no |
@require-wp-5.2
Scenario: Using --auto-update-indicated flag when no plugins have auto-update indicated
Given a WP install
When I run `wp plugin install wordpress-importer --version=0.5 --force`
Then STDOUT should not be empty
When I run `wp plugin update --auto-update-indicated`
Then STDOUT should be:
"""
Success: No plugins with server-indicated automatic updates available.
"""
@require-wp-5.2
Scenario: Error when using --version with --auto-update-indicated
Given a WP install
When I try `wp plugin update --auto-update-indicated --version=1.0.0`
Then STDERR should be:
"""
Error: Cannot use --version with --auto-update-indicated. The version is determined by the server.
"""
And the return code should be 1
@require-wp-5.2
Scenario: Error when using --minor with --auto-update-indicated
Given a WP install
When I try `wp plugin update --auto-update-indicated --minor`
Then STDERR should be:
"""
Error: Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.
"""
And the return code should be 1
@require-wp-5.2
Scenario: Error when using --patch with --auto-update-indicated
Given a WP install
When I try `wp plugin update --auto-update-indicated --patch`
Then STDERR should be:
"""
Error: Cannot use --minor or --patch with --auto-update-indicated. The version is determined by the server.
"""
And the return code should be 1
@require-wp-5.2
Scenario: Error when specifying plugin names with --auto-update-indicated
Given a WP install
When I try `wp plugin update akismet --auto-update-indicated`
Then STDERR should be:
"""
Error: Cannot specify plugin names with --auto-update-indicated. This flag updates all plugins with server-indicated automatic updates.
"""
And the return code should be 1
@require-wp-5.2
Scenario: Preview updates with --auto-update-indicated and --dry-run
Given a WP install
When I run `wp plugin install wordpress-importer --version=0.5 --force`
Then STDOUT should not be empty
When I run `wp plugin update --auto-update-indicated --dry-run`
Then STDOUT should be:
"""
Success: No plugins with server-indicated automatic updates available.
"""
@require-wp-5.2
Scenario: Updating all plugins should show the name of each plugin as it is updated
Given a WP install
And I run `wp plugin delete akismet`
When I run `wp plugin install health-check --version=1.5.0`
Then STDOUT should not be empty
When I run `wp plugin install wordpress-importer --version=0.5`
Then STDOUT should not be empty
When I try `wp plugin update --all`
Then STDOUT should contain:
"""
Updating Health Check & Troubleshooting...
"""
And STDOUT should contain:
"""
Success: Updated 2 of 2 plugins.
"""
@require-wp-5.2 @skip-windows
Scenario: Failed plugin update keeps JSON output parseable
Given a WP install
And these installed plugins:
"""
wordpress-importer --version=0.5 --force
"""
And I run `chmod -w wp-content/plugins/wordpress-importer`
When I try `wp plugin update wordpress-importer --format=json`
Then STDOUT should be JSON containing:
"""
[{"name":"wordpress-importer","old_version":"0.5","status":"Error"}]
"""
And STDERR should be empty
And the return code should be 1
When I run `chmod +w wp-content/plugins/wordpress-importer`
@require-wp-5.2 @skip-windows
Scenario: Failed plugin update keeps CSV output parseable
Given a WP install
And these installed plugins:
"""
wordpress-importer --version=0.5 --force
"""
And I run `chmod -w wp-content/plugins/wordpress-importer`
When I try `wp plugin update wordpress-importer --format=csv`
Then STDOUT should be CSV containing:
| name | old_version | status |
| wordpress-importer | 0.5 | Error |
And STDERR should be empty
And the return code should be 1
When I run `chmod +w wp-content/plugins/wordpress-importer`
# Skipped on Windows because of mkdir usage that would need to be refactored for compatibility.
@require-wp-5.2 @skip-windows
Scenario: Skip plugin update when plugin directory is a VCS checkout
Given a WP install
And these installed plugins:
"""
wordpress-importer --version=0.5 --force
"""
And I run `wp plugin path wordpress-importer --dir`
And save STDOUT as {PLUGIN_DIR}
When I run `mkdir {PLUGIN_DIR}/.git`
And I try `wp plugin update wordpress-importer`
Then STDERR should contain:
"""
Warning: wordpress-importer: Skipped update because a VCS checkout was detected. Use --include-vcs to override.
"""
And STDERR should contain:
"""
Error: No plugins updated.
"""
And the return code should be 1
# Skipped on Windows because of mkdir usage that would need to be refactored for compatibility.
@require-wp-5.2 @skip-windows
Scenario: Update plugin in VCS checkout when --include-vcs is set
Given a WP install
And these installed plugins:
"""
wordpress-importer --version=0.5 --force
"""
And I run `wp plugin path wordpress-importer --dir`
And save STDOUT as {PLUGIN_DIR}
When I run `mkdir {PLUGIN_DIR}/.git`
And I run `wp plugin update wordpress-importer --include-vcs`
Then STDOUT should contain:
"""
Success: Updated 1 of 1 plugins.
"""
Scenario: Updating a plugin whose own update mechanism is skipped with --skip-plugins
Given a WP install
And a wp-content/plugins/premium-updater-simulation/premium-updater-simulation.php file:
"""
<?php
/**
* Plugin Name: Premium Updater Simulation
* Description: Mimics a premium plugin whose license does not allow downloading the update.
* Version: 1.0.0
*/
add_filter(
'pre_set_site_transient_update_plugins',
function ( $transient ) {
if ( ! is_object( $transient ) ) {
$transient = new stdClass();
}
$transient->response['premium-updater-simulation/premium-updater-simulation.php'] = (object) [
'id' => 'premium-updater-simulation/premium-updater-simulation.php',
'slug' => 'premium-updater-simulation',
'plugin' => 'premium-updater-simulation/premium-updater-simulation.php',
'new_version' => '2.0.0',
'url' => '',
'package' => '',
];
return $transient;
}
);
"""
And I run `wp plugin activate premium-updater-simulation`
# Update data fetched while plugins are skipped must not be reused by later runs.
When I run `wp plugin list --skip-plugins --fields=name,update`
Then STDOUT should be a table containing rows:
| name | update |
| premium-updater-simulation | none |
When I try `wp plugin update premium-updater-simulation`
Then STDERR should contain:
"""
Warning: Update package not available.
"""
And STDOUT should end with a table containing rows:
| name | old_version | new_version | status |
| premium-updater-simulation | 1.0.0 | 2.0.0 | Error |
And STDERR should contain:
"""
Error: No plugins updated (1 failed).
"""
And the return code should be 1
# Once the update data is refreshed without the plugin's update mechanism, the plugin must not be mistaken for being up to date.
When I try `wp transient delete update_plugins --network`
And I try `wp plugin update premium-updater-simulation --skip-plugins`
Then STDERR should be:
"""
Warning: premium-updater-simulation: Could not determine whether an update is available. The plugin's own update mechanism might not have run because --skip-plugins is in effect.
Error: No plugins updated.
"""
And STDOUT should be empty
And the return code should be 1
# Plugins that WordPress.org reported on are not affected.
When I try `wp plugin update --all --skip-plugins --dry-run`
Then STDERR should contain:
"""
Warning: premium-updater-simulation: Could not determine whether an update is available. The plugin's own update mechanism might not have run because --skip-plugins is in effect.
"""
# Excluded plugins are not warned about.
When I try `wp plugin update --all --skip-plugins --exclude=premium-updater-simulation --dry-run`
Then STDERR should not contain:
"""
premium-updater-simulation
"""
# Update data fetched while plugins were skipped is not reused once plugins are loaded again.
When I try `wp plugin update premium-updater-simulation`
Then STDERR should contain:
"""
Warning: Update package not available.
"""
And STDERR should contain:
"""
Error: No plugins updated (1 failed).
"""
And the return code should be 1
# Skipping other plugins leaves the plugin's update mechanism running.
When I try `wp transient delete update_plugins --network`
And I try `wp plugin update premium-updater-simulation --skip-plugins=akismet`
Then STDERR should contain:
"""
Warning: Update package not available.
"""
And STDERR should contain:
"""
Error: No plugins updated (1 failed).
"""
And the return code should be 1