[wp-trac] [WordPress Trac] #56807: Delete existing attachment subsizes after WP_Customize_Manager tests

WordPress Trac noreply at wordpress.org
Sat Oct 15 01:08:47 UTC 2022


#56807: Delete existing attachment subsizes after WP_Customize_Manager tests
--------------------------------------+-----------------------------
 Reporter:  ironprogrammer            |       Owner:  SergeyBiryukov
     Type:  defect (bug)              |      Status:  closed
 Priority:  normal                    |   Milestone:  6.1
Component:  Build/Test Tools          |     Version:  trunk
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------
Changes (by SergeyBiryukov):

 * status:  accepted => closed
 * resolution:   => fixed


Comment:

 In [changeset:"54519" 54519]:
 {{{
 #!CommitTicketReference repository="" revision="54519"
 Tests: Delete leftover image sub-sizes after `WP_Customize_Manager` tests.

 After running `phpunit --filter test_import_theme_starter_content`, the
 following files were generated and left in place in the version-controlled
 `DIR_TESTDATA` directory, resulting in a dirty working copy of the
 project:
 {{{
 tests/phpunit/data/images/canola-150x150.jpg
 tests/phpunit/data/images/canola-300x225.jpg
 }}}

 In the test, `canola.jpg` is mocked as an **existing attachment**. When
 the test invokes `WP_Customize_Manager::import_theme_starter_content()`,
 existing attachments are passed directly to
 `wp_generate_attachment_metadata()`, which does not make a copy of the
 file, and `wp_create_image_subsizes()` creates the above referenced files
 in the original image's location.

 By contrast, `waffles.jpg`, also used in the test, is **not** set as an
 existing attachment, and in  `import_theme_starter_content()` is passed to
 `media_handle_sideload()`, which makes a **copy** of the file in the `wp-
 content/uploads/` directory, and then calls `wp_create_image_subsizes()`
 against the new file. The resulting sub-sizes are generated in that
 location, and are cleaned up during `tear_down()`.

 The test's `tear_down()` uses `remove_added_uploads()`, which only clears
 items created in `wp-content/uploads/` (i.e. `waffles*.jpg`), but not the
 files in the `DIR_TESTDATA` directory (`canola-*.jpg`).

 This commit addresses the issue by creating a copy of the file in uploads.
 This better matches the intention of the test, as existing attachments
 will most likely be located in uploads and not in an arbitrary path like
 the test data directory.

 Follow-up to [39276], [39346], [39411], [40142], [54424], [54425].

 Props ironprogrammer, audrasjb, boniu91, dariak, SergeyBiryukov.
 Fixes #56807.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56807#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list