Skip to content

Commit 0064498

Browse files
Copilotswissspidy
andcommitted
Add comprehensive test coverage for old files cleanup functionality
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 1a5cb90 commit 0064498

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

features/core-update.feature

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,146 @@ Feature: Update WordPress core
384384
"""
385385
Success:
386386
"""
387+
388+
@require-php-7.2
389+
Scenario: Old files from $_old_files are cleaned up when upgrading
390+
Given a WP install
391+
392+
When I run `wp core download --version=6.8 --force`
393+
Then STDOUT should contain:
394+
"""
395+
Success: WordPress downloaded.
396+
"""
397+
398+
# Create files that should be removed according to 6.9 old_files list
399+
Given a wp-includes/blocks/post-author/editor.css file:
400+
"""
401+
/* Old CSS file */
402+
"""
403+
And a wp-includes/blocks/post-author/editor.min.css file:
404+
"""
405+
/* Old minified CSS */
406+
"""
407+
And a wp-includes/blocks/post-author/editor-rtl.css file:
408+
"""
409+
/* Old RTL CSS */
410+
"""
411+
And a wp-includes/blocks/post-author/editor-rtl.min.css file:
412+
"""
413+
/* Old RTL minified CSS */
414+
"""
415+
And a wp-includes/SimplePie/src/Core.php file:
416+
"""
417+
<?php
418+
// Old SimplePie Core file
419+
"""
420+
And a wp-includes/SimplePie/src/Decode directory
421+
422+
When I run `wp core update --version=6.9 --force`
423+
Then STDOUT should contain:
424+
"""
425+
Success: WordPress updated successfully.
426+
"""
427+
And the wp-includes/blocks/post-author/editor.css file should not exist
428+
And the wp-includes/blocks/post-author/editor.min.css file should not exist
429+
And the wp-includes/blocks/post-author/editor-rtl.css file should not exist
430+
And the wp-includes/blocks/post-author/editor-rtl.min.css file should not exist
431+
And the wp-includes/SimplePie/src/Core.php file should not exist
432+
And the wp-includes/SimplePie/src/Decode directory should not exist
433+
434+
@require-php-7.2
435+
Scenario: Custom old_files list is used for cleanup
436+
Given a WP install
437+
438+
When I run `wp core download --version=6.8 --force`
439+
Then STDOUT should contain:
440+
"""
441+
Success: WordPress downloaded.
442+
"""
443+
444+
# Create test files that we'll add to custom old_files list
445+
Given a wp-includes/test-old-file-1.php file:
446+
"""
447+
<?php
448+
// Test old file 1
449+
"""
450+
And a wp-includes/test-old-file-2.php file:
451+
"""
452+
<?php
453+
// Test old file 2
454+
"""
455+
And a wp-includes/test-old-dir directory
456+
And a wp-includes/test-old-dir/test-file.php file:
457+
"""
458+
<?php
459+
// Test file in old directory
460+
"""
461+
462+
# Modify update-core.php to include our test files in old_files list
463+
And a wp-admin/includes/update-core-custom.php file:
464+
"""
465+
<?php
466+
global $_old_files;
467+
require_once ABSPATH . 'wp-admin/includes/update-core.php';
468+
$_old_files[] = 'wp-includes/test-old-file-1.php';
469+
$_old_files[] = 'wp-includes/test-old-file-2.php';
470+
$_old_files[] = 'wp-includes/test-old-dir';
471+
"""
472+
473+
# Backup original and replace with custom version
474+
When I run `mv wp-admin/includes/update-core.php wp-admin/includes/update-core-backup.php`
475+
And I run `mv wp-admin/includes/update-core-custom.php wp-admin/includes/update-core.php`
476+
477+
When I run `wp core update --version=6.9 --force`
478+
Then STDOUT should contain:
479+
"""
480+
Success: WordPress updated successfully.
481+
"""
482+
483+
# Restore original update-core.php
484+
When I run `mv wp-admin/includes/update-core-backup.php wp-admin/includes/update-core.php`
485+
486+
# Verify custom old files were removed
487+
Then the wp-includes/test-old-file-1.php file should not exist
488+
And the wp-includes/test-old-file-2.php file should not exist
489+
And the wp-includes/test-old-dir directory should not exist
490+
491+
@require-php-7.2
492+
Scenario: Old files cleanup works when checksums unavailable
493+
Given a WP install
494+
495+
When I run `wp core download --version=6.8 --force`
496+
Then STDOUT should contain:
497+
"""
498+
Success: WordPress downloaded.
499+
"""
500+
501+
# Create files that should be removed
502+
Given a wp-includes/test-cleanup-file.php file:
503+
"""
504+
<?php
505+
// Test cleanup file
506+
"""
507+
508+
# Modify update-core.php to include our test file
509+
And a wp-admin/includes/update-core-custom.php file:
510+
"""
511+
<?php
512+
global $_old_files;
513+
require_once ABSPATH . 'wp-admin/includes/update-core.php';
514+
$_old_files[] = 'wp-includes/test-cleanup-file.php';
515+
"""
516+
517+
When I run `mv wp-admin/includes/update-core.php wp-admin/includes/update-core-backup.php`
518+
And I run `mv wp-admin/includes/update-core-custom.php wp-admin/includes/update-core.php`
519+
520+
# Update to a version where checksums might not be available
521+
When I try `wp core update --version=nightly --force`
522+
Then STDOUT should contain:
523+
"""
524+
Cleaning up files...
525+
"""
526+
527+
When I run `mv wp-admin/includes/update-core-backup.php wp-admin/includes/update-core.php`
528+
529+
Then the wp-includes/test-cleanup-file.php file should not exist

0 commit comments

Comments
 (0)