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/ajax/CustomizeMenus.php

    r41887 r42343  
    2626        global $wp_customize;
    2727        $this->wp_customize = new WP_Customize_Manager();
    28         $wp_customize = $this->wp_customize;
     28        $wp_customize       = $this->wp_customize;
    2929    }
    3030
     
    8787     * @return array {
    8888     *     @type array {
    89      *         @string string $role             The role that will test caps for.
    90      *         @array  array  $expected_results The expected results from the ajax call.
     89     * @string string $role             The role that will test caps for.
     90     * @array  array  $expected_results The expected results from the ajax call.
    9191     *     }
    9292     * }
     
    130130    function test_ajax_load_available_items_error_messages( $post_args, $expected_results ) {
    131131
    132         $_POST = array_merge( array(
    133             'action'                => 'load-available-menu-items-customizer',
    134             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    135         ), $post_args );
     132        $_POST = array_merge(
     133            array(
     134                'action'                => 'load-available-menu-items-customizer',
     135                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     136            ), $post_args
     137        );
    136138
    137139        // Make the request.
     
    154156     * @return array {
    155157     *     @type array {
    156      *         @array array $post_args        The arguments that will merged with the $_POST array.
    157      *         @array array $expected_results The expected results from the ajax call.
     158     * @array array $post_args        The arguments that will merged with the $_POST array.
     159     * @array array $expected_results The expected results from the ajax call.
    158160     *     }
    159161     * }
     
    164166            array(
    165167                array(
    166                     'type'     => '',
    167                     'object'   => '',
    168                 ),
    169                 array(
    170                     'success'  => false,
    171                     'data'     => 'nav_menus_missing_type_or_object_parameter',
     168                    'type'   => '',
     169                    'object' => '',
     170                ),
     171                array(
     172                    'success' => false,
     173                    'data'    => 'nav_menus_missing_type_or_object_parameter',
    172174                ),
    173175            ),
     
    175177            array(
    176178                array(
    177                     'type'     => 'post_type',
    178                     'object'   => '',
    179                 ),
    180                 array(
    181                     'success'  => false,
    182                     'data'     => 'nav_menus_missing_type_or_object_parameter',
     179                    'type'   => 'post_type',
     180                    'object' => '',
     181                ),
     182                array(
     183                    'success' => false,
     184                    'data'    => 'nav_menus_missing_type_or_object_parameter',
    183185                ),
    184186            ),
     
    186188            array(
    187189                array(
    188                     'type'     => '',
    189                     'object'   => 'post',
    190                 ),
    191                 array(
    192                     'success'  => false,
    193                     'data'     => 'nav_menus_missing_type_or_object_parameter',
     190                    'type'   => '',
     191                    'object' => 'post',
     192                ),
     193                array(
     194                    'success' => false,
     195                    'data'    => 'nav_menus_missing_type_or_object_parameter',
    194196                ),
    195197            ),
     
    199201                    'item_types' => array(
    200202                        array(
    201                             'type'     => 'post_type',
    202                             'object'   => 'post',
     203                            'type'   => 'post_type',
     204                            'object' => 'post',
    203205                        ),
    204206                        array(
    205                             'type'     => 'post_type',
    206                             'object'   => '',
     207                            'type'   => 'post_type',
     208                            'object' => '',
    207209                        ),
    208210                    ),
    209211                ),
    210212                array(
    211                     'success'  => false,
    212                     'data'     => 'nav_menus_missing_type_or_object_parameter',
     213                    'success' => false,
     214                    'data'    => 'nav_menus_missing_type_or_object_parameter',
    213215                ),
    214216            ),
     
    216218            array(
    217219                array(
    218                     'type'     => 'post_type',
    219                     'object'   => 'invalid',
    220                 ),
    221                 array(
    222                     'success'  => false,
    223                     'data'     => 'nav_menus_invalid_post_type',
     220                    'type'   => 'post_type',
     221                    'object' => 'invalid',
     222                ),
     223                array(
     224                    'success' => false,
     225                    'data'    => 'nav_menus_invalid_post_type',
    224226                ),
    225227            ),
     
    237239    function test_ajax_load_available_items_success_status( $post_args, $success_status ) {
    238240
    239         $_POST = array_merge( array(
    240             'action'                => 'load-available-menu-items-customizer',
    241             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    242         ), $post_args );
     241        $_POST = array_merge(
     242            array(
     243                'action'                => 'load-available-menu-items-customizer',
     244                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     245            ), $post_args
     246        );
    243247
    244248        // Make the request.
     
    270274            array(
    271275                array(
    272                     'type'     => 'post_type',
    273                     'object'   => 'post',
     276                    'type'   => 'post_type',
     277                    'object' => 'post',
    274278                ),
    275279                true,
     
    277281            array(
    278282                array(
    279                     'type'     => 'post_type',
    280                     'object'   => 'page',
     283                    'type'   => 'post_type',
     284                    'object' => 'page',
    281285                ),
    282286                true,
     
    284288            array(
    285289                array(
    286                     'type'     => 'post_type',
    287                     'object'   => 'custom',
     290                    'type'   => 'post_type',
     291                    'object' => 'custom',
    288292                ),
    289293                false,
     
    291295            array(
    292296                array(
    293                     'type'     => 'taxonomy',
    294                     'object'   => 'post_tag',
     297                    'type'   => 'taxonomy',
     298                    'object' => 'post_tag',
    295299                ),
    296300                true,
     
    301305                    'item_types' => array(
    302306                        array(
    303                             'type'     => 'post_type',
    304                             'object'   => 'post',
     307                            'type'   => 'post_type',
     308                            'object' => 'post',
    305309                        ),
    306310                        array(
    307                             'type'     => 'post_type',
    308                             'object'   => 'page',
     311                            'type'   => 'post_type',
     312                            'object' => 'page',
    309313                        ),
    310314                    ),
     
    338342        self::factory()->term->create_many( 5 );
    339343        self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) );
    340         $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Auto Draft', 'post_type' => 'post' ) );
     344        $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post(
     345            array(
     346                'post_title' => 'Test Auto Draft',
     347                'post_type'  => 'post',
     348            )
     349        );
    341350        $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $auto_draft_post->ID ) );
    342351        $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview();
    343352
    344         $_POST = array_merge( array(
    345             'action'                => 'load-available-menu-items-customizer',
    346             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    347         ), $post_args );
     353        $_POST = array_merge(
     354            array(
     355                'action'                => 'load-available-menu-items-customizer',
     356                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     357            ), $post_args
     358        );
    348359
    349360        // Make the request.
     
    357368        // Get the second index to avoid the home page edge case.
    358369        $first_prop = current( $response['data']['items'] );
    359         $test_item = $first_prop[1];
     370        $test_item  = $first_prop[1];
    360371
    361372        foreach ( $expected_keys as $key ) {
     
    367378        if ( 'page' === $test_item['object'] ) {
    368379            $first_prop = current( $response['data']['items'] );
    369             $home = $first_prop[0];
     380            $home       = $first_prop[0];
    370381            foreach ( $expected_keys as $key ) {
    371382                if ( 'object_id' !== $key ) {
     
    399410            array(
    400411                array(
    401                     'type'     => 'post_type',
    402                     'object'   => 'post',
    403                 ),
    404             ),
    405             array(
    406                 array(
    407                     'type'     => 'post_type',
    408                     'object'   => 'page',
    409                 ),
    410             ),
    411             array(
    412                 array(
    413                     'type'     => 'taxonomy',
    414                     'object'   => 'post_tag',
     412                    'type'   => 'post_type',
     413                    'object' => 'post',
     414                ),
     415            ),
     416            array(
     417                array(
     418                    'type'   => 'post_type',
     419                    'object' => 'page',
     420                ),
     421            ),
     422            array(
     423                array(
     424                    'type'   => 'taxonomy',
     425                    'object' => 'post_tag',
    415426                ),
    416427            ),
     
    463474     * @return array {
    464475     *     @type array {
    465      *         @string string $role             The role that will test caps for.
    466      *         @array  array  $expected_results The expected results from the ajax call.
     476     * @string string $role             The role that will test caps for.
     477     * @array  array  $expected_results The expected results from the ajax call.
    467478     *     }
    468479     * }
     
    508519
    509520        self::factory()->post->create_many( 5, array( 'post_title' => 'Test Post' ) );
    510         $included_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Included Auto Draft', 'post_type' => 'post' ) );
    511         $excluded_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Excluded Auto Draft', 'post_type' => 'post' ) );
     521        $included_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post(
     522            array(
     523                'post_title' => 'Test Included Auto Draft',
     524                'post_type'  => 'post',
     525            )
     526        );
     527        $excluded_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post(
     528            array(
     529                'post_title' => 'Excluded Auto Draft',
     530                'post_type'  => 'post',
     531            )
     532        );
    512533        $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $included_auto_draft_post->ID, $excluded_auto_draft_post->ID ) );
    513534        $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview();
    514535
    515         $_POST = array_merge( array(
    516             'action'                => 'search-available-menu-items-customizer',
    517             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    518         ), $post_args );
     536        $_POST = array_merge(
     537            array(
     538                'action'                => 'search-available-menu-items-customizer',
     539                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     540            ), $post_args
     541        );
    519542
    520543        $this->make_ajax_call( 'search-available-menu-items-customizer' );
     
    542565     * @return array {
    543566     *     @type array {
    544      *         @string string $post_args        The args that will be passed to ajax.
    545      *         @array  array  $expected_results The expected results from the ajax call.
     567     * @string string $post_args        The args that will be passed to ajax.
     568     * @array  array  $expected_results The expected results from the ajax call.
    546569     *     }
    547570     * }
     
    558581            array(
    559582                array(
    560                     'search'  => 'all_the_things',
     583                    'search' => 'all_the_things',
    561584                ),
    562585                array(
     
    569592            array(
    570593                array(
    571                     'search'  => 'test',
     594                    'search' => 'test',
    572595                ),
    573596                array(
     
    585608     */
    586609    function test_ajax_insert_auto_draft_post_success() {
    587         $_POST = wp_slash( array(
    588             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    589             'params' => array(
    590                 'post_type' => 'post',
    591                 'post_title' => 'Hello World',
    592             ),
    593         ) );
     610        $_POST                = wp_slash(
     611            array(
     612                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     613                'params'                => array(
     614                    'post_type'  => 'post',
     615                    'post_title' => 'Hello World',
     616                ),
     617            )
     618        );
    594619        $this->_last_response = '';
    595620        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    614639    function test_ajax_insert_auto_draft_failures() {
    615640        // No nonce.
    616         $_POST = array();
     641        $_POST                = array();
    617642        $this->_last_response = '';
    618643        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    622647
    623648        // Bad nonce.
    624         $_POST = wp_slash( array(
    625             'customize-menus-nonce' => 'bad',
    626         ) );
     649        $_POST                = wp_slash(
     650            array(
     651                'customize-menus-nonce' => 'bad',
     652            )
     653        );
    627654        $this->_last_response = '';
    628655        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    633660        // Bad nonce.
    634661        wp_set_current_user( $this->factory()->user->create( array( 'role' => 'subscriber' ) ) );
    635         $_POST = wp_slash( array(
    636             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    637         ) );
     662        $_POST                = wp_slash(
     663            array(
     664                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     665            )
     666        );
    638667        $this->_last_response = '';
    639668        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    644673        // Missing params.
    645674        wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) );
    646         $_POST = wp_slash( array(
    647             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    648         ) );
     675        $_POST                = wp_slash(
     676            array(
     677                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     678            )
     679        );
    649680        $this->_last_response = '';
    650681        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    655686        // insufficient_post_permissions.
    656687        register_post_type( 'privilege', array( 'capability_type' => 'privilege' ) );
    657         $_POST = wp_slash( array(
    658             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    659             'params' => array(
    660                 'post_type' => 'privilege',
    661             ),
    662         ) );
     688        $_POST                = wp_slash(
     689            array(
     690                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     691                'params'                => array(
     692                    'post_type' => 'privilege',
     693                ),
     694            )
     695        );
    663696        $this->_last_response = '';
    664697        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    668701
    669702        // insufficient_post_permissions.
    670         $_POST = wp_slash( array(
    671             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    672             'params' => array(
    673                 'post_type' => 'non-existent',
    674             ),
    675         ) );
     703        $_POST                = wp_slash(
     704            array(
     705                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     706                'params'                => array(
     707                    'post_type' => 'non-existent',
     708                ),
     709            )
     710        );
    676711        $this->_last_response = '';
    677712        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    681716
    682717        // missing_post_title.
    683         $_POST = wp_slash( array(
    684             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    685             'params' => array(
    686                 'post_type' => 'post',
    687                 'post_title' => '    ',
    688             ),
    689         ) );
     718        $_POST                = wp_slash(
     719            array(
     720                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     721                'params'                => array(
     722                    'post_type'  => 'post',
     723                    'post_title' => '    ',
     724                ),
     725            )
     726        );
    690727        $this->_last_response = '';
    691728        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
     
    695732
    696733        // illegal_params.
    697         $_POST = wp_slash( array(
    698             'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
    699             'params' => array(
    700                 'post_type' => 'post',
    701                 'post_title' => 'OK',
    702                 'post_name' => 'bad',
    703                 'post_content' => 'bad',
    704             ),
    705         ) );
     734        $_POST                = wp_slash(
     735            array(
     736                'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ),
     737                'params'                => array(
     738                    'post_type'    => 'post',
     739                    'post_title'   => 'OK',
     740                    'post_name'    => 'bad',
     741                    'post_content' => 'bad',
     742                ),
     743            )
     744        );
    706745        $this->_last_response = '';
    707746        $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
Note: See TracChangeset for help on using the changeset viewer.