Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/admin/includesScreen.php

    r40800 r42343  
    77class Tests_Admin_includesScreen extends WP_UnitTestCase {
    88    var $core_screens = array(
    9         'index.php' => array( 'base' => 'dashboard', 'id' => 'dashboard' ),
    10         'edit.php' => array( 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post' ),
    11         'post-new.php'=> array( 'action' => 'add', 'base' => 'post', 'id' => 'post', 'post_type' => 'post' ),
    12         'edit-tags.php' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
    13         'edit-tags.php?taxonomy=post_tag' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
    14         'edit-tags.php?taxonomy=category' => array( 'base' => 'edit-tags', 'id' => 'edit-category', 'post_type' => 'post', 'taxonomy' => 'category' ),
    15         'upload.php' => array( 'base' => 'upload', 'id' => 'upload', 'post_type' => 'attachment' ),
    16         'media-new.php' => array( 'action' => 'add', 'base' => 'media', 'id' => 'media' ),
    17         'edit.php?post_type=page' => array( 'base' => 'edit', 'id' => 'edit-page', 'post_type' => 'page' ),
    18         'link-manager.php' => array( 'base' => 'link-manager', 'id' => 'link-manager' ),
    19         'link-add.php' => array( 'action' => 'add', 'base' => 'link', 'id' => 'link' ),
    20         'edit-tags.php?taxonomy=link_category' => array( 'base' => 'edit-tags', 'id' => 'edit-link_category', 'taxonomy' => 'link_category', 'post_type' => '' ),
    21         'edit-comments.php' => array( 'base' => 'edit-comments', 'id' => 'edit-comments' ),
    22         'themes.php' => array( 'base' => 'themes', 'id' => 'themes' ),
    23         'widgets.php' => array( 'base' => 'widgets', 'id' => 'widgets' ),
    24         'nav-menus.php' => array( 'base' => 'nav-menus', 'id' => 'nav-menus' ),
    25         'plugins.php' => array( 'base' => 'plugins', 'id' => 'plugins' ),
    26         'users.php' => array( 'base' => 'users', 'id' => 'users' ),
    27         'user-new.php' => array( 'action' => 'add', 'base' => 'user', 'id' => 'user' ),
    28         'profile.php' => array( 'base' => 'profile', 'id' => 'profile' ),
    29         'tools.php' => array( 'base' => 'tools', 'id' => 'tools' ),
    30         'import.php' => array( 'base' => 'import', 'id' => 'import' ),
    31         'export.php' => array( 'base' => 'export', 'id' => 'export' ),
    32         'options-general.php' => array( 'base' => 'options-general', 'id' => 'options-general' ),
    33         'options-writing.php' => array( 'base' => 'options-writing', 'id' => 'options-writing' ),
     9        'index.php'                            => array(
     10            'base' => 'dashboard',
     11            'id'   => 'dashboard',
     12        ),
     13        'edit.php'                             => array(
     14            'base'      => 'edit',
     15            'id'        => 'edit-post',
     16            'post_type' => 'post',
     17        ),
     18        'post-new.php'                         => array(
     19            'action'    => 'add',
     20            'base'      => 'post',
     21            'id'        => 'post',
     22            'post_type' => 'post',
     23        ),
     24        'edit-tags.php'                        => array(
     25            'base'      => 'edit-tags',
     26            'id'        => 'edit-post_tag',
     27            'post_type' => 'post',
     28            'taxonomy'  => 'post_tag',
     29        ),
     30        'edit-tags.php?taxonomy=post_tag'      => array(
     31            'base'      => 'edit-tags',
     32            'id'        => 'edit-post_tag',
     33            'post_type' => 'post',
     34            'taxonomy'  => 'post_tag',
     35        ),
     36        'edit-tags.php?taxonomy=category'      => array(
     37            'base'      => 'edit-tags',
     38            'id'        => 'edit-category',
     39            'post_type' => 'post',
     40            'taxonomy'  => 'category',
     41        ),
     42        'upload.php'                           => array(
     43            'base'      => 'upload',
     44            'id'        => 'upload',
     45            'post_type' => 'attachment',
     46        ),
     47        'media-new.php'                        => array(
     48            'action' => 'add',
     49            'base'   => 'media',
     50            'id'     => 'media',
     51        ),
     52        'edit.php?post_type=page'              => array(
     53            'base'      => 'edit',
     54            'id'        => 'edit-page',
     55            'post_type' => 'page',
     56        ),
     57        'link-manager.php'                     => array(
     58            'base' => 'link-manager',
     59            'id'   => 'link-manager',
     60        ),
     61        'link-add.php'                         => array(
     62            'action' => 'add',
     63            'base'   => 'link',
     64            'id'     => 'link',
     65        ),
     66        'edit-tags.php?taxonomy=link_category' => array(
     67            'base'      => 'edit-tags',
     68            'id'        => 'edit-link_category',
     69            'taxonomy'  => 'link_category',
     70            'post_type' => '',
     71        ),
     72        'edit-comments.php'                    => array(
     73            'base' => 'edit-comments',
     74            'id'   => 'edit-comments',
     75        ),
     76        'themes.php'                           => array(
     77            'base' => 'themes',
     78            'id'   => 'themes',
     79        ),
     80        'widgets.php'                          => array(
     81            'base' => 'widgets',
     82            'id'   => 'widgets',
     83        ),
     84        'nav-menus.php'                        => array(
     85            'base' => 'nav-menus',
     86            'id'   => 'nav-menus',
     87        ),
     88        'plugins.php'                          => array(
     89            'base' => 'plugins',
     90            'id'   => 'plugins',
     91        ),
     92        'users.php'                            => array(
     93            'base' => 'users',
     94            'id'   => 'users',
     95        ),
     96        'user-new.php'                         => array(
     97            'action' => 'add',
     98            'base'   => 'user',
     99            'id'     => 'user',
     100        ),
     101        'profile.php'                          => array(
     102            'base' => 'profile',
     103            'id'   => 'profile',
     104        ),
     105        'tools.php'                            => array(
     106            'base' => 'tools',
     107            'id'   => 'tools',
     108        ),
     109        'import.php'                           => array(
     110            'base' => 'import',
     111            'id'   => 'import',
     112        ),
     113        'export.php'                           => array(
     114            'base' => 'export',
     115            'id'   => 'export',
     116        ),
     117        'options-general.php'                  => array(
     118            'base' => 'options-general',
     119            'id'   => 'options-general',
     120        ),
     121        'options-writing.php'                  => array(
     122            'base' => 'options-writing',
     123            'id'   => 'options-writing',
     124        ),
    34125    );
    35126
     
    48139
    49140        foreach ( $this->core_screens as $hook_name => $screen ) {
    50             $_GET = $_POST = $_REQUEST = array();
     141            $_GET              = $_POST = $_REQUEST = array();
    51142            $GLOBALS['taxnow'] = $GLOBALS['typenow'] = '';
    52             $screen = (object) $screen;
    53             $hook = parse_url( $hook_name );
     143            $screen            = (object) $screen;
     144            $hook              = parse_url( $hook_name );
    54145
    55146            if ( ! empty( $hook['query'] ) ) {
    56147                $args = wp_parse_args( $hook['query'] );
    57                 if ( isset( $args['taxonomy'] ) )
     148                if ( isset( $args['taxonomy'] ) ) {
    58149                    $GLOBALS['taxnow'] = $_GET['taxonomy'] = $_POST['taxonomy'] = $_REQUEST['taxonomy'] = $args['taxonomy'];
    59                 if ( isset( $args['post_type'] ) )
     150                }
     151                if ( isset( $args['post_type'] ) ) {
    60152                    $GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = $args['post_type'];
    61                 else if ( isset( $screen->post_type ) )
     153                } elseif ( isset( $screen->post_type ) ) {
    62154                    $GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = $screen->post_type;
     155                }
    63156            }
    64157
     
    68161            $this->assertEquals( $screen->id, $current_screen->id, $hook_name );
    69162            $this->assertEquals( $screen->base, $current_screen->base, $hook_name );
    70             if ( isset( $screen->action ) )
     163            if ( isset( $screen->action ) ) {
    71164                $this->assertEquals( $screen->action, $current_screen->action, $hook_name );
    72             if ( isset( $screen->post_type ) )
     165            }
     166            if ( isset( $screen->post_type ) ) {
    73167                $this->assertEquals( $screen->post_type, $current_screen->post_type, $hook_name );
    74             else
     168            } else {
    75169                $this->assertEmpty( $current_screen->post_type, $hook_name );
    76             if ( isset( $screen->taxonomy ) )
     170            }
     171            if ( isset( $screen->taxonomy ) ) {
    77172                $this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $hook_name );
     173            }
    78174
    79175            $this->assertTrue( $current_screen->in_admin() );
     
    88184            // With convert_to_screen(), the hook_suffix should return the exact $current_screen.
    89185            // But, convert_to_screen() cannot figure out ?taxonomy and ?post_type.
    90             if ( empty( $hook['query'] ) )
     186            if ( empty( $hook['query'] ) ) {
    91187                $this->assertSame( $current_screen, convert_to_screen( $GLOBALS['hook_suffix'] ), $hook_name );
     188            }
    92189        }
    93190    }
     
    155252
    156253    function test_help_tabs() {
    157         $tab = __FUNCTION__;
     254        $tab      = __FUNCTION__;
    158255        $tab_args = array(
    159             'id' => $tab,
    160             'title' => 'Help!',
    161             'content' => 'Some content',
     256            'id'       => $tab,
     257            'title'    => 'Help!',
     258            'content'  => 'Some content',
    162259            'callback' => false,
    163260        );
     
    165262        $screen = get_current_screen();
    166263        $screen->add_help_tab( $tab_args );
    167         $this->assertEquals( $screen->get_help_tab( $tab ), array(
    168             'id' => $tab,
    169             'title' => 'Help!',
    170             'content' => 'Some content',
    171             'callback' => false,
    172             'priority' => 10,
    173         ) );
     264        $this->assertEquals(
     265            $screen->get_help_tab( $tab ), array(
     266                'id'       => $tab,
     267                'title'    => 'Help!',
     268                'content'  => 'Some content',
     269                'callback' => false,
     270                'priority' => 10,
     271            )
     272        );
    174273
    175274        $tabs = $screen->get_help_tabs();
     
    236335        $screen->add_help_tab( $tab_4_args );
    237336        // Priority is added with the default for future calls
    238         $tab_4_args[ 'priority' ] = 10;
     337        $tab_4_args['priority'] = 10;
    239338        $this->assertEquals( $screen->get_help_tab( $tab_4 ), $tab_4_args );
    240339
     
    248347        // Test priority order.
    249348
    250         $this->assertSame( array(
    251             $tab_2 => $tab_2_args,
    252             $tab_1 => $tab_1_args,
    253             $tab_4 => $tab_4_args,
    254             $tab_3 => $tab_3_args,
    255         ), $tabs );
     349        $this->assertSame(
     350            array(
     351                $tab_2 => $tab_2_args,
     352                $tab_1 => $tab_1_args,
     353                $tab_4 => $tab_4_args,
     354                $tab_3 => $tab_3_args,
     355            ), $tabs
     356        );
    256357
    257358        $screen->remove_help_tab( $tab_1 );
     
    279380     */
    280381    function test_options() {
    281         $option = __FUNCTION__;
     382        $option      = __FUNCTION__;
    282383        $option_args = array(
    283384            'label'   => 'Option',
    284385            'default' => 10,
    285             'option'  => $option
     386            'option'  => $option,
    286387        );
    287388
Note: See TracChangeset for help on using the changeset viewer.