Make WordPress Core


Ignore:
Timestamp:
07/31/2015 01:42:39 AM (11 years ago)
Author:
azaozz
Message:

Backport r33469 and r33470 to 4.1.
See #33106.

File:
1 edited

Legend:

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

    r33374 r33521  
    468468        }
    469469
     470        /**
     471         * @ticket 33016
     472         */
     473        function test_multiline_cdata() {
     474                global $wp_embed;
     475
     476                $content = <<<EOF
     477<script>// <![CDATA[
     478_my_function('data');
     479// ]]>
     480</script>
     481EOF;
     482
     483                $result = $wp_embed->autoembed( $content );
     484                $this->assertEquals( $content, $result );
     485        }
     486
     487        /**
     488         * @ticket 33016
     489         */
     490        function test_multiline_comment() {
     491                global $wp_embed;
     492
     493                $content = <<<EOF
     494<script><!--
     495my_function();
     496// --> </script>
     497EOF;
     498
     499                $result = $wp_embed->autoembed( $content );
     500                $this->assertEquals( $content, $result );
     501        }
     502
     503
     504        /**
     505         * @ticket 33016
     506         */
     507        function test_multiline_comment_with_embeds() {
     508                $content = <<<EOF
     509Start.
     510[embed]http://www.youtube.com/embed/TEST01YRHA0[/embed]
     511<script><!--
     512my_function();
     513// --> </script>
     514http://www.youtube.com/embed/TEST02YRHA0
     515[embed]http://www.example.com/embed/TEST03YRHA0[/embed]
     516http://www.example.com/embed/TEST04YRHA0
     517Stop.
     518EOF;
     519
     520                $expected = <<<EOF
     521<p>Start.</p>
     522<p>https://youtube.com/watch?v=TEST01YRHA0</p>
     523<p><script><!--
     524my_function();
     525// --> </script></p>
     526<p>https://youtube.com/watch?v=TEST02YRHA0</p>
     527<p><a href="http://www.example.com/embed/TEST03YRHA0">http://www.example.com/embed/TEST03YRHA0</a></p>
     528<p>http://www.example.com/embed/TEST04YRHA0</p>
     529<p>Stop.</p>
     530
     531EOF;
     532
     533                $result = apply_filters( 'the_content', $content );
     534                $this->assertEquals( $expected, $result );
     535        }
     536
     537        /**
     538         * @ticket 33016
     539         */
     540        function filter_wp_embed_shortcode_custom( $content, $url ) {
     541                if ( 'https://www.example.com/?video=1' == $url ) {
     542                        $content = '@embed URL was replaced@';
     543                }
     544                return $content;
     545        }
     546
     547        /**
     548         * @ticket 33016
     549         */
     550        function test_oembed_explicit_media_link() {
     551                global $wp_embed;
     552                add_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10, 2 );
     553
     554                $content = <<<EOF
     555https://www.example.com/?video=1
     556EOF;
     557
     558                $expected = <<<EOF
     559
     560@embed URL was replaced@
     561
     562EOF;
     563
     564                $result = $wp_embed->autoembed( $content );
     565                $this->assertEquals( $expected, $result );
     566
     567                $content = <<<EOF
     568<a href="https://www.example.com/?video=1">https://www.example.com/?video=1</a>
     569<script>// <![CDATA[
     570_my_function('data');
     571myvar = 'Hello world
     572https://www.example.com/?video=1
     573do not break this';
     574// ]]>
     575</script>
     576EOF;
     577
     578                $result = $wp_embed->autoembed( $content );
     579                $this->assertEquals( $content, $result );
     580
     581                remove_filter( 'embed_maybe_make_link', array( $this, 'filter_wp_embed_shortcode_custom' ), 10 );
     582        }
    470583}
Note: See TracChangeset for help on using the changeset viewer.