From 0711e585fb745feb6caa8be20864d09442d98c57 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 11 Feb 2018 15:39:20 +0000 Subject: [PATCH] Media: After [42693], update HTML4 markup in `img_caption_shortcode()` to avoid an empty ID attribute as well. Add a unit test for `aria-describedby` in `img_caption_shortcode()`. See #34595. git-svn-id: https://develop.svn.wordpress.org/trunk@42694 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 2 +- tests/phpunit/tests/media.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 68ac031298..55a8ad3704 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -1623,7 +1623,7 @@ function img_caption_shortcode( $attr, $content = null ) { esc_attr( $class ), str_replace( '%s

', + '

%s

', $atts['caption_id'], $atts['caption'] ) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 990166f91b..1fe2228aae 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -214,6 +214,21 @@ CAP; $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) ); } + /** + * @ticket 34595 + */ + function test_img_caption_shortcode_has_aria_describedby() { + $result = img_caption_shortcode( + array( + 'width' => 20, + 'id' => 'myId', + ), + $this->img_content . $this->html_content + ); + + $this->assertEquals( 1, preg_match_all( '/aria-describedby="caption-myId"/', $result, $_r ) ); + } + function test_add_remove_oembed_provider() { wp_oembed_add_provider( 'http://foo.bar/*', 'http://foo.bar/oembed' ); $this->assertTrue( wp_oembed_remove_provider( 'http://foo.bar/*' ) );