Make WordPress Core

Changeset 64042


Ignore:
Timestamp:
10/01/2026 09:48:59 PM (4 days ago)
Author:
lancewillett
Message:

Tests: Improve isolation for media tests.

Reset loading-optimization state before each media test, accept valid generated caption-ID suffixes, and derive expected attachment filenames from the uploaded files. Restore the incoming HTTPS server value after attachment tests.

Group the remote image-cropping test under external-http, preserving its remote-fetch coverage while keeping it out of the default test run.

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

Props jonsurrell, adrianmoldovanwp.
See #65893.

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

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r64036 r64042  
    668668        /**
    669669         * @covers ::wp_crop_image
     670         * @group external-http
    670671         * @requires function imagejpeg
    671672         * @requires extension openssl
  • trunk/tests/phpunit/tests/media.php

    r64033 r64042  
    7777                $wp_styles                = null;
    7878                parent::set_up();
     79
     80                $this->reset_content_media_count();
     81                $this->reset_omit_loading_attr_filter();
     82                $this->reset_high_priority_element_flag();
    7983        }
    8084
    … …  
    270274                );
    271275                $this->assertSame( 1, substr_count( $result, 'wp-caption &myAlignment' ) );
    272                 $this->assertSame( 1, preg_match( '/id="myId(?:[0-9]+)?"/', $result ) );
     276                $this->assertSame( 1, preg_match( '/id="myId(?:-[0-9]+)?"/', $result ) );
    273277                $this->assertSame( 1, substr_count( $result, self::CAPTION ) );
    274278        }
  • trunk/tests/phpunit/tests/post/attachments.php

    r63616 r64042  
    88class Tests_Post_Attachments extends WP_UnitTestCase {
    99
     10        /**
     11         * Original HTTPS value.
     12         *
     13         * @var string|null
     14         */
     15        private $original_https;
     16
     17        public function set_up() {
     18                parent::set_up();
     19
     20                $this->original_https = $_SERVER['HTTPS'] ?? null;
     21        }
     22
    1023        public function tear_down() {
    1124                // Remove all uploads.
    1225                $this->remove_added_uploads();
     26
     27                if ( null === $this->original_https ) {
     28                        unset( $_SERVER['HTTPS'] );
     29                } else {
     30                        $_SERVER['HTTPS'] = $this->original_https;
     31                }
     32
    1333                parent::tear_down();
    1434        }
    … …  
    122142                $this->assertEmpty( $upload['error'] );
    123143
    124                 $id      = $this->_make_attachment( $upload );
    125                 $uploads = wp_upload_dir();
     144                $id            = $this->_make_attachment( $upload );
     145                $uploads       = wp_upload_dir();
     146                $filename_base = wp_basename( $upload['file'], '.jpg' );
    126147
    127148                // Intermediate copies should exist: thumbnail and medium.
    128149                $thumb = image_get_intermediate_size( $id, 'thumbnail' );
    129                 $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
     150                $this->assertSame( $filename_base . '-150x150.jpg', $thumb['file'] );
    130151                $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) );
    131152
    132153                $medium = image_get_intermediate_size( $id, 'medium' );
    133                 $this->assertSame( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
     154                $this->assertSame( $filename_base . '-400x602.jpg', $medium['file'] );
    134155                $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) );
    135156
    136157                $medium_large = image_get_intermediate_size( $id, 'medium_large' );
    137                 $this->assertSame( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
     158                $this->assertSame( $filename_base . '-600x904.jpg', $medium_large['file'] );
    138159                $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) );
    139160
    … …  
    143164                // image_downsize() should return the correct images and sizes.
    144165                $downsize = image_downsize( $id, 'thumbnail' );
    145                 $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) );
     166                $this->assertSame( $filename_base . '-150x150.jpg', wp_basename( $downsize[0] ) );
    146167                $this->assertSame( 150, $downsize[1] );
    147168                $this->assertSame( 150, $downsize[2] );
    148169
    149170                $downsize = image_downsize( $id, 'medium' );
    150                 $this->assertSame( '2007-06-17DSC_4173-400x602.jpg', wp_basename( $downsize[0] ) );
     171                $this->assertSame( $filename_base . '-400x602.jpg', wp_basename( $downsize[0] ) );
    151172                $this->assertSame( 400, $downsize[1] );
    152173                $this->assertSame( 602, $downsize[2] );
    153174
    154175                $downsize = image_downsize( $id, 'medium_large' );
    155                 $this->assertSame( '2007-06-17DSC_4173-600x904.jpg', wp_basename( $downsize[0] ) );
     176                $this->assertSame( $filename_base . '-600x904.jpg', wp_basename( $downsize[0] ) );
    156177                $this->assertSame( 600, $downsize[1] );
    157178                $this->assertSame( 904, $downsize[2] );
    158179
    159180                $downsize = image_downsize( $id, 'full' );
    160                 $this->assertSame( '2007-06-17DSC_4173.jpg', wp_basename( $downsize[0] ) );
     181                $this->assertSame( $filename_base . '.jpg', wp_basename( $downsize[0] ) );
    161182                $this->assertSame( 680, $downsize[1] );
    162183                $this->assertSame( 1024, $downsize[2] );
    … …  
    179200                $this->assertEmpty( $upload['error'] );
    180201
    181                 $id      = $this->_make_attachment( $upload );
    182                 $uploads = wp_upload_dir();
     202                $id            = $this->_make_attachment( $upload );
     203                $uploads       = wp_upload_dir();
     204                $filename_base = wp_basename( $upload['file'], '.jpg' );
    183205
    184206                // Check that the file and intermediates exist.
    185207                $thumb = image_get_intermediate_size( $id, 'thumbnail' );
    186                 $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', $thumb['file'] );
     208                $this->assertSame( $filename_base . '-150x150.jpg', $thumb['file'] );
    187209                $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $thumb['path'] ) );
    188210
    189211                $medium = image_get_intermediate_size( $id, 'medium' );
    190                 $this->assertSame( '2007-06-17DSC_4173-400x602.jpg', $medium['file'] );
     212                $this->assertSame( $filename_base . '-400x602.jpg', $medium['file'] );
    191213                $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium['path'] ) );
    192214
    193215                $medium_large = image_get_intermediate_size( $id, 'medium_large' );
    194                 $this->assertSame( '2007-06-17DSC_4173-600x904.jpg', $medium_large['file'] );
     216                $this->assertSame( $filename_base . '-600x904.jpg', $medium_large['file'] );
    195217                $this->assertTrue( is_file( $uploads['basedir'] . DIRECTORY_SEPARATOR . $medium_large['path'] ) );
    196218
Note: See TracChangeset for help on using the changeset viewer.