Make WordPress Core


Ignore:
Timestamp:
11/07/2015 09:35:34 PM (8 years ago)
Author:
azaozz
Message:

Responsive images: make the new functions and filters signatures more consistent.

Props joemcgill.
Fixes #34612.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r35561 r35569  
    755755            $image_url = wp_get_attachment_image_url( self::$large_id, $size );
    756756            $size_array = $this->_get_image_size_array_from_name( $size );
    757             $this->assertSame( $expected, wp_calculate_image_srcset( $image_url, $size_array, $image_meta ) );
     757            $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
    758758        }
    759759    }
     
    787787            $size_array = $this->_get_image_size_array_from_name( $size );
    788788            $image_url = wp_get_attachment_image_url( $id, $size );
    789             $this->assertSame( $expected, wp_calculate_image_srcset( $image_url, $size_array, $image_meta ) );
     789            $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
    790790        }
    791791
     
    822822
    823823        // Calculate a srcset array.
    824         $sizes = explode( ', ', wp_calculate_image_srcset( $image_url, $size_array, $image_meta ) );
     824        $sizes = explode( ', ', wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
    825825
    826826        // Test to confirm all sources in the array include the same edit hash.
     
    834834     */
    835835    function test_wp_calculate_image_srcset_false() {
    836         $sizes = wp_calculate_image_srcset( 'file.png', array( 400, 300 ), array() );
     836        $sizes = wp_calculate_image_srcset( array( 400, 300 ), 'file.png', array() );
    837837
    838838        // For canola.jpg we should return
     
    850850        $size_array = array(0, 0);
    851851
    852         $srcset = wp_calculate_image_srcset( $image_url, $size_array, $image_meta );
     852        $srcset = wp_calculate_image_srcset( $size_array, $image_url, $image_meta );
    853853
    854854        // The srcset should be false.
     
    915915        // Test sizes against the default WP sizes.
    916916        $intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
     917
     918        foreach( $intermediates as $int_size ) {
     919            $image = wp_get_attachment_image_src( self::$large_id, $int_size );
     920
     921            $expected = '(max-width: ' . $image[1] . 'px) 100vw, ' . $image[1] . 'px';
     922            $sizes = wp_get_attachment_image_sizes( self::$large_id, $int_size );
     923
     924            $this->assertSame( $expected, $sizes );
     925        }
     926    }
     927
     928    /**
     929     * @ticket 33641
     930     */
     931    function test_wp_calculate_image_sizes() {
     932        // Test sizes against the default WP sizes.
     933        $intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
    917934        $image_meta = wp_get_attachment_metadata( self::$large_id );
    918935
    919936        foreach( $intermediates as $int_size ) {
    920937            $size_array = $this->_get_image_size_array_from_name( $int_size );
     938            $image_src = $image_meta['sizes'][$int_size]['file'];
    921939            list( $width, $height ) = $size_array;
    922940
    923941            $expected = '(max-width: ' . $width . 'px) 100vw, ' . $width . 'px';
    924             $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta );
     942            $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta );
    925943
    926944            $this->assertSame( $expected, $sizes );
     
    936954
    937955        $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) );
    938         $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( $size_array, $image_meta, self::$large_id ) );
     956        $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );
    939957
    940958        // Function used to build HTML for the editor.
     
    10201038
    10211039        // Full size GIFs should not return a srcset.
    1022         $this->assertFalse( wp_calculate_image_srcset( $full_src, $size_array, $image_meta ) );
     1040        $this->assertFalse( wp_calculate_image_srcset( $size_array, $full_src, $image_meta ) );
    10231041        // Intermediate sized GIFs should not include the full size in the srcset.
    1024         $this->assertFalse( strpos( wp_calculate_image_srcset( $large_src, $size_array, $image_meta ), $full_src ) );
     1042        $this->assertFalse( strpos( wp_calculate_image_srcset( $size_array, $large_src, $image_meta ), $full_src ) );
    10251043    }
    10261044}
Note: See TracChangeset for help on using the changeset viewer.