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/customize/custom-css-setting.php

    r41376 r42343  
    3232        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    3333
    34         $user_id = self::factory()->user->create( array(
    35             'role' => 'administrator',
    36         ) );
     34        $user_id = self::factory()->user->create(
     35            array(
     36                'role' => 'administrator',
     37            )
     38        );
    3739        if ( is_multisite() ) {
    3840            grant_super_admin( $user_id );
     
    4345        global $wp_customize;
    4446        $this->wp_customize = new WP_Customize_Manager();
    45         $wp_customize = $this->wp_customize;
     47        $wp_customize       = $this->wp_customize;
    4648
    4749        do_action( 'customize_register', $this->wp_customize );
     
    118120        $this->assertNull( wp_get_custom_css_post( 'twentyten' ) );
    119121
    120         $original_css = 'body { color: black; }';
    121         $post_id = $this->factory()->post->create( array(
    122             'post_title' => $this->setting->stylesheet,
    123             'post_name' => $this->setting->stylesheet,
    124             'post_content' => $original_css,
    125             'post_status' => 'publish',
    126             'post_type' => 'custom_css',
    127         ) );
    128         $twentyten_css = 'body { color: red; }';
    129         $twentyten_post_id = $this->factory()->post->create( array(
    130             'post_title' => 'twentyten',
    131             'post_name' => 'twentyten',
    132             'post_content' => $twentyten_css,
    133             'post_status' => 'publish',
    134             'post_type' => 'custom_css',
    135         ) );
     122        $original_css      = 'body { color: black; }';
     123        $post_id           = $this->factory()->post->create(
     124            array(
     125                'post_title'   => $this->setting->stylesheet,
     126                'post_name'    => $this->setting->stylesheet,
     127                'post_content' => $original_css,
     128                'post_status'  => 'publish',
     129                'post_type'    => 'custom_css',
     130            )
     131        );
     132        $twentyten_css     = 'body { color: red; }';
     133        $twentyten_post_id = $this->factory()->post->create(
     134            array(
     135                'post_title'   => 'twentyten',
     136                'post_name'    => 'twentyten',
     137                'post_content' => $twentyten_css,
     138                'post_status'  => 'publish',
     139                'post_type'    => 'custom_css',
     140            )
     141        );
    136142        $twentyten_setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentyten]' );
    137143
     
    163169
    164170        // Make sure that wp_update_custom_css_post() works as expected for updates.
    165         $r = wp_update_custom_css_post( 'body { color:red; }', array(
    166             'stylesheet' => $this->setting->stylesheet,
    167             'preprocessed' => "body\n\tcolor:red;",
    168         ) );
     171        $r = wp_update_custom_css_post(
     172            'body { color:red; }', array(
     173                'stylesheet'   => $this->setting->stylesheet,
     174                'preprocessed' => "body\n\tcolor:red;",
     175            )
     176        );
    169177        $this->assertInstanceOf( 'WP_Post', $r );
    170178        $this->assertEquals( $post_id, $r->ID );
     
    177185
    178186        // Make sure that wp_update_custom_css_post() works as expected for insertion.
    179         $r = wp_update_custom_css_post( 'body { background:black; }', array(
    180             'stylesheet' => 'other',
    181         ) );
     187        $r = wp_update_custom_css_post(
     188            'body { background:black; }', array(
     189                'stylesheet' => 'other',
     190            )
     191        );
    182192        $this->assertInstanceOf( 'WP_Post', $r );
    183193        $this->assertEquals( 'other', get_post( $r )->post_name );
     
    202212    function test_custom_css_revision_saved() {
    203213        $inserted_css = 'body { background: black; }';
    204         $updated_css = 'body { background: red; }';
    205 
    206         $post = wp_update_custom_css_post( $inserted_css, array(
    207             'stylesheet' => 'testtheme',
    208         ) );
     214        $updated_css  = 'body { background: red; }';
     215
     216        $post = wp_update_custom_css_post(
     217            $inserted_css, array(
     218                'stylesheet' => 'testtheme',
     219            )
     220        );
    209221
    210222        $this->assertSame( $inserted_css, $post->post_content );
     
    213225        $this->assertSame( $inserted_css, $revisions[0]->post_content );
    214226
    215         wp_update_custom_css_post( $updated_css, array(
    216             'stylesheet' => 'testtheme',
    217         ) );
     227        wp_update_custom_css_post(
     228            $updated_css, array(
     229                'stylesheet' => 'testtheme',
     230            )
     231        );
    218232
    219233        $revisions = array_values( wp_get_post_revisions( $post ) );
     
    256270        $this->assertEquals( '/*default*//*filtered*/', $this->setting->value() );
    257271
    258         $this->factory()->post->create( array(
    259             'post_title' => $this->setting->stylesheet,
    260             'post_name' => $this->setting->stylesheet,
    261             'post_content' => '/*custom*/',
    262             'post_status' => 'publish',
    263             'post_type' => 'custom_css',
    264         ) );
     272        $this->factory()->post->create(
     273            array(
     274                'post_title'   => $this->setting->stylesheet,
     275                'post_name'    => $this->setting->stylesheet,
     276                'post_content' => '/*custom*/',
     277                'post_status'  => 'publish',
     278                'post_type'    => 'custom_css',
     279            )
     280        );
    265281        remove_theme_mod( 'custom_css_post_id' );
    266282        $this->assertEquals( '/*custom*//*filtered*/', $this->setting->value() );
     
    291307    function test_update_filter() {
    292308        $original_css = 'body { color:red; }';
    293         $post_id = $this->factory()->post->create( array(
    294             'post_title' => $this->setting->stylesheet,
    295             'post_name' => $this->setting->stylesheet,
    296             'post_content' => $original_css,
    297             'post_status' => 'publish',
    298             'post_type' => 'custom_css',
    299         ) );
     309        $post_id      = $this->factory()->post->create(
     310            array(
     311                'post_title'   => $this->setting->stylesheet,
     312                'post_name'    => $this->setting->stylesheet,
     313                'post_content' => $original_css,
     314                'post_status'  => 'publish',
     315                'post_type'    => 'custom_css',
     316            )
     317        );
    300318
    301319        $overridden_css = 'body { color:green; }';
    302320        $this->wp_customize->set_post_value( $this->setting->id, $overridden_css );
    303321
    304         $post = get_post( $post_id );
     322        $post           = get_post( $post_id );
    305323        $original_title = $post->post_title;
    306324
     
    331349        $this->assertEquals( $args['preprocessed'], $data['preprocessed'] );
    332350
    333         $data['css'] .= '/* filtered post_content */';
     351        $data['css']         .= '/* filtered post_content */';
    334352        $data['preprocessed'] = '/* filtered post_content_filtered */';
    335         $data['post_title'] = 'Ignored';
     353        $data['post_title']   = 'Ignored';
    336354        return $data;
    337355    }
     
    353371        // Basic, valid CSS throws no errors.
    354372        $basic_css = 'body { background: #f00; } h1.site-title { font-size: 36px; } a:hover { text-decoration: none; } input[type="text"] { padding: 1em; }';
    355         $result = $this->setting->validate( $basic_css );
     373        $result    = $this->setting->validate( $basic_css );
    356374        $this->assertTrue( $result );
    357375
    358376        // Check for markup.
    359377        $unclosed_comment = $basic_css . '</style>';
    360         $result = $this->setting->validate( $unclosed_comment );
     378        $result           = $this->setting->validate( $unclosed_comment );
    361379        $this->assertTrue( array_key_exists( 'illegal_markup', $result->errors ) );
    362380    }
Note: See TracChangeset for help on using the changeset viewer.