Make WordPress Core

Changeset 54519


Ignore:
Timestamp:
10/15/2022 01:08:33 AM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r54426 r54519  
    548548        add_theme_support( 'custom-background' );
    549549
     550        // For existing attachment, copy into uploads.
     551        $canola_image_file    = DIR_TESTDATA . '/images/canola.jpg';
     552        $canola_image_upload  = wp_upload_bits( wp_basename( $canola_image_file ), null, file_get_contents( $canola_image_file ) );
     553        $existing_canola_file = $canola_image_upload['file'];
     554
    550555        $existing_canola_attachment_id = self::factory()->attachment->create_object(
    551             DIR_TESTDATA . '/images/canola.jpg',
     556            $existing_canola_file,
    552557            0,
    553558            array(
     
    632637                    'post_content' => 'Canola Attachment Description',
    633638                    'post_excerpt' => 'Canola Attachment Caption',
    634                     'file'         => DIR_TESTDATA . '/images/canola.jpg',
     639                    'file'         => $existing_canola_file,
    635640                ),
    636641            ),
Note: See TracChangeset for help on using the changeset viewer.