Responsive images: add test for invalid size name. Remove invalid size from other tests.

Props jaspermdegroot.
See #33641.

git-svn-id: https://develop.svn.wordpress.org/trunk@35560 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-11-07 01:32:41 +00:00
parent 9cd8c7e2c0
commit 3df03d1675
1 changed files with 22 additions and 6 deletions

View File

@ -748,8 +748,8 @@ EOF;
$uploads_dir_url . $year_month . '/' . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' . $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
$uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
// Set up test cases for all expected size names and a random one. // Set up test cases for all expected size names.
$sizes = array( 'medium', 'medium_large', 'large', 'full', 'yoav' ); $sizes = array( 'medium', 'medium_large', 'large', 'full' );
foreach ( $sizes as $size ) { foreach ( $sizes as $size ) {
$image_url = wp_get_attachment_image_url( self::$large_id, $size ); $image_url = wp_get_attachment_image_url( self::$large_id, $size );
@ -780,8 +780,8 @@ EOF;
$uploads_dir_url . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' . $uploads_dir_url . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ' .
$uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w'; $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w';
// Set up test cases for all expected size names and a random one. // Set up test cases for all expected size names.
$sizes = array( 'medium', 'medium_large', 'large', 'full', 'yoav' ); $sizes = array( 'medium', 'medium_large', 'large', 'full' );
foreach ( $sizes as $size ) { foreach ( $sizes as $size ) {
$size_array = $this->_get_image_size_array_from_name( $size ); $size_array = $this->_get_image_size_array_from_name( $size );
@ -862,7 +862,7 @@ EOF;
$image_meta = wp_get_attachment_metadata( self::$large_id ); $image_meta = wp_get_attachment_metadata( self::$large_id );
$size_array = array( 1600, 1200 ); // full size $size_array = array( 1600, 1200 ); // full size
$sizes = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta ); $srcset = wp_get_attachment_image_srcset( self::$large_id, $size_array, $image_meta );
$year_month = date('Y/m'); $year_month = date('Y/m');
@ -874,7 +874,7 @@ EOF;
. $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, '; . $image_meta['sizes']['large']['file'] . ' ' . $image_meta['sizes']['large']['width'] . 'w, ';
$expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file'] . ' ' . $image_meta['width'] .'w'; $expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
$this->assertSame( $expected, $sizes ); $this->assertSame( $expected, $srcset );
} }
/** /**
@ -892,6 +892,22 @@ EOF;
$this->assertFalse( $sizes ); $this->assertFalse( $sizes );
} }
/**
* @ticket 33641
*/
function test_wp_get_attachment_image_srcset_invalidsize() {
$image_meta = wp_get_attachment_metadata( self::$large_id );
$invalid_size = 'nailthumb';
$original_size = array( 1600, 1200 );
$srcset = wp_get_attachment_image_srcset( self::$large_id, $invalid_size, $image_meta );
// Expect a srcset for the original full size image to be returned.
$expected = wp_get_attachment_image_srcset( self::$large_id, $original_size, $image_meta );
$this->assertSame( $expected, $srcset );
}
/** /**
* @ticket 33641 * @ticket 33641
*/ */