• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress develop tests

WordPress develop tests

WordPress develop tests a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Tests_Media::test_wp_make_content_images_responsive() –

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 ) );
  }
 

 View on GitHub

Published: 26th November 2019 | Last updated: 27th November 2019

Primary Sidebar

Information

Function name: Tests_Media::test_wp_make_content_images_responsive
Class ref: Tests_Media
Plugin ref: WordPress develop tests
Version: 5.3
Sourcefile: phpunit/tests/media.php
File ref: phpunit/tests/media.php
Deprecated?: No
API Letters: M,T,W

Footer

WordPress develop tests
WordPress develop tests
WordPress develop tests a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  develop.wp-a2z.org
© Copyright WordPress develop tests 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites