Make WordPress Core


Ignore:
Timestamp:
07/30/2015 07:40:33 PM (10 years ago)
Author:
azaozz
Message:

Backport r33469 and r33470 to 4.2.
See #33106.

File:
1 edited

Legend:

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

    r32365 r33518  
    560560    }
    561561
     562    /**
     563     * @ticket 33016
     564     */
     565    function test_multiline_cdata() {
     566        global $wp_embed;
     567
     568        $content = <<<EOF
     569<script>// <![CDATA[
     570_my_function('data');
     571// ]]>
     572</script>
     573EOF;
     574
     575        $result = $wp_embed->autoembed( $content );
     576        $this->assertEquals( $content, $result );
     577    }
     578
     579    /**
     580     * @ticket 33016
     581     */
     582    function test_multiline_comment() {
     583        global $wp_embed;
     584
     585        $content = <<<EOF
     586<script><!--
     587my_function();
     588// --> </script>
     589EOF;
     590
     591        $result = $wp_embed->autoembed( $content );
     592        $this->assertEquals( $content, $result );
     593    }
     594
     595
     596    /**
     597     * @ticket 33016
     598     */
     599    function test_multiline_comment_with_embeds() {
     600        $content = <<<EOF
     601Start.
     602[embed]http://www.youtube.com/embed/TEST01YRHA0[/embed]
     603<script><!--
     604my_function();
     605// --> </script>
     606http://www.youtube.com/embed/TEST02YRHA0
     607[embed]http://www.example.com/embed/TEST03YRHA0[/embed]
     608http://www.example.com/embed/TEST04YRHA0
     609Stop.
     610EOF;
     611
     612        $expected = <<<EOF
     613<p>Start.<br />
     614https://youtube.com/watch?v=TEST01YRHA0<br />
     615<script><!--
     616my_function();
     617// --> </script><br />
     618https://youtube.com/watch?v=TEST02YRHA0<br />
     619<a href="http://www.example.com/embed/TEST03YRHA0">http://www.example.com/embed/TEST03YRHA0</a><br />
     620http://www.example.com/embed/TEST04YRHA0<br />
     621Stop.</p>
     622
     623EOF;
     624
     625        $result = apply_filters( 'the_content', $content );
     626        $this->assertEquals( $expected, $result );
     627    }
     628
     629    /**
     630     * @ticket 33016
     631     */
     632    function filter_wp_embed_shortcode_custom( $content, $url ) {
     633        if ( 'https://www.example.com/?video=1' == $url ) {
     634            $content = '@embed URL was replaced@';
     635        }
     636        return $content;
     637    }
     638
     639    /**
     640     * @ticket 33016
     641     */
     642    function test_oembed_explicit_media_link() {
     643        global $wp_embed;
     644        add_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 2 );
     645
     646        $content = <<<EOF
     647https://www.example.com/?video=1
     648EOF;
     649
     650        $expected = <<<EOF
     651@embed URL was replaced@
     652EOF;
     653
     654        $result = $wp_embed->autoembed( $content );
     655        $this->assertEquals( $expected, $result );
     656
     657        $content = <<<EOF
     658<a href="https://www.example.com/?video=1">https://www.example.com/?video=1</a>
     659<script>// <![CDATA[
     660_my_function('data');
     661myvar = 'Hello world
     662https://www.example.com/?video=1
     663do not break this';
     664// ]]>
     665</script>
     666EOF;
     667
     668        $result = $wp_embed->autoembed( $content );
     669        $this->assertEquals( $content, $result );
     670
     671        remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
     672    }
    562673}
Note: See TracChangeset for help on using the changeset viewer.