Make WordPress Core

Changeset 54425


Ignore:
Timestamp:
10/09/2022 04:26:57 PM (21 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r54424 r54425  
    3535
    3636    /**
     37     * Whether any attachments have been created in the current test run.
     38     *
     39     * @var bool
     40     */
     41    private $attachments_created = false;
     42
     43    /**
    3744     * Set up before class.
    3845     *
     
    5764     */
    5865    public function tear_down() {
     66        if ( true === $this->attachments_created ) {
     67            $this->remove_added_uploads();
     68            $this->attachments_created = false;
     69        }
     70
    5971        $this->manager = null;
    6072        unset( $GLOBALS['wp_customize'] );
     
    545557            )
    546558        );
     559
     560        $this->attachments_created = true;
     561
    547562        $existing_published_home_page_id   = self::factory()->post->create(
    548563            array(
Note: See TracChangeset for help on using the changeset viewer.