Make WordPress Core

Changeset 54424


Ignore:
Timestamp:
10/09/2022 01:45:23 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Remove unnecessary file copying in WP_Customize_Manager tests.

This was added to avoid creating leftover image sub-sizes in the version-controlled DIR_TESTDATA directory.

However, this does not appear to be necessary:

  • WP_Customizer_Manager::import_theme_starter_content() already makes a copy of the image before sideloading, so the test was essentially working with a copy of a copy.
  • The images were only used in one test out of 70 and do not need to be copied for every single test.

Upon further investigation, there is also no evidence that creating these copies actually resolved the reported issue:

  • WP_UnitTest_Factory_For_Attachment::create_object() inserts an attachment, but does not create image sub-sizes.
  • media_handle_sideload() does create image sub-sizes, but the file is already in the media library by that time, and sub-sizes are created in the uploads directory, not in the version-controlled DIR_TESTDATA directory.

This commit removes ~140 redundant file copying operations when running the test suite.

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

See #55652.

File:
1 edited

Legend:

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

    r54402 r54424  
    3535
    3636    /**
    37      * Path to test file 1.
    38      *
    39      * @var string
    40      */
    41     private $test_file;
    42 
    43     /**
    44      * Path to test file 2.
    45      *
    46      * @var string
    47      */
    48     private $test_file2;
    49 
    50     /**
    5137     * Set up before class.
    5238     *
     
    6551        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    6652        $this->manager = $this->instantiate();
    67 
    68         $orig_file       = DIR_TESTDATA . '/images/canola.jpg';
    69         $this->test_file = get_temp_dir() . 'canola.jpg';
    70         copy( $orig_file, $this->test_file );
    71         $orig_file2       = DIR_TESTDATA . '/images/waffles.jpg';
    72         $this->test_file2 = get_temp_dir() . 'waffles.jpg';
    73         copy( $orig_file2, $this->test_file2 );
    7453    }
    7554
     
    558537
    559538        $existing_canola_attachment_id     = self::factory()->attachment->create_object(
    560             $this->test_file,
     539            DIR_TESTDATA . '/images/canola.jpg',
    561540            0,
    562541            array(
     
    632611                    'post_content' => 'Waffles Attachment Description',
    633612                    'post_excerpt' => 'Waffles Attachment Caption',
    634                     'file'         => $this->test_file2,
     613                    'file'         => DIR_TESTDATA . '/images/waffles.jpg',
    635614                ),
    636615                'canola'  => array(
     
    638617                    'post_content' => 'Canola Attachment Description',
    639618                    'post_excerpt' => 'Canola Attachment Caption',
    640                     'file'         => $this->test_file,
     619                    'file'         => DIR_TESTDATA . '/images/canola.jpg',
    641620                ),
    642621            ),
Note: See TracChangeset for help on using the changeset viewer.