Make WordPress Core

Changeset 64260


Ignore:
Timestamp:
10/09/2026 06:00:42 PM (4 hours ago)
Author:
lancewillett
Message:

Tests: Reduce REST attachment quality fixture overhead.

Create attachment records with static image metadata for the three REST image quality response tests instead of uploading a JPEG and generating thumbnails. Preserve the requests, filters, and assertions while removing the unnecessary imagejpeg() requirements.

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

Props abcd95.
See #66074.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r64233 r64260  
    21572157        /**
    21582158         * @ticket 65262
    2159          * @requires function imagejpeg
    21602159         */
    21612160        public function test_image_quality_default_in_response() {
    21622161                wp_set_current_user( self::$editor_id );
    2163                 $attachment = self::factory()->attachment->create_upload_object( self::$test_file );
     2162                $attachment = $this->create_image_quality_test_attachment();
    21642163
    21652164                $request = new WP_REST_Request( 'GET', "/wp/v2/media/{$attachment}" );
    … …  
    21772176        /**
    21782177         * @ticket 65262
    2179          * @requires function imagejpeg
    21802178         */
    21812179        public function test_image_quality_with_size_aware_filter() {
    21822180                wp_set_current_user( self::$editor_id );
    2183                 $attachment = self::factory()->attachment->create_upload_object( self::$test_file );
     2181                $attachment = $this->create_image_quality_test_attachment();
    21842182
    21852183                // Lower the quality for small images (e.g. thumbnails) only.
    … …  
    22132211         *
    22142212         * @ticket 65262
    2215          * @requires function imagejpeg
    22162213         */
    22172214        public function test_image_quality_honors_jpeg_quality_filter() {
    22182215                wp_set_current_user( self::$editor_id );
    2219                 $attachment = self::factory()->attachment->create_upload_object( self::$test_file );
     2216                $attachment = $this->create_image_quality_test_attachment();
    22202217
    22212218                $filter = static function () {
    … …  
    22342231                // JPEG output, so the jpeg_quality filter overrides the 82 default.
    22352232                $this->assertSame( 70, $data['image_quality']['default'] );
     2233        }
     2234
     2235        /**
     2236         * Creates a JPEG attachment with static metadata for image quality tests.
     2237         *
     2238         * Quality reporting uses the MIME type, full-size dimensions, and registered
     2239         * image sizes, so no upload or generated thumbnails are needed.
     2240         *
     2241         * @return int Attachment post ID.
     2242         */
     2243        private function create_image_quality_test_attachment() {
     2244                $attachment_id = self::factory()->attachment->create(
     2245                        array(
     2246                                'post_mime_type' => 'image/jpeg',
     2247                                'post_status'    => 'inherit',
     2248                                'file'           => 'canola.jpg',
     2249                        )
     2250                );
     2251
     2252                wp_update_attachment_metadata(
     2253                        $attachment_id,
     2254                        array(
     2255                                'width'  => 640,
     2256                                'height' => 480,
     2257                                'file'   => 'canola.jpg',
     2258                        )
     2259                );
     2260
     2261                return $attachment_id;
    22362262        }
    22372263
Note: See TracChangeset for help on using the changeset viewer.