[wp-trac] [WordPress Trac] #41978: `_delete_all_data()` does not delete attachment files

WordPress Trac noreply at wordpress.org
Mon Sep 25 14:30:56 UTC 2017


#41978: `_delete_all_data()` does not delete attachment files
------------------------------+-----------------------------
 Reporter:  Frank Klein       |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:  trunk
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41978>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list