From 2517aff83707ce90e19ed794da7f7473e8f7d036 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 9 Oct 2022 16:26:57 +0000 Subject: [PATCH] Tests: Clean up test images in `WP_Customize_Manager` tests. The test for `WP_Customizer_Manager::import_theme_starter_content()` creates two attachments that remain in the `uploads` directory after the test run is complete. This commit follows the approach from `WP_REST_Posts_Controller` tests and utilizes an `$attachments_created` property to track any files uploaded in the current test run and clean them up afterwards. This makes sure there are no leftover images after the test class is run. Follow-up to [39276], [39346], [39411], [40142], [53935], [54424]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54425 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/customize/manager.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 686a25506a..e98bf783aa 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -33,6 +33,13 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { */ protected static $subscriber_user_id; + /** + * Whether any attachments have been created in the current test run. + * + * @var bool + */ + private $attachments_created = false; + /** * Set up before class. * @@ -56,6 +63,11 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { * Tear down test. */ public function tear_down() { + if ( true === $this->attachments_created ) { + $this->remove_added_uploads(); + $this->attachments_created = false; + } + $this->manager = null; unset( $GLOBALS['wp_customize'] ); $_REQUEST = array(); @@ -544,6 +556,9 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { 'post_name' => 'canola', ) ); + + $this->attachments_created = true; + $existing_published_home_page_id = self::factory()->post->create( array( 'post_name' => 'home',