Make WordPress Core

Ticket #35367: 35367.diff

File 35367.diff, 6.8 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 7a41653..65842d0 100644
    function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) { 
    21632163 *     @type string $src      URL to the source of the audio file. Default empty.
    21642164 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
    21652165 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
    2166  *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default empty.
     2166 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
    21672167 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
    2168  *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
     2168 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%; visibility: hidden;'.
    21692169 * }
    21702170 * @param string $content Shortcode content.
    21712171 * @return string|void HTML content to display audio.
    function wp_audio_shortcode( $attr, $content = '' ) { 
    22002200                'src'      => '',
    22012201                'loop'     => '',
    22022202                'autoplay' => '',
    2203                 'preload'  => 'none'
     2203                'preload'  => 'none',
     2204                'class'    => 'wp-audio-shortcode',
     2205                'style'    => 'width: 100%; visibility: hidden;'
    22042206        );
    22052207        foreach ( $default_types as $type ) {
    22062208                $defaults_atts[$type] = '';
    function wp_audio_shortcode( $attr, $content = '' ) { 
    22622264         *
    22632265         * @param string $class CSS class or list of space-separated classes.
    22642266         */
     2267         $atts['class'] = apply_filters( 'wp_audio_shortcode_class', $atts['class'] );
     2268
    22652269        $html_atts = array(
    2266                 'class'    => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ),
     2270                'class'    => $atts['class'],
    22672271                'id'       => sprintf( 'audio-%d-%d', $post_id, $instance ),
    22682272                'loop'     => wp_validate_boolean( $atts['loop'] ),
    22692273                'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
    22702274                'preload'  => $atts['preload'],
    2271                 'style'    => 'width: 100%; visibility: hidden;',
     2275                'style'    => $atts['style'],
    22722276        );
    22732277
    22742278        // These ones should just be omitted altogether if they are blank
    function wp_video_shortcode( $attr, $content = '' ) { 
    24072411                'preload'  => 'metadata',
    24082412                'width'    => 640,
    24092413                'height'   => 360,
     2414                'class'    => 'wp-video-shortcode',
    24102415        );
    24112416
    24122417        foreach ( $default_types as $type ) {
    function wp_video_shortcode( $attr, $content = '' ) { 
    24962501         *
    24972502         * @param string $class CSS class or list of space-separated classes.
    24982503         */
     2504         $atts['class'] = apply_filters( 'wp_video_shortcode_class', $atts['class'] );
     2505
    24992506        $html_atts = array(
    2500                 'class'    => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
     2507                'class'    => $atts['class'],
    25012508                'id'       => sprintf( 'video-%d-%d', $post_id, $instance ),
    25022509                'width'    => absint( $atts['width'] ),
    25032510                'height'   => absint( $atts['height'] ),
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 5fa4fab..0ff06da 100644
    CAP; 
    118118                $this->assertEquals( 1, preg_match_all( "~wp-caption-text.*{$content_preg}~", $result, $_r ) );
    119119        }
    120120
     121        /**
     122         * @ticket 35367
     123         */
     124        function test_wp_audio_shortcode_with_empty_params() {
     125                $this->assertNull( wp_audio_shortcode( array() ) );
     126        }
     127
     128        /**
     129         * @ticket 35367
     130         */
     131        function test_wp_audio_shortcode_with_bad_attr() {
     132                $this->assertSame(
     133                        '<a class="wp-embedded-audio" href="https://example.com/foo.php">https://example.com/foo.php</a>',
     134                        wp_audio_shortcode( array(
     135                                'src' => 'https://example.com/foo.php',
     136                        ) )
     137                );
     138        }
     139
     140        /**
     141         * @ticket 35367
     142         */
     143        function test_wp_audio_shortcode_attributes() {
     144                $actual = wp_audio_shortcode( array(
     145                        'src' => 'https://example.com/foo.mp3',
     146                ) );
     147
     148                $this->assertContains( 'src="https://example.com/foo.mp3', $actual );
     149                $this->assertNotContains( 'loop', $actual );
     150                $this->assertNotContains( 'autoplay', $actual );
     151                $this->assertContains( 'preload="none"', $actual );
     152                $this->assertContains( 'class="wp-audio-shortcode"', $actual );
     153                $this->assertContains( 'style="width: 100%; visibility: hidden;"', $actual );
     154
     155                $actual = wp_audio_shortcode( array(
     156                        'src'      => 'https://example.com/foo.mp3',
     157                        'loop'     => true,
     158                        'autoplay' => true,
     159                        'preload'  => true,
     160                        'class'    => 'foobar',
     161                        'style'    => 'padding:0;',
     162                ) );
     163
     164                $this->assertContains( 'src="https://example.com/foo.mp3', $actual );
     165                $this->assertContains( 'loop="1"', $actual );
     166                $this->assertContains( 'autoplay="1"', $actual );
     167                $this->assertContains( 'preload="1"', $actual );
     168                $this->assertContains( 'class="foobar"', $actual );
     169                $this->assertContains( 'style="padding:0;"', $actual );
     170        }
     171
     172        /**
     173         * @ticket 35367
     174         */
     175        function test_wp_video_shortcode_with_empty_params() {
     176                $this->assertNull( wp_video_shortcode( array() ) );
     177        }
     178
     179        /**
     180         * @ticket 35367
     181         */
     182        function test_wp_video_shortcode_with_bad_attr() {
     183                $this->assertSame(
     184                        '<a class="wp-embedded-video" href="https://example.com/foo.php">https://example.com/foo.php</a>',
     185                        wp_video_shortcode( array(
     186                                'src' => 'https://example.com/foo.php',
     187                        ) )
     188                );
     189        }
     190
     191        /**
     192         * @ticket 35367
     193         */
     194        function test_wp_video_shortcode_attributes() {
     195                $actual = wp_video_shortcode( array(
     196                        'src' => 'https://example.com/foo.mp4',
     197                ) );
     198
     199                $this->assertContains( 'src="https://example.com/foo.mp4', $actual );
     200                $this->assertNotContains( 'loop', $actual );
     201                $this->assertNotContains( 'autoplay', $actual );
     202                $this->assertContains( 'preload="metadata"', $actual );
     203                $this->assertContains( 'width="640"', $actual );
     204                $this->assertContains( 'height="360"', $actual );
     205                $this->assertContains( 'class="wp-video-shortcode"', $actual );
     206
     207                $actual = wp_video_shortcode( array(
     208                        'src'      => 'https://example.com/foo.mp4',
     209                        'poster'      => 'https://example.com/foo.png',
     210                        'loop'     => true,
     211                        'autoplay' => true,
     212                        'preload'  => true,
     213                        'width'    => 123,
     214                        'height'   => 456,
     215                        'class'    => 'foobar',
     216                ) );
     217
     218                $this->assertContains( 'src="https://example.com/foo.mp4', $actual );
     219                $this->assertContains( 'poster="https://example.com/foo.png', $actual );
     220                $this->assertContains( 'loop="1"', $actual );
     221                $this->assertContains( 'autoplay="1"', $actual );
     222                $this->assertContains( 'preload="1"', $actual );
     223                $this->assertContains( 'width="123"', $actual );
     224                $this->assertContains( 'height="456"', $actual );
     225                $this->assertContains( 'class="foobar"', $actual );
     226        }
     227
    121228        function test_add_remove_oembed_provider() {
    122229                wp_oembed_add_provider( 'http://foo.bar/*', 'http://foo.bar/oembed' );
    123230                $this->assertTrue( wp_oembed_remove_provider( 'http://foo.bar/*' ) );