WordPress.org

Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4/tests/phpunit/tests/media.php

    r35821 r36152  
    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     */
     
    890932        // The srcset should be false.
    891933        $this->assertFalse( $srcset );
     934    }
     935
     936    /**
     937     * @ticket 35108
     938     * @ticket 33641
     939     */
     940    function test_wp_calculate_image_srcset_include_src() {
     941        // Mock data for this test.
     942        $size_array = array( 2000, 1000 );
     943        $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png';
     944        $image_meta = array(
     945            'width' => 2000,
     946            'height' => 1000,
     947            'file' => '2015/12/test.png',
     948            'sizes' => array(
     949                'thumbnail' => array(
     950                    'file' => 'test-150x150.png',
     951                    'width' => 150,
     952                    'height' => 150,
     953                    'mime-type' => 'image/png',
     954                ),
     955                'medium' => array(
     956                    'file' => 'test-300x150.png',
     957                    'width' => 300,
     958                    'height' => 150,
     959                    'mime-type' => 'image/png',
     960                ),
     961                'medium_large' => array(
     962                    'file' => 'test-768x384.png',
     963                    'width' => 768,
     964                    'height' => 384,
     965                    'mime-type' => 'image/png',
     966                ),
     967                'large' => array(
     968                    'file' => 'test-1024x512.png',
     969                    'width' => 1024,
     970                    'height' => 512,
     971                    'mime-type' => 'image/png',
     972                ),
     973            ),
     974        );
     975
     976        $expected_srcset = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-300x150.png 300w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-768x384.png 768w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test-1024x512.png 1024w, http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/2015/12/test.png 2000w';
     977
     978        $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_src, $image_meta ) );
    892979    }
    893980
     
    11341221        $this->assertFalse( strpos( wp_calculate_image_srcset( $size_array, $large_src, $image_meta ), $full_src ) );
    11351222    }
     1223
     1224    /**
     1225     * @ticket 35045
     1226     * @ticket 33641
     1227     */
     1228    function test_wp_make_content_images_responsive_schemes() {
     1229        $image_meta = wp_get_attachment_metadata( self::$large_id );
     1230        $size_array = $this->_get_image_size_array_from_name( 'medium' );
     1231
     1232        $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) );
     1233        $sizes  = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) );
     1234
     1235        // Build HTML for the editor.
     1236        $img          = get_image_tag( self::$large_id, '', '', '', 'medium' );
     1237        $img_https    = str_replace( 'http://', 'https://', $img );
     1238        $img_relative = str_replace( 'http://', '//', $img );
     1239
     1240        // Manually add srcset and sizes to the markup from get_image_tag().
     1241        $respimg          = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img );
     1242        $respimg_https    = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_https );
     1243        $respimg_relative = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_relative );
     1244
     1245        $content = '
     1246            <p>Image, http: protocol. Should have srcset and sizes.</p>
     1247            %1$s
     1248
     1249            <p>Image, https: protocol. Should have srcset and sizes.</p>
     1250            %2$s
     1251
     1252            <p>Image, protocol-relative. Should have srcset and sizes.</p>
     1253            %3$s';
     1254
     1255        $unfiltered = sprintf( $content, $img, $img_https, $img_relative );
     1256        $expected   = sprintf( $content, $respimg, $respimg_https, $respimg_relative );
     1257        $actual     = wp_make_content_images_responsive( $unfiltered );
     1258
     1259        $this->assertSame( $expected, $actual );
     1260    }
    11361261}
Note: See TracChangeset for help on using the changeset viewer.