Make WordPress Core


Ignore:
Timestamp:
02/05/2014 12:45:53 AM (11 years ago)
Author:
azaozz
Message:

Consolidate handling of <object>, <audio> and <video> in wpautop() and add unit tests for them. Part props wonderboymusic, see #26864

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/Autop.php

    r25002 r27094  
    9999        $this->assertEquals( "<p>$str</p>", trim( wpautop( $str ) ) );
    100100    }
     101
     102    /**
     103     * wpautop() Should not add <p> and <br/> around <source> and <track>
     104     *
     105     * @ticket 26864
     106     */
     107    public function test_source_track_elements() {
     108        $content = "Paragraph one.\n\n" .
     109            '<video class="wp-video-shortcode" id="video-0-1" width="640" height="360" preload="metadata" controls="controls">
     110                <source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4" />
     111                <!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
     112                <source type="video/webm" src="myvideo.webm" />
     113                <!-- Ogg/Vorbis for older Firefox and Opera versions -->
     114                <source type="video/ogg" src="myvideo.ogv" />
     115                <!-- Optional: Add subtitles for each language -->
     116                <track kind="subtitles" src="subtitles.srt" srclang="en" />
     117                <!-- Optional: Add chapters -->
     118                <track kind="chapters" src="chapters.srt" srclang="en" />
     119                <a href="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4">http://domain.tld/wp-content/uploads/2013/12/xyz.mp4</a>
     120            </video>' .
     121            "\n\nParagraph two.";
     122
     123        $content2 = "Paragraph one.\n\n" .
     124            '<video class="wp-video-shortcode" id="video-0-1" width="640" height="360" preload="metadata" controls="controls">
     125
     126            <source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4" />
     127
     128            <!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
     129            <source type="video/webm" src="myvideo.webm" />
     130
     131            <!-- Ogg/Vorbis for older Firefox and Opera versions -->
     132            <source type="video/ogg" src="myvideo.ogv" />
     133
     134            <!-- Optional: Add subtitles for each language -->
     135            <track kind="subtitles" src="subtitles.srt" srclang="en" />
     136
     137            <!-- Optional: Add chapters -->
     138            <track kind="chapters" src="chapters.srt" srclang="en" />
     139
     140            <a href="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4">http://domain.tld/wp-content/uploads/2013/12/xyz.mp4</a>
     141
     142            </video>' .
     143            "\n\nParagraph two.";
     144
     145        $expected = "<p>Paragraph one.</p>\n" . // line breaks only after <p>
     146            '<p><video class="wp-video-shortcode" id="video-0-1" width="640" height="360" preload="metadata" controls="controls">' .
     147            '<source type="video/mp4" src="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4" />' .
     148            '<!-- WebM/VP8 for Firefox4, Opera, and Chrome -->' .
     149            '<source type="video/webm" src="myvideo.webm" />' .
     150            '<!-- Ogg/Vorbis for older Firefox and Opera versions -->' .
     151            '<source type="video/ogg" src="myvideo.ogv" />' .
     152            '<!-- Optional: Add subtitles for each language -->' .
     153            '<track kind="subtitles" src="subtitles.srt" srclang="en" />' .
     154            '<!-- Optional: Add chapters -->' .
     155            '<track kind="chapters" src="chapters.srt" srclang="en" />' .
     156            '<a href="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4">' .
     157            "http://domain.tld/wp-content/uploads/2013/12/xyz.mp4</a></video></p>\n" .
     158            '<p>Paragraph two.</p>';
     159
     160        // When running the content through wpautop() from wp_richedit_pre()
     161        $shortcode_content = "Paragraph one.\n\n" .
     162            '[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]
     163            <!-- WebM/VP8 for Firefox4, Opera, and Chrome -->
     164            <source type="video/webm" src="myvideo.webm" />
     165            <!-- Ogg/Vorbis for older Firefox and Opera versions -->
     166            <source type="video/ogg" src="myvideo.ogv" />
     167            <!-- Optional: Add subtitles for each language -->
     168            <track kind="subtitles" src="subtitles.srt" srclang="en" />
     169            <!-- Optional: Add chapters -->
     170            <track kind="chapters" src="chapters.srt" srclang="en" />
     171            [/video]' .
     172            "\n\nParagraph two.";
     173
     174        $shortcode_expected = "<p>Paragraph one.</p>\n" . // line breaks only after <p>
     175            '<p>[video width="720" height="480" mp4="http://domain.tld/wp-content/uploads/2013/12/xyz.mp4"]' .
     176            '<!-- WebM/VP8 for Firefox4, Opera, and Chrome --><source type="video/webm" src="myvideo.webm" />' .
     177            '<!-- Ogg/Vorbis for older Firefox and Opera versions --><source type="video/ogg" src="myvideo.ogv" />' .
     178            '<!-- Optional: Add subtitles for each language --><track kind="subtitles" src="subtitles.srt" srclang="en" />' .
     179            '<!-- Optional: Add chapters --><track kind="chapters" src="chapters.srt" srclang="en" />' .
     180            "[/video]</p>\n" .
     181            '<p>Paragraph two.</p>';
     182
     183        $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     184        $this->assertEquals( $expected, trim( wpautop( $content2 ) ) );
     185        $this->assertEquals( $shortcode_expected, trim( wpautop( $shortcode_content ) ) );
     186    }
     187
     188    /**
     189     * wpautop() Should not add <p> and <br/> around <param> and <embed>
     190     *
     191     * @ticket 26864
     192     */
     193    public function test_param_embed_elements() {
     194        $content1 = '
     195Paragraph one.
     196
     197<object width="400" height="224" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
     198    <param name="src" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />
     199    <param name="allowfullscreen" value="true" />
     200    <param name="allowscriptaccess" value="always" />
     201    <param name="overstretch" value="true" />
     202    <param name="flashvars" value="isDynamicSeeking=true" />
     203
     204    <embed width="400" height="224" type="application/x-shockwave-flash" src="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" wmode="direct" seamlesstabbing="true" allowfullscreen="true" overstretch="true" flashvars="isDynamicSeeking=true" />
     205</object>
     206
     207Paragraph two.';
     208
     209        $expected1 = "<p>Paragraph one.</p>\n" . // line breaks only after <p>
     210            '<p><object width="400" height="224" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">' .
     211            '<param name="src" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />' .
     212            '<param name="allowfullscreen" value="true" />' .
     213            '<param name="allowscriptaccess" value="always" />' .
     214            '<param name="overstretch" value="true" />' .
     215            '<param name="flashvars" value="isDynamicSeeking=true" />' .
     216            '<embed width="400" height="224" type="application/x-shockwave-flash" src="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" wmode="direct" seamlesstabbing="true" allowfullscreen="true" overstretch="true" flashvars="isDynamicSeeking=true" />' .
     217            "</object></p>\n" .
     218            '<p>Paragraph two.</p>';
     219
     220        $content2 = '
     221Paragraph one.
     222
     223<div class="video-player" id="x-video-0">
     224<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="360" id="video-0" standby="Standby text">
     225  <param name="movie" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />
     226  <param name="quality" value="best" />
     227
     228  <param name="seamlesstabbing" value="true" />
     229  <param name="allowfullscreen" value="true" />
     230  <param name="allowscriptaccess" value="always" />
     231  <param name="overstretch" value="true" />
     232
     233  <!--[if !IE]--><object type="application/x-shockwave-flash" data="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" width="640" height="360" standby="Standby text">
     234    <param name="quality" value="best" />
     235
     236    <param name="seamlesstabbing" value="true" />
     237    <param name="allowfullscreen" value="true" />
     238    <param name="allowscriptaccess" value="always" />
     239    <param name="overstretch" value="true" />
     240  </object><!--<![endif]-->
     241</object></div>
     242
     243Paragraph two.';
     244
     245        $expected2 = "<p>Paragraph one.</p>\n" . // line breaks only after block tags
     246            '<div class="video-player" id="x-video-0">' . "\n" .
     247            '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="360" id="video-0" standby="Standby text">' .
     248            '<param name="movie" value="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" />' .
     249            '<param name="quality" value="best" />' .
     250            '<param name="seamlesstabbing" value="true" />' .
     251            '<param name="allowfullscreen" value="true" />' .
     252            '<param name="allowscriptaccess" value="always" />' .
     253            '<param name="overstretch" value="true" />' .
     254            '<!--[if !IE]--><object type="application/x-shockwave-flash" data="http://domain.tld/wp-content/uploads/2013/12/xyz.swf" width="640" height="360" standby="Standby text">' .
     255            '<param name="quality" value="best" />' .
     256            '<param name="seamlesstabbing" value="true" />' .
     257            '<param name="allowfullscreen" value="true" />' .
     258            '<param name="allowscriptaccess" value="always" />' .
     259            '<param name="overstretch" value="true" /></object><!--<![endif]-->' .
     260            "</object></div>\n" .
     261            '<p>Paragraph two.</p>';
     262
     263        $this->assertEquals( $expected1, trim( wpautop( $content1 ) ) );
     264        $this->assertEquals( $expected2, trim( wpautop( $content2 ) ) );
     265    }
    101266}
Note: See TracChangeset for help on using the changeset viewer.