From 323ac54d4b03b38955f658f6ba8e5169bb8e1bc2 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 9 Oct 2022 13:45:23 +0000 Subject: [PATCH] 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 [source:tags/6.0.2/src/wp-includes/class-wp-customize-manager.php?marks=1370-1374#L1367 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. git-svn-id: https://develop.svn.wordpress.org/trunk@54424 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/customize/manager.php | 27 +++-------------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 96aa37f889..686a25506a 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -33,20 +33,6 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { */ protected static $subscriber_user_id; - /** - * Path to test file 1. - * - * @var string - */ - private $test_file; - - /** - * Path to test file 2. - * - * @var string - */ - private $test_file2; - /** * Set up before class. * @@ -64,13 +50,6 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { parent::set_up(); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; $this->manager = $this->instantiate(); - - $orig_file = DIR_TESTDATA . '/images/canola.jpg'; - $this->test_file = get_temp_dir() . 'canola.jpg'; - copy( $orig_file, $this->test_file ); - $orig_file2 = DIR_TESTDATA . '/images/waffles.jpg'; - $this->test_file2 = get_temp_dir() . 'waffles.jpg'; - copy( $orig_file2, $this->test_file2 ); } /** @@ -557,7 +536,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { add_theme_support( 'custom-background' ); $existing_canola_attachment_id = self::factory()->attachment->create_object( - $this->test_file, + DIR_TESTDATA . '/images/canola.jpg', 0, array( 'post_mime_type' => 'image/jpeg', @@ -631,13 +610,13 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { 'post_title' => 'Waffles', 'post_content' => 'Waffles Attachment Description', 'post_excerpt' => 'Waffles Attachment Caption', - 'file' => $this->test_file2, + 'file' => DIR_TESTDATA . '/images/waffles.jpg', ), 'canola' => array( 'post_title' => 'Canola', 'post_content' => 'Canola Attachment Description', 'post_excerpt' => 'Canola Attachment Caption', - 'file' => $this->test_file, + 'file' => DIR_TESTDATA . '/images/canola.jpg', ), ), 'options' => array(