Make WordPress Core


Ignore:
Timestamp:
03/16/2016 10:48:13 PM (8 years ago)
Author:
johnbillion
Message:

Media: When generating the base URL to be used in the srcset attribute, use an https scheme when the image base URL's host matches that of the current host, and the request is being served over HTTPS. This prevents mixed content warnings caused by http embedded media.

See #34945
Props joemcgill

File:
1 edited

Legend:

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

    r37018 r37022  
    14811481
    14821482        $this->assertSame( $expected, $actual );
    1483     }
    14841483}
     1484
     1485    /**
     1486     * @ticket 34945
     1487     * @ticket 33641
     1488     */
     1489    function test_wp_get_attachment_image_with_https_on() {
     1490        // Mock meta for the image.
     1491        $image_meta = array(
     1492            'width'  => 1200,
     1493            'height' => 600,
     1494            'file'   => 'test.jpg',
     1495            'sizes'  => array(
     1496                'thumbnail' => array(
     1497                    'file'   => 'test-150x150.jpg',
     1498                    'width'  => 150,
     1499                    'height' => 150,
     1500                ),
     1501                'medium'    => array(
     1502                    'file'   => 'test-300x150.jpg',
     1503                    'width'  => 300,
     1504                    'height' => 150,
     1505                ),
     1506                'large'     => array(
     1507                    'file'   => 'test-1024x512.jpg',
     1508                    'width'  => 1024,
     1509                    'height' => 512,
     1510                ),
     1511            )
     1512        );
     1513
     1514        // Test using the large file size.
     1515        $size_array = array( 1024, 512 );
     1516        $image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file'];
     1517
     1518        $_SERVER['HTTPS'] = 'on';
     1519
     1520        $expected = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-300x150.jpg 300w, https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test-1024x512.jpg 1024w, https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/test.jpg 1200w';
     1521        $actual   = wp_calculate_image_srcset( $size_array, $image_url, $image_meta );
     1522
     1523        $this->assertSame( $expected, $actual );
     1524    }
     1525}
Note: See TracChangeset for help on using the changeset viewer.