Skip to content

Tests: Delete attachment files during test cleanup - #8898

Closed
SirLouen wants to merge 3 commits into
WordPress:trunkfrom
SirLouen:patch/41978
Closed

Tests: Delete attachment files during test cleanup#8898
SirLouen wants to merge 3 commits into
WordPress:trunkfrom
SirLouen:patch/41978

Conversation

@SirLouen

@SirLouen SirLouen commented Jun 4, 2025

Copy link
Copy Markdown
Member

Delete attachment files before _delete_all_data() clears the database tables. Calling wp_delete_attachment( $id, true ) while attachment metadata still exists removes the uploaded file and its associated image files. Other records retain the existing bulk SQL cleanup.

This refreshes the original patch for https://core.trac.wordpress.org/ticket/41978 against current trunk without rewriting the PR history. The attachment query now returns scalar IDs, and the regression test verifies that an existing uploaded file and its attachment post are deleted.

Validation

Validated on 640c25f:

  • Focused PHPUnit test passed in single-site and multisite: 1 test, 3 assertions each.
  • PHPCS passed both changed files.
  • Removing the attachment cleanup loop made the regression test fail because the uploaded file remained.
  • A randomized media/image run with seed 8898 produced 864 tests and 2,425 assertions, with 7 skips and two failures. The exact trunk baseline produced the same two failures: a caption-output assertion and a URL-based image crop reporting a missing file. Neither is introduced by this change.
  • That single diagnostic run took 40.530 seconds with the patch and 41.453 seconds on trunk. The extra attachment query runs once per class teardown; longer-term suite timing can be monitored through CodeVitals.
  • The patch applies cleanly to SVN trunk, including the new regression-test file.

Fresh CI is running on the refreshed head.

Use of AI tools

AI assistance for this refresh: Yes
Tool(s): Codex
Model(s): GPT-6, GPT-5.6
Used for: Reviewing the existing patch, refreshing the branch, simplifying the query, correcting the regression test, running validation, and drafting this update.


This pull request is for code review only. Please keep other discussion in the Trac ticket. Do not merge this pull request.

@github-actions

github-actions Bot commented Jun 4, 2025

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sirlouen, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jun 4, 2025

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@lancewillett lancewillett changed the title Test Suite: delete_all_data improvements. Refreshing 41978.patch Tests: Delete attachment files during test cleanup Sep 10, 2026
wporg-sync pushed a commit that referenced this pull request Sep 10, 2026
Delete attachments before the bulk database cleanup so their uploaded files and generated image sizes are removed while attachment metadata is still available. Preserve the existing bulk SQL cleanup for other records.

Add regression coverage for attachment file and post deletion.

Developed in: #8898

Props sirlouen, johnbillion, adrianmoldovanwp.
Fixes #41978.


git-svn-id: https://develop.svn.wordpress.org/trunk@63586 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 63586
GitHub commit: 2c6ec19

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Sep 10, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Sep 10, 2026
Delete attachments before the bulk database cleanup so their uploaded files and generated image sizes are removed while attachment metadata is still available. Preserve the existing bulk SQL cleanup for other records.

Add regression coverage for attachment file and post deletion.

Developed in: WordPress/wordpress-develop#8898

Props sirlouen, johnbillion, adrianmoldovanwp.
Fixes #41978.

Built from https://develop.svn.wordpress.org/trunk@63586


git-svn-id: http://core.svn.wordpress.org/trunk@62762 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants