WordPress.org

Make WordPress Core

Opened 8 weeks ago

#41978 new defect (bug)

`_delete_all_data()` does not delete attachment files

Reported by: Frank Klein Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description

The _delete_all_data() function is called by WP_UnitTestCase::wpTearDownAfterClass(). The function deletes all the contents of the posts table in the tests database. However it does not delete any attachment files.

So when you create a shared attachment fixture in WP_UnitTestCase::wpSetUpBeforeClass(), _delete_all_data() will delete the attachment post in WP_UnitTestCase::wpTearDownAfterClass(), but leave the file.

There is no way to manually delete the attachment file in wpTearDownAfterClass(), because the attachment id no longer exists, and wp_delete_attachment() will therefore fail.

The solution: Instead of a direct SQL query, _delete_all_data() should use _delete_all_posts(), which accounts for attachments.

Change History (0)

Note: See TracTickets for help on using tickets.