Improve get_media_embedded_in_content() so that it returns the media it finds in the same order that it appears in the content.

Adds unit test, updates another.

Props kopepasah.
See #26675.


git-svn-id: https://develop.svn.wordpress.org/trunk@31574 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-02-27 16:11:00 +00:00
parent cbb528de0f
commit 65c58832cb
2 changed files with 33 additions and 6 deletions
+22 -1
View File
@@ -378,7 +378,7 @@ $video
This is a comment
CONTENT;
$types = array( 'audio', 'video', 'object', 'embed', 'iframe' );
$types = array( 'object', 'embed', 'iframe', 'audio', 'video' );
$contents = array_values( compact( $types ) );
$matches = get_media_embedded_in_content( $content, 'audio' );
@@ -400,6 +400,27 @@ CONTENT;
$this->assertEquals( $contents, $matches );
}
function test_get_media_embedded_in_content_order() {
$audio =<<<AUDIO
<audio preload="none">
<source />
</audio>
AUDIO;
$video =<<<VIDEO
<video preload="none">
<source />
</video>
VIDEO;
$content = $audio . $video;
$matches1 = get_media_embedded_in_content( $content, array( 'audio', 'video' ) );
$this->assertEquals( array( $audio, $video ), $matches1 );
$reversed = $video . $audio;
$matches2 = get_media_embedded_in_content( $reversed, array( 'audio', 'video' ) );
$this->assertEquals( array( $video, $audio ), $matches2 );
}
/**
* Test [video] shortcode processing
*