Make WordPress Core


Ignore:
Timestamp:
02/27/2015 04:11:00 PM (9 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r31239 r31574  
    379379CONTENT;
    380380
    381         $types = array( 'audio', 'video', 'object', 'embed', 'iframe' );
     381        $types = array( 'object', 'embed', 'iframe', 'audio', 'video' );
    382382        $contents = array_values( compact( $types ) );
    383383
     
    399399        $matches = get_media_embedded_in_content( $content, $types );
    400400        $this->assertEquals( $contents, $matches );
     401    }
     402
     403    function test_get_media_embedded_in_content_order() {
     404        $audio =<<<AUDIO
     405<audio preload="none">
     406    <source />
     407</audio>
     408AUDIO;
     409        $video =<<<VIDEO
     410<video preload="none">
     411    <source />
     412</video>
     413VIDEO;
     414        $content = $audio . $video;
     415
     416        $matches1 = get_media_embedded_in_content( $content, array( 'audio', 'video' ) );
     417        $this->assertEquals( array( $audio, $video ), $matches1 );
     418
     419        $reversed = $video . $audio;
     420        $matches2 = get_media_embedded_in_content( $reversed, array( 'audio', 'video' ) );
     421        $this->assertEquals( array( $video, $audio ), $matches2 );
    401422    }
    402423
Note: See TracChangeset for help on using the changeset viewer.