Make WordPress Core

Changeset 36240


Ignore:
Timestamp:
01/09/2016 02:17:02 PM (9 years ago)
Author:
swissspidy
Message:

Media: Fix wp_audio_shortcode and wp_video_shortcode attributes handling.

Although documented, the class and style attributes were simply ignored.
Adds unit tests.

Fixes #35367.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r36121 r36240  
    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.
     
    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 ) {
     
    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
     
    24082412        'width'    => 640,
    24092413        'height'   => 360,
     2414        'class'    => 'wp-video-shortcode',
    24102415    );
    24112416
     
    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'] ),
  • trunk/tests/phpunit/tests/media.php

    r36121 r36240  
    416416        $matches2 = get_media_embedded_in_content( $reversed, array( 'audio', 'video' ) );
    417417        $this->assertEquals( array( $video, $audio ), $matches2 );
     418    }
     419
     420    /**
     421     * @ticket 35367
     422     */
     423    function test_wp_audio_shortcode_with_empty_params() {
     424        $this->assertNull( wp_audio_shortcode( array() ) );
     425    }
     426
     427    /**
     428     * @ticket 35367
     429     */
     430    function test_wp_audio_shortcode_with_bad_attr() {
     431        $this->assertSame(
     432            '<a class="wp-embedded-audio" href="https://example.com/foo.php">https://example.com/foo.php</a>',
     433            wp_audio_shortcode( array(
     434                'src' => 'https://example.com/foo.php',
     435            ) )
     436        );
     437    }
     438
     439    /**
     440     * @ticket 35367
     441     */
     442    function test_wp_audio_shortcode_attributes() {
     443        $actual = wp_audio_shortcode( array(
     444            'src' => 'https://example.com/foo.mp3',
     445        ) );
     446
     447        $this->assertContains( 'src="https://example.com/foo.mp3', $actual );
     448        $this->assertNotContains( 'loop', $actual );
     449        $this->assertNotContains( 'autoplay', $actual );
     450        $this->assertContains( 'preload="none"', $actual );
     451        $this->assertContains( 'class="wp-audio-shortcode"', $actual );
     452        $this->assertContains( 'style="width: 100%; visibility: hidden;"', $actual );
     453
     454        $actual = wp_audio_shortcode( array(
     455            'src'      => 'https://example.com/foo.mp3',
     456            'loop'     => true,
     457            'autoplay' => true,
     458            'preload'  => true,
     459            'class'    => 'foobar',
     460            'style'    => 'padding:0;',
     461        ) );
     462
     463        $this->assertContains( 'src="https://example.com/foo.mp3', $actual );
     464        $this->assertContains( 'loop="1"', $actual );
     465        $this->assertContains( 'autoplay="1"', $actual );
     466        $this->assertContains( 'preload="1"', $actual );
     467        $this->assertContains( 'class="foobar"', $actual );
     468        $this->assertContains( 'style="padding:0;"', $actual );
     469    }
     470
     471    /**
     472     * @ticket  35367
     473     * @depends test_video_shortcode_body
     474     */
     475    function test_wp_video_shortcode_with_empty_params() {
     476        $this->assertNull( wp_video_shortcode( array() ) );
     477    }
     478
     479    /**
     480     * @ticket  35367
     481     * @depends test_video_shortcode_body
     482     */
     483    function test_wp_video_shortcode_with_bad_attr() {
     484        $this->assertSame(
     485            '<a class="wp-embedded-video" href="https://example.com/foo.php">https://example.com/foo.php</a>',
     486            wp_video_shortcode( array(
     487                'src' => 'https://example.com/foo.php',
     488            ) )
     489        );
     490    }
     491
     492    /**
     493     * @ticket  35367
     494     * @depends test_video_shortcode_body
     495     */
     496    function test_wp_video_shortcode_attributes() {
     497        $actual = wp_video_shortcode( array(
     498            'src' => 'https://example.com/foo.mp4',
     499        ) );
     500
     501        $this->assertContains( 'src="https://example.com/foo.mp4', $actual );
     502        $this->assertNotContains( 'loop', $actual );
     503        $this->assertNotContains( 'autoplay', $actual );
     504        $this->assertContains( 'preload="metadata"', $actual );
     505        $this->assertContains( 'width="640"', $actual );
     506        $this->assertContains( 'height="360"', $actual );
     507        $this->assertContains( 'class="wp-video-shortcode"', $actual );
     508
     509        $actual = wp_video_shortcode( array(
     510            'src'      => 'https://example.com/foo.mp4',
     511            'poster'   => 'https://example.com/foo.png',
     512            'loop'     => true,
     513            'autoplay' => true,
     514            'preload'  => true,
     515            'width'    => 123,
     516            'height'   => 456,
     517            'class'    => 'foobar',
     518        ) );
     519
     520        $this->assertContains( 'src="https://example.com/foo.mp4', $actual );
     521        $this->assertContains( 'poster="https://example.com/foo.png', $actual );
     522        $this->assertContains( 'loop="1"', $actual );
     523        $this->assertContains( 'autoplay="1"', $actual );
     524        $this->assertContains( 'preload="1"', $actual );
     525        $this->assertContains( 'width="123"', $actual );
     526        $this->assertContains( 'height="456"', $actual );
     527        $this->assertContains( 'class="foobar"', $actual );
    418528    }
    419529
Note: See TracChangeset for help on using the changeset viewer.