Make WordPress Core

Changeset 63631


Ignore:
Timestamp:
09/15/2026 09:31:01 PM (2 months ago)
Author:
lancewillett
Message:

Tests: Reduce export fixture cost and fix upload cleanup.

Create export attachment fixtures directly in the database instead of copying images and generating intermediate sizes. Preserve the attachment parent and featured-image relationships.

Cache an initially empty upload snapshot and clean up files created by the admin media tests, preventing leftover uploads from changing later filenames. Add regression coverage for empty and nonempty initial snapshots.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13495

Props sainathpoojary.
See #66074.

Location:
trunk/tests/phpunit
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r63592 r63631  
    120120                $this->factory = static::factory();
    121121
    122                 if ( ! self::$ignore_files ) {
     122                if ( null === self::$ignore_files ) {
    123123                        self::$ignore_files = $this->scan_user_uploads();
    124124                }
    … …  
    15851585         *
    15861586         * This method works in tandem with the `set_up()` and `rmdir()` methods:
    1587          * - `set_up()` scans the `uploads` directory before every test, and stores
    1588          *   its contents inside of the `$ignore_files` property.
     1587         * - `set_up()` stores the initial `uploads` directory snapshot in the
     1588         *   `$ignore_files` property, including when the directory is empty.
    15891589         * - `rmdir()` and its helper methods only delete files that are not listed
    15901590         *   in the `$ignore_files` property. If called during `tear_down()` in tests,
    1591          *   this will only delete files added during the previously run test.
     1591         *   this deletes files added after the initial snapshot.
    15921592         */
    15931593        public function remove_added_uploads() {
    … …  
    16261626         */
    16271627        public function scan_user_uploads() {
    1628                 static $files = array();
    1629                 if ( ! empty( $files ) ) {
     1628                static $files = null;
     1629                if ( null !== $files ) {
    16301630                        return $files;
    16311631                }
  • trunk/tests/phpunit/tests/admin/exportWp.php

    r62168 r63631  
    4545        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    4646                require_once ABSPATH . 'wp-admin/includes/export.php';
    47                 $file = DIR_TESTDATA . '/images/test-image.jpg';
    4847
    4948                $dataset = array(
    … …  
    7271                        $post_data['post_author'] = $factory->user->create( array( 'role' => 'editor' ) );
    7372
    74                         $post_id       = $factory->post->create( $post_data );
    75                         $attachment_id = $factory->attachment->create_upload_object( $file, $post_id );
     73                        $post_id = $factory->post->create( $post_data );
     74
     75                        $attachment_id = $factory->attachment->create(
     76                                array(
     77                                        'file'           => 'test-image.jpg',
     78                                        'post_parent'    => $post_id,
     79                                        'post_mime_type' => 'image/jpeg',
     80                                )
     81                        );
    7682                        set_post_thumbnail( $post_id, $attachment_id );
    7783
  • trunk/tests/phpunit/tests/admin/includesMedia.php

    r62978 r63631  
    1111
    1212                require_once ABSPATH . 'wp-admin/includes/media.php';
     13        }
     14
     15        public function tear_down() {
     16                $this->remove_added_uploads();
     17
     18                parent::tear_down();
    1319        }
    1420
Note: See TracChangeset for help on using the changeset viewer.