Make WordPress Core

Ticket #35106: 35106.patch

File 35106.patch, 2.6 KB (added by SergeyBiryukov, 9 years ago)
  • src/wp-includes/media.php

     
    10081008        if ( $image_basename !== $image_meta['file'] ) {
    10091009                $dirname = dirname( $image_meta['file'] );
    10101010
     1011                if ( false !== strpos( $dirname, 'wp-content/uploads/' ) ) {
     1012                        // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads)
     1013                        $dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads/' ) + 19 );
     1014                }
     1015
    10111016                if ( $dirname !== '.' ) {
    10121017                        $image_baseurl = trailingslashit( $image_baseurl ) . $dirname;
    10131018                }
  • tests/phpunit/tests/media.php

     
    866866        }
    867867
    868868        /**
     869         * @ticket 35106
     870         */
     871        function test_wp_calculate_image_srcset_with_absolute_path_in_meta() {
     872                global $_wp_additional_image_sizes;
     873
     874                $year_month = date('Y/m');
     875                $image_meta = wp_get_attachment_metadata( self::$large_id );
     876                $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
     877
     878                // Set up test cases for all expected size names.
     879                $intermediates = array( 'medium', 'medium_large', 'large', 'full' );
     880
     881                // Add any soft crop intermediate sizes.
     882                foreach ( $_wp_additional_image_sizes as $name => $additional_size ) {
     883                        if ( ! $_wp_additional_image_sizes[$name]['crop'] || 0 === $_wp_additional_image_sizes[$name]['height'] ) {
     884                                $intermediates[] = $name;
     885                        }
     886                }
     887
     888                $expected = '';
     889
     890                foreach( $image_meta['sizes'] as $name => $size ) {
     891                        // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
     892                        if ( in_array( $name, $intermediates ) ) {
     893                                $expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
     894                        }
     895                }
     896
     897                // Add the full size width at the end.
     898                $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
     899
     900                // Prepend an absolute path to simulate a pre-2.7 upload
     901                $image_meta['file'] = 'H:\home\wordpress\trunk/wp-content/uploads/' . $image_meta['file'];
     902
     903                foreach ( $intermediates as $int ) {
     904                        $image_url = wp_get_attachment_image_url( self::$large_id, $int );
     905                        $size_array = $this->_get_image_size_array_from_name( $int );
     906                        $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
     907                }
     908        }
     909
     910        /**
    869911         * @ticket 33641
    870912         */
    871913        function test_wp_calculate_image_srcset_false() {