You appear to be a bot. Output may be restricted
Description
Usage
Tests_Media::test_wp_make_content_images_responsive();
Parameters
Returns
void
Source
File name: wordpress-develop-tests/phpunit/tests/media.php
Lines:
1 to 53 of 53
function test_wp_make_content_images_responsive() { $image_meta = wp_get_attachment_metadata( self::$large_id ); $size_array = $this->_get_image_size_array_from_meta( $image_meta, 'medium' ); $srcset = sprintf( 'srcset="%s"', wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ) ); $sizes = sprintf( 'sizes="%s"', wp_get_attachment_image_sizes( self::$large_id, $size_array, $image_meta ) ); // Function used to build HTML for the editor. $img = get_image_tag( self::$large_id, '', '', '', 'medium' ); $img_no_size_in_class = str_replace( 'size-', '', $img ); $img_no_width_height = str_replace( ' width="' . $size_array[0] . '"', '', $img ); $img_no_width_height = str_replace( ' height="' . $size_array[1] . '"', '', $img_no_width_height ); $img_no_size_id = str_replace( 'wp-image-', 'id-', $img ); $img_with_sizes_attr = str_replace( '<img ', '<img sizes="99vw" ', $img ); $img_xhtml = str_replace( ' />', '/>', $img ); $img_html5 = str_replace( ' />', '>', $img ); // Manually add srcset and sizes to the markup from get_image_tag(); $respimg = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img ); $respimg_no_size_in_class = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class ); $respimg_no_width_height = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height ); $respimg_with_sizes_attr = preg_replace( '|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr ); $respimg_xhtml = preg_replace( '|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml ); $respimg_html5 = preg_replace( '|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5 ); $content = ' <p>Image, standard. Should have srcset and sizes.</p> %1$s <p>Image, no size class. Should have srcset and sizes.</p> %2$s <p>Image, no width and height attributes. Should have srcset and sizes (from matching the file name).</p> %3$s <p>Image, no attachment ID class. Should NOT have srcset and sizes.</p> %4$s <p>Image, with sizes attribute. Should NOT have two sizes attributes.</p> %5$s <p>Image, XHTML 1.0 style (no space before the closing slash). Should have srcset and sizes.</p> %6$s <p>Image, HTML 5.0 style. Should have srcset and sizes.</p> %7$s'; $content_unfiltered = sprintf( $content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr, $img_xhtml, $img_html5 ); $content_filtered = sprintf( $content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr, $respimg_xhtml, $respimg_html5 ); $this->assertSame( $content_filtered, wp_make_content_images_responsive( $content_unfiltered ) ); }