WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/31/2015 01:45:34 AM (4 years ago)
Author:
azaozz
Message:

Backport r33469 and r33470 to 3.7.
See #33106.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7/tests/phpunit/tests/media.php

    r25409 r33525  
    347347        $this->assertEquals( $contents, $matches );
    348348    }
     349   
     350    /**
     351     * @ticket 33016
     352     */
     353    function test_multiline_cdata() {
     354        global $wp_embed;
     355
     356        $content = <<<EOF
     357<script>// <![CDATA[
     358_my_function('data');
     359// ]]>
     360</script>
     361EOF;
     362
     363        $result = $wp_embed->autoembed( $content );
     364        $this->assertEquals( $content, $result );
     365    }
     366
     367    /**
     368     * @ticket 33016
     369     */
     370    function test_multiline_comment() {
     371        global $wp_embed;
     372
     373        $content = <<<EOF
     374<script><!--
     375my_function();
     376// --> </script>
     377EOF;
     378
     379        $result = $wp_embed->autoembed( $content );
     380        $this->assertEquals( $content, $result );
     381    }
     382
     383
     384    /**
     385     * @ticket 33016
     386     */
     387    function test_multiline_comment_with_embeds() {
     388        $content = <<<EOF
     389Start.
     390[embed]http://www.youtube.com/embed/TEST01YRHA0[/embed]
     391<script><!--
     392my_function();
     393// --> </script>
     394http://www.youtube.com/embed/TEST02YRHA0
     395[embed]http://www.example.com/embed/TEST03YRHA0[/embed]
     396http://www.example.com/embed/TEST04YRHA0
     397Stop.
     398EOF;
     399
     400        $expected = <<<EOF
     401<p>Start.<br />
     402<a href="http://www.youtube.com/embed/TEST01YRHA0">http://www.youtube.com/embed/TEST01YRHA0</a><br />
     403<script><!--
     404my_function();
     405// --> </script></p>
     406<p>http://www.youtube.com/embed/TEST02YRHA0</p>
     407<p><a href="http://www.example.com/embed/TEST03YRHA0">http://www.example.com/embed/TEST03YRHA0</a></p>
     408<p>http://www.example.com/embed/TEST04YRHA0</p>
     409<p>Stop.</p>
     410
     411EOF;
     412
     413        $result = apply_filters( 'the_content', $content );
     414        $this->assertEquals( $expected, $result );
     415    }
     416
     417    /**
     418     * @ticket 33016
     419     */
     420    function filter_wp_embed_shortcode_custom( $content, $url ) {
     421        if ( 'https://www.example.com/?video=1' == $url ) {
     422            $content = '@embed URL was replaced@';
     423        }
     424        return $content;
     425    }
     426
     427    /**
     428     * @ticket 33016
     429     */
     430    function test_oembed_explicit_media_link() {
     431        global $wp_embed;
     432        add_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 2 );
     433
     434        $content = <<<EOF
     435https://www.example.com/?video=1
     436EOF;
     437
     438        $expected = <<<EOF
     439
     440@embed URL was replaced@
     441
     442EOF;
     443
     444        $result = $wp_embed->autoembed( $content );
     445        $this->assertEquals( $expected, $result );
     446
     447        $content = <<<EOF
     448<a href="https://www.example.com/?video=1">https://www.example.com/?video=1</a>
     449<script>// <![CDATA[
     450_my_function('data');
     451myvar = 'Hello world
     452https://www.example.com/?video=1
     453do not break this';
     454// ]]>
     455</script>
     456EOF;
     457
     458        $result = $wp_embed->autoembed( $content );
     459        $this->assertEquals( $content, $result );
     460
     461        remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
     462    }
     463
    349464}
Note: See TracChangeset for help on using the changeset viewer.