Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: tests/phpunit/data/images/test-image-large.jpg
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: tests/phpunit/data/images/test-image-large.png
___________________________________________________________________
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
|
|
|
|
| 7 | 7 | class Tests_Media extends WP_UnitTestCase { |
| 8 | 8 | protected static $large_id; |
| 9 | 9 | protected static $_sizes; |
| | 10 | protected static $large_filename = 'test-image-large.jpg'; |
| 10 | 11 | |
| 11 | 12 | public static function wpSetUpBeforeClass( $factory ) { |
| 12 | 13 | self::$_sizes = wp_get_additional_image_sizes(); |
| 13 | 14 | $GLOBALS['_wp_additional_image_sizes'] = array(); |
| 14 | 15 | |
| 15 | | $filename = DIR_TESTDATA . '/images/test-image-large.png'; |
| | 16 | $filename = DIR_TESTDATA . '/images/' . self::$large_filename; |
| 16 | 17 | self::$large_id = $factory->attachment->create_upload_object( $filename ); |
| 17 | 18 | } |
| 18 | 19 | |
| … |
… |
|
| 1479 | 1480 | } |
| 1480 | 1481 | } |
| 1481 | 1482 | |
| 1482 | | // Add the full size width at the end. |
| 1483 | | $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; |
| | 1483 | $expected = trim( $expected, ' ,' ); |
| 1484 | 1484 | |
| 1485 | 1485 | foreach ( $intermediates as $int ) { |
| 1486 | 1486 | $image_url = wp_get_attachment_image_url( self::$large_id, $int ); |
| 1487 | 1487 | $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int ); |
| | 1488 | |
| | 1489 | if ( 'full' === $int ) { |
| | 1490 | // Add the full size image. |
| | 1491 | $expected = $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w, ' . $expected; |
| | 1492 | } |
| | 1493 | |
| 1488 | 1494 | $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] ); |
| 1489 | 1495 | $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); |
| 1490 | 1496 | } |
| … |
… |
|
| 1500 | 1506 | add_filter( 'upload_dir', '_upload_dir_no_subdir' ); |
| 1501 | 1507 | |
| 1502 | 1508 | // Make an image. |
| 1503 | | $filename = DIR_TESTDATA . '/images/test-image-large.png'; |
| | 1509 | $filename = DIR_TESTDATA . '/images/' . self::$large_filename; |
| 1504 | 1510 | $id = self::factory()->attachment->create_upload_object( $filename ); |
| 1505 | 1511 | |
| 1506 | 1512 | $image_meta = wp_get_attachment_metadata( $id ); |
| … |
… |
|
| 1524 | 1530 | } |
| 1525 | 1531 | } |
| 1526 | 1532 | |
| 1527 | | // Add the full size width at the end. |
| 1528 | | $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; |
| | 1533 | $expected = trim( $expected, ' ,' ); |
| 1529 | 1534 | |
| 1530 | 1535 | foreach ( $intermediates as $int ) { |
| 1531 | 1536 | $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int ); |
| 1532 | 1537 | $image_url = wp_get_attachment_image_url( $id, $int ); |
| | 1538 | |
| | 1539 | if ( 'full' === $int ) { |
| | 1540 | // Add the full size image. |
| | 1541 | $expected = $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w, ' . $expected; |
| | 1542 | } |
| | 1543 | |
| 1533 | 1544 | $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] ); |
| 1534 | 1545 | $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); |
| 1535 | 1546 | } |
| … |
… |
|
| 1552 | 1563 | // Copy hash generation method used in wp_save_image(). |
| 1553 | 1564 | $hash = 'e' . time() . rand( 100, 999 ); |
| 1554 | 1565 | |
| 1555 | | $filename_base = wp_basename( $image_meta['file'], '.png' ); |
| | 1566 | $filename_base = wp_basename( $image_meta['file'], '-scaled.jpg' ); |
| 1556 | 1567 | |
| 1557 | 1568 | // Add the hash to the image URL. |
| 1558 | 1569 | $image_url = str_replace( $filename_base, $filename_base . '-' . $hash, $image_url ); |
| 1559 | 1570 | |
| 1560 | 1571 | // Replace file paths for full and medium sizes with hashed versions. |
| 1561 | | $image_meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['file'] ); |
| 1562 | 1572 | $image_meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium']['file'] ); |
| 1563 | 1573 | $image_meta['sizes']['medium_large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium_large']['file'] ); |
| 1564 | 1574 | $image_meta['sizes']['large']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['large']['file'] ); |
| … |
… |
|
| 1601 | 1611 | } |
| 1602 | 1612 | } |
| 1603 | 1613 | |
| 1604 | | // Add the full size width at the end. |
| 1605 | | $expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; |
| | 1614 | $expected = trim( $expected, ' ,' ); |
| | 1615 | $full_size_file = $image_meta['file']; |
| 1606 | 1616 | |
| 1607 | 1617 | // Prepend an absolute path to simulate a pre-2.7 upload. |
| 1608 | 1618 | $image_meta['file'] = 'H:\home\wordpress\trunk/wp-content/uploads/' . $image_meta['file']; |
| … |
… |
|
| 1610 | 1620 | foreach ( $intermediates as $int ) { |
| 1611 | 1621 | $image_url = wp_get_attachment_image_url( self::$large_id, $int ); |
| 1612 | 1622 | $size_array = $this->_get_image_size_array_from_meta( $image_meta, $int ); |
| | 1623 | |
| | 1624 | if ( 'full' === $int ) { |
| | 1625 | // Add the full size image. |
| | 1626 | $expected = $uploads_dir_url . $full_size_file . ' ' . $image_meta['width'] . 'w, ' . $expected; |
| | 1627 | } |
| | 1628 | |
| 1613 | 1629 | $expected_srcset = $this->_src_first( $expected, $image_url, $size_array[0] ); |
| 1614 | 1630 | $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); |
| 1615 | 1631 | } |
| … |
… |
|
| 1855 | 1871 | $_wp_additional_image_sizes = wp_get_additional_image_sizes(); |
| 1856 | 1872 | |
| 1857 | 1873 | $image_meta = wp_get_attachment_metadata( self::$large_id ); |
| 1858 | | $size_array = array( 1600, 1200 ); // Full size. |
| | 1874 | $size_array = array( $image_meta['width'], $image_meta['height'] ); // Full size. |
| 1859 | 1875 | |
| 1860 | 1876 | $srcset = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ); |
| 1861 | 1877 | |
| … |
… |
|
| 2272 | 2288 | $expected = '<img width="999" height="999" src="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-testsize-999x999.png"' . |
| 2273 | 2289 | ' class="attachment-testsize size-testsize" alt="" loading="lazy"' . |
| 2274 | 2290 | ' srcset="http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-testsize-999x999.png 999w,' . |
| 2275 | | ' http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-large-150x150.png 150w"' . |
| | 2291 | ' http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-image-large-150x150.jpg 150w"' . |
| 2276 | 2292 | ' sizes="(max-width: 999px) 100vw, 999px" />'; |
| 2277 | 2293 | |
| 2278 | 2294 | remove_filter( 'wp_get_attachment_metadata', array( $this, '_filter_36246' ) ); |
| … |
… |
|
| 2852 | 2868 | |
| 2853 | 2869 | $this->assertFalse( wp_image_file_matches_image_meta( $image_src, $image_meta ) ); |
| 2854 | 2870 | } |
| | 2871 | |
| | 2872 | /** |
| | 2873 | * @ticket 50543 |
| | 2874 | */ |
| | 2875 | function test_wp_image_file_matches_image_meta_original_image() { |
| | 2876 | $image_meta = wp_get_attachment_metadata( self::$large_id ); |
| | 2877 | $image_src = wp_get_original_image_url( self::$large_id ); |
| | 2878 | |
| | 2879 | $this->assertTrue( wp_image_file_matches_image_meta( $image_src, $image_meta ) ); |
| | 2880 | } |
| 2855 | 2881 | } |
| 2856 | 2882 | |
| 2857 | 2883 | /** |