• 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_get_attachment_image_srcset() –

You appear to be a bot. Output may be restricted

Description

Usage

Tests_Media::test_wp_get_attachment_image_srcset();

Parameters

Returns

void

Source

File name: wordpress-develop-tests/phpunit/tests/media.php


Lines:

1 to 36 of 36
  function test_wp_get_attachment_image_srcset() {
    $_wp_additional_image_sizes = wp_get_additional_image_sizes();

    $image_meta = wp_get_attachment_metadata( self::$large_id );
    $size_array = array( 1600, 1200 ); // full size

    $srcset = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta );

    $year_month  = gmdate( 'Y/m' );
    $uploads_dir = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';

    // Set up test cases for all expected size names.
    $intermediates = array( 'medium', 'medium_large', 'large', 'full' );

    foreach ( $_wp_additional_image_sizes as $name => $additional_size ) {
      if ( ! $_wp_additional_image_sizes[ $name ]['crop'] || 0 === $_wp_additional_image_sizes[ $name ]['height'] ) {
        $intermediates[] = $name;
      }
    }

    $expected = '';

    foreach ( $image_meta['sizes'] as $name => $size ) {
      // Whitelist the sizes that should be included so we pick up 'medium_large' in 4.4.
      if ( in_array( $name, $intermediates, true ) ) {
        $expected .= $uploads_dir . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
      }
    }

    $expected .= $uploads_dir . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';

    $expected_srcset = $this->_src_first( $expected, $uploads_dir . $image_meta['file'], $size_array[0] );

    $this->assertSame( $expected_srcset, $srcset );
  }
 

 View on GitHub

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

Primary Sidebar

Information

Function name: Tests_Media::test_wp_get_attachment_image_srcset
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: G,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