Make WordPress Core

Ticket #26675: media.php_unit-test.patch

File media.php_unit-test.patch, 3.5 KB (added by kopepasah, 11 years ago)
  • tests/phpunit/tests/media.php

     
    284284        }
    285285
    286286        function test_get_media_embedded_in_content() {
    287                 $object =<<<OBJ
     287                $object[0] =<<<OBJ
    288288<object src="this" data="that">
    289289        <param name="value"/>
    290290</object>
    291291OBJ;
    292                 $embed =<<<EMBED
     292                $object[1] =<<<OBJ
     293<object src="that" data="this">
     294        <param name="value"/>
     295</object>
     296OBJ;
     297                $embed[0] =<<<EMBED
    293298<embed src="something.mp4"/>
    294299EMBED;
    295                 $iframe =<<<IFRAME
    296 <iframe src="youtube.com" width="7000" />
     300                $embed[1] =<<<EMBED
     301<embed src="anotherthing.mp4"/>
     302EMBED;
     303                $iframe[0] =<<<IFRAME
     304<iframe src="youtube.com" width="7000"></iframe>
    297305IFRAME;
    298                 $audio =<<<AUDIO
     306                $iframe[1] =<<<IFRAME
     307<iframe src="vimeo.com" width="7000"></iframe>
     308IFRAME;
     309                $audio[0] =<<<AUDIO
    299310<audio preload="none">
    300311        <source />
    301312</audio>
    302313AUDIO;
    303                 $video =<<<VIDEO
     314                $audio[1] =<<<AUDIO
     315<audio preload="none">
     316        <source />
     317</audio>
     318AUDIO;
     319                $video[0] =<<<VIDEO
    304320<video preload="none">
    305321        <source />
    306322</video>
    307323VIDEO;
     324                $video[1] =<<<VIDEO
     325<video preload="none">
     326        <source />
     327</video>
     328VIDEO;
     329                $img[0] =<<<IMG
     330<img src="kittens.jpg"/>
     331IMG;
     332                $img[1] =<<<IMG
     333<img src="cats.png"/>
     334IMG;
    308335
    309336                $content =<<<CONTENT
    310337This is a comment
    311 $object
     338$object[0]
    312339
    313340This is a comment
    314 $embed
     341$img[0]
    315342
    316343This is a comment
    317 $iframe
     344$iframe[0]
    318345
    319346This is a comment
    320 $audio
     347$embed[0]
    321348
    322349This is a comment
    323 $video
     350$video[0]
    324351
    325352This is a comment
     353$iframe[1]
     354
     355This is a comment
     356$audio[0]
     357
     358This is a comment
     359$embed[1]
     360
     361This is a comment
     362$video[1]
     363
     364This is a comment
     365$img[1]
     366
     367This is a comment
     368$audio[1]
     369
     370This is a comment
     371$object[1]
     372
     373This is a comment
    326374CONTENT;
    327375
    328                 $types = array( 'audio', 'video', 'object', 'embed', 'iframe' );
    329                 $contents = array_values( compact( $types ) );
     376                $types = array( 'img', 'audio', 'video', 'object', 'embed', 'iframe' );
     377                $contents = array( $img[0], $img[1], $audio[0], $audio[1], $video[0], $video[1], $object[0], $object[1], $embed[0], $embed[1], $iframe[0], $iframe[1] );
     378                $source_contents = array( $object[0], $img[0], $iframe[0], $embed[0], $video[0], $iframe[1], $audio[0], $embed[1], $video[1], $img[1], $audio[1], $object[1] );
    330379
     380                $matches = get_media_embedded_in_content( $content, 'img' );
     381                $this->assertEquals( $img, $matches );
     382
    331383                $matches = get_media_embedded_in_content( $content, 'audio' );
    332                 $this->assertEquals( array( $audio ), $matches );
     384                $this->assertEquals( $audio, $matches );
    333385
    334386                $matches = get_media_embedded_in_content( $content, 'video' );
    335                 $this->assertEquals( array( $video ), $matches );
     387                $this->assertEquals( $video, $matches );
    336388
    337389                $matches = get_media_embedded_in_content( $content, 'object' );
    338                 $this->assertEquals( array( $object ), $matches );
     390                $this->assertEquals( $object, $matches );
    339391
    340392                $matches = get_media_embedded_in_content( $content, 'embed' );
    341                 $this->assertEquals( array( $embed ), $matches );
     393                $this->assertEquals( $embed, $matches );
    342394
    343395                $matches = get_media_embedded_in_content( $content, 'iframe' );
    344                 $this->assertEquals( array( $iframe ), $matches );
     396                $this->assertEquals( $iframe, $matches );
    345397
    346398                $matches = get_media_embedded_in_content( $content, $types );
    347399                $this->assertEquals( $contents, $matches );
     400
     401                $matches = get_media_embedded_in_content( $content, $types, 'source' );
     402                $this->assertEquals( $source_contents, $matches );
    348403        }
    349 }
     404}
     405 No newline at end of file