WordPress.org

Make WordPress Core

Changeset 36649


Ignore:
Timestamp:
02/23/2016 08:40:43 PM (2 years ago)
Author:
ocean90
Message:

Styles: Clarify the allowed values for the $media parameter of wp_register_style()/wp_enqueue_style().

Adds unit test.

Fixes #35921.

Location:
trunk
Files:
2 edited

Legend:

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

    r36074 r36649  
    107107 *                            is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'.
    108108 * @param string      $media  Optional. The media for which this stylesheet has been defined.
    109  *                            Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
    110  *                            'screen', 'tty', or 'tv'.
     109 *                            Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
     110 *                            '(orientation: portrait)' and '(max-width: 640px)'.
     111 *
    111112 * @return bool Whether the style has been registered. True on success, false on failure.
    112113 */
     
    150151 *                            should be included if a version number is available and makes sense for the stylesheet.
    151152 * @param string      $media  Optional. The media for which this stylesheet has been defined.
    152  *                            Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
    153  *                            'screen', 'tty', or 'tv'.
     153 *                            Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
     154 *                            '(orientation: portrait)' and '(max-width: 640px)'.
    154155 */
    155156function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r36550 r36649  
    262262    }
    263263
     264    /**
     265     * @ticket 35921
     266     * @dataProvider data_styles_with_media
     267     */
     268    function test_wp_enqueue_style_with_media( $expected, $media ) {
     269        wp_enqueue_style( 'handle', 'http://example.com', array(), 1, $media );
     270        $this->assertContains( $expected, get_echo( 'wp_print_styles' ) );
     271    }
     272
     273    function data_styles_with_media() {
     274        return array(
     275            array(
     276                "media='all'",
     277                'all'
     278            ),
     279            array(
     280                "media='(orientation: portrait)'",
     281                '(orientation: portrait)'
     282            ),
     283            array(
     284                "media='(max-width: 640px)'",
     285                '(max-width: 640px)'
     286            ),
     287            array(
     288                "media='print and (min-width: 25cm)'",
     289                'print and (min-width: 25cm)'
     290            ),
     291            array(
     292                "media='screen and (color), projection and (color)'",
     293                'screen and (color), projection and (color)'
     294            ),
     295            array(
     296                "media='not screen and (color)'",
     297                'not screen and (color)'
     298            ),
     299        );
     300    }
    264301}
Note: See TracChangeset for help on using the changeset viewer.