Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/styles.php

    r36649 r42343  
    99    function setUp() {
    1010        parent::setUp();
    11         if ( empty( $GLOBALS['wp_styles'] ) )
     11        if ( empty( $GLOBALS['wp_styles'] ) ) {
    1212            $GLOBALS['wp_styles'] = null;
     13        }
    1314        $this->old_wp_styles = $GLOBALS['wp_styles'];
    1415        remove_action( 'wp_default_styles', 'wp_default_styles' );
    1516        remove_action( 'wp_print_styles', 'print_emoji_styles' );
    16         $GLOBALS['wp_styles'] = new WP_Styles();
     17        $GLOBALS['wp_styles']                  = new WP_Styles();
    1718        $GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' );
    1819    }
     
    2728    /**
    2829     * Test versioning
     30     *
    2931     * @ticket 11315
    3032     */
    3133    function test_wp_enqueue_style() {
    32         wp_enqueue_style('no-deps-no-version', 'example.com' );
    33         wp_enqueue_style('no-deps-version', 'example.com', array(), 1.2);
    34         wp_enqueue_style('no-deps-null-version', 'example.com', array(), null);
    35         wp_enqueue_style('no-deps-null-version-print-media', 'example.com', array(), null, 'print');
    36         $ver = get_bloginfo( 'version' );
     34        wp_enqueue_style( 'no-deps-no-version', 'example.com' );
     35        wp_enqueue_style( 'no-deps-version', 'example.com', array(), 1.2 );
     36        wp_enqueue_style( 'no-deps-null-version', 'example.com', array(), null );
     37        wp_enqueue_style( 'no-deps-null-version-print-media', 'example.com', array(), null, 'print' );
     38        $ver       = get_bloginfo( 'version' );
    3739        $expected  = "<link rel='stylesheet' id='no-deps-no-version-css'  href='http://example.com?ver=$ver' type='text/css' media='all' />\n";
    3840        $expected .= "<link rel='stylesheet' id='no-deps-version-css'  href='http://example.com?ver=1.2' type='text/css' media='all' />\n";
     
    4042        $expected .= "<link rel='stylesheet' id='no-deps-null-version-print-media-css'  href='http://example.com' type='text/css' media='print' />\n";
    4143
    42         $this->assertEquals($expected, get_echo('wp_print_styles'));
     44        $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) );
    4345
    4446        // No styles left to print
    45         $this->assertEquals("", get_echo('wp_print_styles'));
     47        $this->assertEquals( '', get_echo( 'wp_print_styles' ) );
    4648    }
    4749
    4850    /**
    4951     * Test the different protocol references in wp_enqueue_style
     52     *
    5053     * @global WP_Styles $wp_styles
    5154     * @ticket 16560
     
    5457        // Init
    5558        global $wp_styles;
    56         $base_url_backup = $wp_styles->base_url;
     59        $base_url_backup     = $wp_styles->base_url;
    5760        $wp_styles->base_url = 'http://example.com/wordpress';
    58         $expected = '';
    59         $ver = get_bloginfo( 'version' );
     61        $expected            = '';
     62        $ver                 = get_bloginfo( 'version' );
    6063
    6164        // Try with an HTTP reference
    6265        wp_enqueue_style( 'reset-css-http', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    63         $expected  .= "<link rel='stylesheet' id='reset-css-http-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     66        $expected .= "<link rel='stylesheet' id='reset-css-http-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    6467
    6568        // Try with an HTTPS reference
    6669        wp_enqueue_style( 'reset-css-https', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    67         $expected  .= "<link rel='stylesheet' id='reset-css-https-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     70        $expected .= "<link rel='stylesheet' id='reset-css-https-css'  href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    6871
    6972        // Try with an automatic protocol reference (//)
    7073        wp_enqueue_style( 'reset-css-doubleslash', '//yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    71         $expected  .= "<link rel='stylesheet' id='reset-css-doubleslash-css'  href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     74        $expected .= "<link rel='stylesheet' id='reset-css-doubleslash-css'  href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    7275
    7376        // Try with a local resource and an automatic protocol reference (//)
    7477        $url = '//my_plugin/style.css';
    7578        wp_enqueue_style( 'plugin-style', $url );
    76         $expected  .= "<link rel='stylesheet' id='plugin-style-css'  href='$url?ver=$ver' type='text/css' media='all' />\n";
     79        $expected .= "<link rel='stylesheet' id='plugin-style-css'  href='$url?ver=$ver' type='text/css' media='all' />\n";
    7780
    7881        // Try with a bad protocol
    7982        wp_enqueue_style( 'reset-css-ftp', 'ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' );
    80         $expected  .= "<link rel='stylesheet' id='reset-css-ftp-css'  href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
     83        $expected .= "<link rel='stylesheet' id='reset-css-ftp-css'  href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";
    8184
    8285        // Go!
     
    9295    /**
    9396     * Test if inline styles work
     97     *
    9498     * @ticket 24813
    9599     */
     
    98102        $style  = ".thing {\n";
    99103        $style .= "\tbackground: red;\n";
    100         $style .= "}";
     104        $style .= '}';
    101105
    102106        $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     
    114118    /**
    115119     * Test if inline styles work with concatination
     120     *
    116121     * @global WP_Styles $wp_styles
    117122     * @ticket 24813
     
    121126        global $wp_styles;
    122127
    123         $wp_styles->do_concat = true;
     128        $wp_styles->do_concat    = true;
    124129        $wp_styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Default dirs as in wp-includes/script-loader.php
    125130
    126131        $style  = ".thing {\n";
    127132        $style .= "\tbackground: red;\n";
    128         $style .= "}";
     133        $style .= '}';
    129134
    130135        $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     
    143148    /**
    144149     * Test if multiple inline styles work
     150     *
    145151     * @ticket 24813
    146152     */
     
    149155        $style1  = ".thing1 {\n";
    150156        $style1 .= "\tbackground: red;\n";
    151         $style1 .= "}";
     157        $style1 .= '}';
    152158
    153159        $style2  = ".thing2 {\n";
    154160        $style2 .= "\tbackground: blue;\n";
    155         $style2 .= "}";
     161        $style2 .= '}';
    156162
    157163        $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     
    182188        $style .= "\tbackground: red;\n";
    183189        $style .= "}\n";
    184         $style .= "</style>";
     190        $style .= '</style>';
    185191
    186192        $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     
    197203    /**
    198204     * Test to make sure <style> tags aren't output if there are no inline styles.
     205     *
    199206     * @ticket 24813
    200207     */
    201208    public function test_unnecessary_style_tags() {
    202209
    203         $expected  = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     210        $expected = "<link rel='stylesheet' id='handle-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
    204211
    205212        wp_enqueue_style( 'handle', 'http://example.com', array(), 1 );
     
    244251     */
    245252    function test_wp_add_inline_style_for_handle_without_source() {
    246         $style  = "a { color: blue; }";
     253        $style = 'a { color: blue; }';
    247254
    248255        $expected  = "<link rel='stylesheet' id='handle-one-css'  href='http://example.com?ver=1' type='text/css' media='all' />\n";
     
    275282            array(
    276283                "media='all'",
    277                 'all'
     284                'all',
    278285            ),
    279286            array(
    280287                "media='(orientation: portrait)'",
    281                 '(orientation: portrait)'
     288                '(orientation: portrait)',
    282289            ),
    283290            array(
    284291                "media='(max-width: 640px)'",
    285                 '(max-width: 640px)'
     292                '(max-width: 640px)',
    286293            ),
    287294            array(
    288295                "media='print and (min-width: 25cm)'",
    289                 'print and (min-width: 25cm)'
     296                'print and (min-width: 25cm)',
    290297            ),
    291298            array(
    292299                "media='screen and (color), projection and (color)'",
    293                 'screen and (color), projection and (color)'
     300                'screen and (color), projection and (color)',
    294301            ),
    295302            array(
    296303                "media='not screen and (color)'",
    297                 'not screen and (color)'
     304                'not screen and (color)',
    298305            ),
    299306        );
Note: See TracChangeset for help on using the changeset viewer.