Unit Tests: fix responsive image unit tests. Correct the logic in video shortcode unit test for width.

Props joemcgill, wonderboymusic.
Fixes #34790.


git-svn-id: https://develop.svn.wordpress.org/trunk@35751 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-12-01 20:44:54 +00:00
parent cfbd88836d
commit c8b7126cbf
1 changed files with 98 additions and 41 deletions

View File

@ -425,10 +425,15 @@ VIDEO;
$width = 720;
$height = 480;
$w = empty( $GLOBALS['content_width'] ) ? 640 : $GLOBALS['content_width'];
if ( $width > $w ) {
$width = $w;
}
$post_id = get_post() ? get_the_ID() : 0;
$video =<<<VIDEO
[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]
[video width="$width" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]
<!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
<source type="video/webm" src="myvideo.webm" />
<!-- Ogg/Vorbis for older Firefox and Opera versions -->
@ -440,14 +445,14 @@ VIDEO;
[/video]
VIDEO;
$w = empty( $GLOBALS['content_width'] ) ? 640 : $GLOBALS['content_width'];
$h = ceil( ( $height * $w ) / $width );
$h = ceil( ( $height * $width ) / $width );
$content = apply_filters( 'the_content', $video );
$expected = '<div style="width: ' . $w . 'px; " class="wp-video">' .
$expected = '<div style="width: ' . $width . 'px; " class="wp-video">' .
"<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n" .
'<video class="wp-video-shortcode" id="video-' . $post_id . '-1" width="' . $w . '" height="' . $h . '" preload="metadata" controls="controls">' .
'<video class="wp-video-shortcode" id="video-' . $post_id . '-1" width="' . $width . '" height="' . $h . '" preload="metadata" controls="controls">' .
'<source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4?_=1" />' .
'<!-- WebM/VP8 for Firefox4, Opera, and Chrome --><source type="video/webm" src="myvideo.webm" />' .
'<!-- Ogg/Vorbis for older Firefox and Opera versions --><source type="video/ogg" src="myvideo.ogv" />' .
@ -739,21 +744,37 @@ EOF;
* @ticket 33641
*/
function test_wp_calculate_image_srcset() {
global $_wp_additional_image_sizes;
$year_month = date('Y/m');
$image_meta = wp_get_attachment_metadata( self::$large_id );
$uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
$expected = $uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
$uploads_dir_url . $year_month . '/' . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_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';
// Set up test cases for all expected size names.
$sizes = array( 'medium', 'medium_large', 'large', 'full' );
$intermediates = array( 'medium', 'medium_large', 'large', 'full' );
foreach ( $sizes as $size ) {
$image_url = wp_get_attachment_image_url( self::$large_id, $size );
$size_array = $this->_get_image_size_array_from_name( $size );
// Add any soft crop intermediate sizes.
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 ) ) {
$expected .= $uploads_dir_url . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
// Add the full size width at the end.
$expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
foreach ( $intermediates as $int ) {
$image_url = wp_get_attachment_image_url( self::$large_id, $int );
$size_array = $this->_get_image_size_array_from_name( $int );
$this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
}
}
@ -762,6 +783,8 @@ EOF;
* @ticket 33641
*/
function test_wp_calculate_image_srcset_no_date_uploads() {
global $_wp_additional_image_sizes;
// Save the current setting for uploads folders
$uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
@ -775,17 +798,30 @@ EOF;
$image_meta = wp_get_attachment_metadata( $id );
$uploads_dir_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
$expected = $uploads_dir_url . $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ' .
$uploads_dir_url . $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_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';
// Set up test cases for all expected size names.
$sizes = array( 'medium', 'medium_large', 'large', 'full' );
$intermediates = array( 'medium', 'medium_large', 'large', 'full' );
foreach ( $sizes as $size ) {
$size_array = $this->_get_image_size_array_from_name( $size );
$image_url = wp_get_attachment_image_url( $id, $size );
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 ) ) {
$expected .= $uploads_dir_url . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
// Add the full size width at the end.
$expected .= $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
foreach ( $intermediates as $int ) {
$size_array = $this->_get_image_size_array_from_name( $int );
$image_url = wp_get_attachment_image_url( $id, $int );
$this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
}
@ -859,20 +895,35 @@ EOF;
* @ticket 33641
*/
function test_wp_get_attachment_image_srcset() {
global $_wp_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 = date('Y/m');
$uploads_dir = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/';
$expected = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
. $image_meta['sizes']['medium']['file'] . ' ' . $image_meta['sizes']['medium']['width'] . 'w, ';
$expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
. $image_meta['sizes']['medium_large']['file'] . ' ' . $image_meta['sizes']['medium_large']['width'] . 'w, ';
$expected .= 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year_month = date('Y/m') . '/'
. $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';
// 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 ) ) {
$expected .= $uploads_dir . $year_month . '/' . $size['file'] . ' ' . $size['width'] . 'w, ';
}
}
$expected .= $uploads_dir . $image_meta['file'] . ' ' . $image_meta['width'] .'w';
$this->assertSame( $expected, $srcset );
}
@ -915,6 +966,9 @@ EOF;
// Test sizes against the default WP sizes.
$intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
// Make sure themes aren't filtering the sizes array.
remove_all_filters( 'wp_calculate_image_sizes' );
foreach( $intermediates as $int_size ) {
$image = wp_get_attachment_image_src( self::$large_id, $int_size );
@ -933,6 +987,9 @@ EOF;
$intermediates = array('thumbnail', 'medium', 'medium_large', 'large');
$image_meta = wp_get_attachment_metadata( self::$large_id );
// Make sure themes aren't filtering the sizes array.
remove_all_filters( 'wp_calculate_image_sizes' );
foreach( $intermediates as $int_size ) {
$size_array = $this->_get_image_size_array_from_name( $int_size );
$image_src = $image_meta['sizes'][$int_size]['file'];