Make WordPress Core


Ignore:
Timestamp:
10/30/2015 11:26:44 PM (9 years ago)
Author:
azaozz
Message:

Responsive images:

  • Merge wp_image_srcset_attr() into wp_calculate_image_srcset().
  • Remove the wp_image_srcset filter.
  • Fix the tests for the above changes.

See #34430.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r35412 r35464  
    740740        $year_month = date('Y/m');
    741741        $image_meta = wp_get_attachment_metadata( self::$large_id );
    742 
    743         $expected = array(
    744             array(
    745                 'url'        => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month . '/' . $image_meta['sizes']['medium']['file'],
    746                 'descriptor' => 'w',
    747                 'value'      => $image_meta['sizes']['medium']['width'],
    748             ),
    749             array(
    750                 'url'        => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month . '/' . $image_meta['sizes']['large']['file'],
    751                 'descriptor' => 'w',
    752                 'value'      => $image_meta['sizes']['large']['width'],
    753             ),
    754             array(
    755                 'url'        => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file'],
    756                 'descriptor' => 'w',
    757                 'value'      => $image_meta['width'],
    758             ),
    759         );
     742        $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
     743
     744        $expected = $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
     745                $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
     746                $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
    760747
    761748        // Set up test cases for all expected size names and a random one.
     
    784771
    785772        $image_meta = wp_get_attachment_metadata( $id );
    786 
    787         $expected = array(
    788             array(
    789                 'url'        => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['medium']['file'],
    790                 'descriptor' => 'w',
    791                 'value'      => $image_meta['sizes']['medium']['width'],
    792             ),
    793             array(
    794                 'url'        => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file'],
    795                 'descriptor' => 'w',
    796                 'value'      => $image_meta['sizes']['large']['width'],
    797             ),
    798             array(
    799                 'url'        => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file'],
    800                 'descriptor' => 'w',
    801                 'value'      => $image_meta['width'],
    802             ),
    803         );
     773        $uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
     774
     775        $expected = $uploads_dir_url . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
     776                $uploads_dir_url . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
     777                $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
    804778
    805779        // Set up test cases for all expected size names and a random one.
     
    836810
    837811        // Calculate a srcset array.
    838         $sizes = wp_calculate_image_srcset( $image_url, $size_array, $image_meta );
     812        $sizes = explode( ', ', wp_calculate_image_srcset( $image_url, $size_array, $image_meta ) );
    839813
    840814        // Test to confirm all sources in the array include the same edit hash.
    841815        foreach ( $sizes as $size ) {
    842             $this->assertTrue( false !== strpos( $size['url'], $hash ) );
     816            $this->assertTrue( false !== strpos( $size, $hash ) );
    843817        }
    844818    }
Note: See TracChangeset for help on using the changeset viewer.