Make WordPress Core


Ignore:
Timestamp:
12/05/2024 09:19:37 PM (17 months ago)
Author:
swissspidy
Message:

Embeds: ensure correct thumbnail height.

Use height 0 instead of 9999 to avoid unnecessarily using the full size version.

Props colinleroy, swissspidy.
Fixes #62094.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/oembed/getResponseData.php

    r58235 r59493  
    252252    }
    253253
     254    /**
     255     * @ticket 62094
     256     */
     257    public function test_get_oembed_response_data_has_correct_thumbnail_size() {
     258        $post = self::factory()->post->create_and_get();
     259
     260        /* Use a large image as post thumbnail */
     261        $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/33772.jpg' );
     262        set_post_thumbnail( $post, $attachment_id );
     263
     264        /* Get the image, sized for 400x??? pixels display */
     265        $image = wp_get_attachment_image_src( $attachment_id, array( 400, 0 ) );
     266
     267        /* Get the oembed data array for a 400 pixels wide embed */
     268        $data = get_oembed_response_data( $post, 400 );
     269
     270        /* Make sure the embed references the small image, not the full-size one. */
     271        $this->assertSame( $image[0], $data['thumbnail_url'] );
     272    }
     273
    254274    public function test_get_oembed_response_data_for_attachment() {
    255275        $parent = self::factory()->post->create();
Note: See TracChangeset for help on using the changeset viewer.