[wp-trac] [WordPress Trac] #38457: PHPUnit suite in trunk does not pass currently: 3 tests with extra sizes="100vw" in output
WordPress Trac
noreply at wordpress.org
Sun Oct 23 14:19:27 UTC 2016
#38457: PHPUnit suite in trunk does not pass currently: 3 tests with extra
sizes="100vw" in output
---------------------------+-----------------------------
Reporter: ottok | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Bundled Theme | Version: trunk
Severity: normal | Keywords:
Focuses: |
---------------------------+-----------------------------
Current WordPress development trunk currently fails with the following 3
failures:
{{{
There were 3 failures:
1) Tests_Media::test_wp_get_attachment_image_defaults
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<img width="150" height="150" src="http://example.org/wp-
content/uploads/2016/10/test-image-large-150x150.png" class="attachment-
thumbnail size-thumbnail" alt="" />'
+'<img width="150" height="150" src="http://example.org/wp-
content/uploads/2016/10/test-image-large-150x150.png" class="attachment-
thumbnail size-thumbnail" alt="" sizes="100vw" />'
/vagrant/www/wordpress-develop/tests/phpunit/tests/media.php:932
2) Tests_Media::test_wp_get_attachment_image_with_alt
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<img width="150" height="150" src="http://example.org/wp-
content/uploads/2016/10/test-image-large-150x150.png" class="attachment-
thumbnail size-thumbnail" alt="Some very clever alt text" />'
+'<img width="150" height="150" src="http://example.org/wp-
content/uploads/2016/10/test-image-large-150x150.png" class="attachment-
thumbnail size-thumbnail" alt="Some very clever alt text" sizes="100vw"
/>'
/vagrant/www/wordpress-develop/tests/phpunit/tests/media.php:946
3)
Tests_Media::test_wp_get_attachment_image_should_use_wp_get_attachment_metadata
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-<img width="999" height="999" src="http://example.org/wp-
content/uploads/2016/10/test-image-testsize-999x999.png" class
="attachment-testsize size-testsize" alt="" srcset="http://example.org/wp-
content/uploads/2016/10/test-image-testsize-999x999.png 999w,
http://example.org/wp-content/uploads/2016/10/test-image-large-150x150.png
150w" sizes="(max-width: 999px) 100vw, 999px" />
+<img width="999" height="999" src="http://example.org/wp-
content/uploads/2016/10/test-image-testsize-999x999.png" class
="attachment-testsize size-testsize" alt="" srcset="http://example.org/wp-
content/uploads/2016/10/test-image-testsize-999x999.png 999w,
http://example.org/wp-content/uploads/2016/10/test-image-large-150x150.png
150w" sizes="100vw" />
/vagrant/www/wordpress-develop/tests/phpunit/tests/media.php:1852
}}}
These are all related to the same thing. There is an extra string in the
output:
{{{
sizes="100vw"
}}}
This sizes-string seem to stem from the 2017 theme. Removing that theme
removes the test failures (de-activating the theme was not enough!).
Below is the code block that introduces this string. I don't know what is
the proper fix, but I am happy to take a shot if somebody gives me some
guidance. (I am a PHP programmer.)
{{{
/**
* Add custom image sizes attribute to enhance responsive image
functionality
* for post thumbnails.
*
* @since Twenty Seventeen 1.0
*
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height
and width dimensions.
* @return string A source size value for use in a post thumbnail 'sizes'
attribute.
*/
function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment,
$size ) {
if ( is_archive() || is_search() || is_home() ) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width:
1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes',
'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
}}}
Failing tests:
{{{
/**
* Tests the default output of `wp_get_attachment_image()`.
* @ticket 34635
*/
function test_wp_get_attachment_image_defaults() {
$image = image_downsize( self::$large_id, 'thumbnail' );
$expected = sprintf( '<img width="%1$d" height="%2$d"
src="%3$s" class="attachment-thumbnail size-thumbnail" alt="" />',
$image[1], $image[2], $image[0] );
$this->assertEquals( $expected, wp_get_attachment_image(
self::$large_id ) );
}
/**
* Test that `wp_get_attachment_image()` returns a proper alt
value.
* @ticket 34635
*/
function test_wp_get_attachment_image_with_alt() {
// Add test alt metadata.
update_post_meta( self::$large_id,
'_wp_attachment_image_alt', 'Some very clever alt text', true );
$image = image_downsize( self::$large_id, 'thumbnail' );
$expected = sprintf( '<img width="%1$d" height="%2$d"
src="%3$s" class="attachment-thumbnail size-thumbnail" alt="Some very
clever alt text" />', $image[1], $image[2], $image[0] );
$this->assertEquals( $expected, wp_get_attachment_image(
self::$large_id ) );
// Cleanup.
update_post_meta( self::$large_id,
'_wp_attachment_image_alt', '', true );
}
/**
* Tests if wp_get_attachment_image() uses
wp_get_attachment_metadata().
*
* In this way, the meta data can be filtered using the filter
* `wp_get_attachment_metadata`.
*
* The test checks if the image size that is added in the filter
is
* used in the output of `wp_get_attachment_image()`.
*
* @ticket 36246
*/
function
test_wp_get_attachment_image_should_use_wp_get_attachment_metadata() {
add_filter( 'wp_get_attachment_metadata', array( $this,
'_filter_36246' ), 10, 2 );
remove_all_filters( 'wp_calculate_image_sizes' );
$actual = wp_get_attachment_image( self::$large_id,
'testsize' );
$year = date( 'Y' );
$month = date( 'm' );
$expected = '<img width="999" height="999" src="http://' .
WP_TESTS_DOMAIN . '/wp-content/uploads/' . $year . '/' . $month . '/test-
image-testsize-999x999.png"' .
' class="attachment-testsize size-testsize"
alt=""' .
' srcset="http://' . WP_TESTS_DOMAIN . '/wp-
content/uploads/' . $year . '/' . $month . '/test-image-testsize-
999x999.png 999w,' .
' http://' . WP_TESTS_DOMAIN . '/wp-
content/uploads/' . $year . '/' . $month . '/test-image-large-150x150.png
150w"' .
' sizes="(max-width: 999px) 100vw, 999px"
/>';
remove_filter( 'wp_get_attachment_metadata', array( $this,
'_filter_36246' ) );
$this->assertSame( $expected, $actual );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38457>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list