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/category/wpListCategories.php

    r39280 r42343  
    88        $c = self::factory()->category->create();
    99
    10         $found = wp_list_categories( array(
    11             'hide_empty' => false,
    12             'echo' => false,
    13         ) );
     10        $found = wp_list_categories(
     11            array(
     12                'hide_empty' => false,
     13                'echo'       => false,
     14            )
     15        );
    1416
    1517        $this->assertContains( 'class="cat-item cat-item-' . $c . '"', $found );
     
    2022        $c2 = self::factory()->category->create();
    2123
    22         $found = wp_list_categories( array(
    23             'hide_empty' => false,
    24             'echo' => false,
    25             'current_category' => $c2,
    26         ) );
     24        $found = wp_list_categories(
     25            array(
     26                'hide_empty'       => false,
     27                'echo'             => false,
     28                'current_category' => $c2,
     29            )
     30        );
    2731
    2832        $this->assertNotRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat[^"]*"/', $found );
     
    3236    public function test_class_containing_current_cat_parent() {
    3337        $c1 = self::factory()->category->create();
    34         $c2 = self::factory()->category->create( array(
    35             'parent' => $c1,
    36         ) );
    37 
    38         $found = wp_list_categories( array(
    39             'hide_empty' => false,
    40             'echo' => false,
    41             'current_category' => $c2,
    42         ) );
     38        $c2 = self::factory()->category->create(
     39            array(
     40                'parent' => $c1,
     41            )
     42        );
     43
     44        $found = wp_list_categories(
     45            array(
     46                'hide_empty'       => false,
     47                'echo'             => false,
     48                'current_category' => $c2,
     49            )
     50        );
    4351
    4452        $this->assertRegExp( '/class="[^"]*cat-item-' . $c1 . '[^"]*current-cat-parent[^"]*"/', $found );
     
    5260        $cats = self::factory()->category->create_many( 3 );
    5361
    54         $found = wp_list_categories( array(
    55             'echo' => false,
    56             'hide_empty' => false,
    57             'current_category' => array( $cats[0], $cats[2] ),
    58         ) );
     62        $found = wp_list_categories(
     63            array(
     64                'echo'             => false,
     65                'hide_empty'       => false,
     66                'current_category' => array( $cats[0], $cats[2] ),
     67            )
     68        );
    5969
    6070        $this->assertRegExp( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found );
     
    6777     */
    6878    public function test_should_not_create_element_when_cat_name_is_filtered_to_empty_string() {
    69         $c1 = self::factory()->category->create( array(
    70             'name' => 'Test Cat 1',
    71         ) );
    72         $c2 = self::factory()->category->create( array(
    73             'name' => 'Test Cat 2',
    74         ) );
     79        $c1 = self::factory()->category->create(
     80            array(
     81                'name' => 'Test Cat 1',
     82            )
     83        );
     84        $c2 = self::factory()->category->create(
     85            array(
     86                'name' => 'Test Cat 2',
     87            )
     88        );
    7589
    7690        add_filter( 'list_cats', array( $this, 'list_cats_callback' ) );
    77         $found = wp_list_categories( array(
    78             'hide_empty' => false,
    79             'echo' => false,
    80         ) );
     91        $found = wp_list_categories(
     92            array(
     93                'hide_empty' => false,
     94                'echo'       => false,
     95            )
     96        );
    8197        remove_filter( 'list_cats', array( $this, 'list_cats_callback' ) );
    8298
     
    91107        $cats = self::factory()->category->create_many( 2 );
    92108
    93         $found = wp_list_categories( array(
    94             'echo' => false,
    95             'show_option_all' => 'All',
    96             'hide_empty' => false,
    97             'taxonomy' => 'category',
    98         ) );
     109        $found = wp_list_categories(
     110            array(
     111                'echo'            => false,
     112                'show_option_all' => 'All',
     113                'hide_empty'      => false,
     114                'taxonomy'        => 'category',
     115            )
     116        );
    99117
    100118        $this->assertContains( "<li class='cat-item-all'><a href='" . home_url( '/' ) . "'>All</a></li>", $found );
     
    103121    public function test_show_option_all_link_should_respect_page_for_posts() {
    104122        $cats = self::factory()->category->create_many( 2 );
    105         $p = self::factory()->post->create( array( 'post_type' => 'page' ) );
     123        $p    = self::factory()->post->create( array( 'post_type' => 'page' ) );
    106124
    107125        update_option( 'show_on_front', 'page' );
    108126        update_option( 'page_for_posts', $p );
    109127
    110         $found = wp_list_categories( array(
    111             'echo' => false,
    112             'show_option_all' => 'All',
    113             'hide_empty' => false,
    114             'taxonomy' => 'category',
    115         ) );
     128        $found = wp_list_categories(
     129            array(
     130                'echo'            => false,
     131                'show_option_all' => 'All',
     132                'hide_empty'      => false,
     133                'taxonomy'        => 'category',
     134            )
     135        );
    116136
    117137        $this->assertContains( "<li class='cat-item-all'><a href='" . get_permalink( $p ) . "'>All</a></li>", $found );
     
    126146        register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'wptests_pt2' ) );
    127147
    128         $terms = self::factory()->term->create_many( 2, array(
    129             'taxonomy' => 'wptests_tax',
    130         ) );
    131 
    132         $found = wp_list_categories( array(
    133             'echo' => false,
    134             'show_option_all' => 'All',
    135             'hide_empty' => false,
    136             'taxonomy' => 'wptests_tax',
    137         ) );
     148        $terms = self::factory()->term->create_many(
     149            2, array(
     150                'taxonomy' => 'wptests_tax',
     151            )
     152        );
     153
     154        $found = wp_list_categories(
     155            array(
     156                'echo'            => false,
     157                'show_option_all' => 'All',
     158                'hide_empty'      => false,
     159                'taxonomy'        => 'wptests_tax',
     160            )
     161        );
    138162
    139163        $pt_archive = get_post_type_archive_link( 'wptests_pt' );
     
    150174        register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'wptests_pt2' ) );
    151175
    152         $terms = self::factory()->term->create_many( 2, array(
    153             'taxonomy' => 'wptests_tax',
    154         ) );
    155 
    156         $found = wp_list_categories( array(
    157             'echo' => false,
    158             'show_option_all' => 'All',
    159             'hide_empty' => false,
    160             'taxonomy' => 'wptests_tax',
    161         ) );
     176        $terms = self::factory()->term->create_many(
     177            2, array(
     178                'taxonomy' => 'wptests_tax',
     179            )
     180        );
     181
     182        $found = wp_list_categories(
     183            array(
     184                'echo'            => false,
     185                'show_option_all' => 'All',
     186                'hide_empty'      => false,
     187                'taxonomy'        => 'wptests_tax',
     188            )
     189        );
    162190
    163191        $pt_archive = get_post_type_archive_link( 'wptests_pt2' );
     
    171199        register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'post', 'wptests_pt2' ) );
    172200
    173         $terms = self::factory()->term->create_many( 2, array(
    174             'taxonomy' => 'wptests_tax',
    175         ) );
    176 
    177         $found = wp_list_categories( array(
    178             'echo' => false,
    179             'show_option_all' => 'All',
    180             'hide_empty' => false,
    181             'taxonomy' => 'wptests_tax',
    182         ) );
     201        $terms = self::factory()->term->create_many(
     202            2, array(
     203                'taxonomy' => 'wptests_tax',
     204            )
     205        );
     206
     207        $found = wp_list_categories(
     208            array(
     209                'echo'            => false,
     210                'show_option_all' => 'All',
     211                'hide_empty'      => false,
     212                'taxonomy'        => 'wptests_tax',
     213            )
     214        );
    183215
    184216        $url = home_url( '/' );
     
    192224        register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt', 'wptests_pt2' ) );
    193225
    194         $terms = self::factory()->term->create_many( 2, array(
    195             'taxonomy' => 'wptests_tax',
    196         ) );
    197 
    198         $found = wp_list_categories( array(
    199             'echo' => false,
    200             'show_option_all' => 'All',
    201             'hide_empty' => false,
    202             'taxonomy' => 'wptests_tax',
    203         ) );
     226        $terms = self::factory()->term->create_many(
     227            2, array(
     228                'taxonomy' => 'wptests_tax',
     229            )
     230        );
     231
     232        $found = wp_list_categories(
     233            array(
     234                'echo'            => false,
     235                'show_option_all' => 'All',
     236                'hide_empty'      => false,
     237                'taxonomy'        => 'wptests_tax',
     238            )
     239        );
    204240
    205241        $url = home_url( '/' );
     
    220256     */
    221257    public function test_title_li_should_be_shown_by_default_for_empty_lists() {
    222         $found = wp_list_categories( array(
    223             'echo' => false,
    224         ) );
     258        $found = wp_list_categories(
     259            array(
     260                'echo' => false,
     261            )
     262        );
    225263
    226264        $this->assertContains( '<li class="categories">Categories', $found );
     
    231269     */
    232270    public function test_hide_title_if_empty_should_be_respected_for_empty_lists_when_true() {
    233         $found = wp_list_categories( array(
    234             'echo' => false,
    235             'hide_title_if_empty' => true,
    236         ) );
     271        $found = wp_list_categories(
     272            array(
     273                'echo'                => false,
     274                'hide_title_if_empty' => true,
     275            )
     276        );
    237277
    238278        $this->assertNotContains( '<li class="categories">Categories', $found );
     
    243283     */
    244284    public function test_hide_title_if_empty_should_be_respected_for_empty_lists_when_false() {
    245         $found = wp_list_categories( array(
    246             'echo' => false,
    247             'hide_title_if_empty' => false,
    248         ) );
     285        $found = wp_list_categories(
     286            array(
     287                'echo'                => false,
     288                'hide_title_if_empty' => false,
     289            )
     290        );
    249291
    250292        $this->assertContains( '<li class="categories">Categories', $found );
     
    257299        $cat = self::factory()->category->create();
    258300
    259         $found = wp_list_categories( array(
    260             'echo' => false,
    261             'hide_empty' => false,
    262             'hide_title_if_empty' => true,
    263         ) );
     301        $found = wp_list_categories(
     302            array(
     303                'echo'                => false,
     304                'hide_empty'          => false,
     305                'hide_title_if_empty' => true,
     306            )
     307        );
    264308
    265309        $this->assertContains( '<li class="categories">Categories', $found );
     
    272316        $cat = self::factory()->category->create();
    273317
    274         $found = wp_list_categories( array(
    275             'echo' => false,
    276             'show_option_none' => '',
    277             'child_of' => 1,
    278             'hide_title_if_empty' => true,
    279         ) );
     318        $found = wp_list_categories(
     319            array(
     320                'echo'                => false,
     321                'show_option_none'    => '',
     322                'child_of'            => 1,
     323                'hide_title_if_empty' => true,
     324            )
     325        );
    280326
    281327        $this->assertNotContains( '</ul></li>', $found );
     
    286332     */
    287333    public function test_exclude_tree_should_be_respected() {
    288         $c = self::factory()->category->create();
    289         $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
    290         $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
    291 
    292         $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
     334        $c      = self::factory()->category->create();
     335        $parent = self::factory()->category->create(
     336            array(
     337                'name' => 'Parent',
     338                'slug' => 'parent',
     339            )
     340        );
     341        $child  = self::factory()->category->create(
     342            array(
     343                'name'   => 'Child',
     344                'slug'   => 'child',
     345                'parent' => $parent,
     346            )
     347        );
     348
     349        $args = array(
     350            'echo'         => 0,
     351            'hide_empty'   => 0,
     352            'exclude_tree' => $parent,
     353        );
    293354
    294355        $actual = wp_list_categories( $args );
     
    303364     */
    304365    public function test_exclude_tree_should_be_merged_with_exclude() {
    305         $c = self::factory()->category->create();
    306         $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
    307         $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
    308         $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
    309         $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
    310 
    311         $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
    312 
    313         $actual = wp_list_categories( array(
    314             'echo' => 0,
    315             'hide_empty' => 0,
    316             'exclude' => $parent,
    317             'exclude_tree' => $parent2,
    318         ) );
     366        $c       = self::factory()->category->create();
     367        $parent  = self::factory()->category->create(
     368            array(
     369                'name' => 'Parent',
     370                'slug' => 'parent',
     371            )
     372        );
     373        $child   = self::factory()->category->create(
     374            array(
     375                'name'   => 'Child',
     376                'slug'   => 'child',
     377                'parent' => $parent,
     378            )
     379        );
     380        $parent2 = self::factory()->category->create(
     381            array(
     382                'name' => 'Parent',
     383                'slug' => 'parent2',
     384            )
     385        );
     386        $child2  = self::factory()->category->create(
     387            array(
     388                'name'   => 'Child',
     389                'slug'   => 'child2',
     390                'parent' => $parent2,
     391            )
     392        );
     393
     394        $args = array(
     395            'echo'         => 0,
     396            'hide_empty'   => 0,
     397            'exclude_tree' => $parent,
     398        );
     399
     400        $actual = wp_list_categories(
     401            array(
     402                'echo'         => 0,
     403                'hide_empty'   => 0,
     404                'exclude'      => $parent,
     405                'exclude_tree' => $parent2,
     406            )
     407        );
    319408
    320409        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent . '">', $actual );
     
    329418     */
    330419    public function test_comma_separated_exclude_tree_should_be_merged_with_exclude() {
    331         $c = self::factory()->category->create();
    332         $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
    333         $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
    334         $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
    335         $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
    336         $parent3 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent3' ) );
    337         $child3 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child3', 'parent' => $parent3 ) );
    338         $parent4 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent4' ) );
    339         $child4 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child4', 'parent' => $parent4 ) );
    340 
    341 
    342         $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
    343 
    344         $actual = wp_list_categories( array(
    345             'echo' => 0,
    346             'hide_empty' => 0,
    347             'exclude' => "$parent,$parent2",
    348             'exclude_tree' => "$parent3,$parent4",
    349         ) );
     420        $c       = self::factory()->category->create();
     421        $parent  = self::factory()->category->create(
     422            array(
     423                'name' => 'Parent',
     424                'slug' => 'parent',
     425            )
     426        );
     427        $child   = self::factory()->category->create(
     428            array(
     429                'name'   => 'Child',
     430                'slug'   => 'child',
     431                'parent' => $parent,
     432            )
     433        );
     434        $parent2 = self::factory()->category->create(
     435            array(
     436                'name' => 'Parent',
     437                'slug' => 'parent2',
     438            )
     439        );
     440        $child2  = self::factory()->category->create(
     441            array(
     442                'name'   => 'Child',
     443                'slug'   => 'child2',
     444                'parent' => $parent2,
     445            )
     446        );
     447        $parent3 = self::factory()->category->create(
     448            array(
     449                'name' => 'Parent',
     450                'slug' => 'parent3',
     451            )
     452        );
     453        $child3  = self::factory()->category->create(
     454            array(
     455                'name'   => 'Child',
     456                'slug'   => 'child3',
     457                'parent' => $parent3,
     458            )
     459        );
     460        $parent4 = self::factory()->category->create(
     461            array(
     462                'name' => 'Parent',
     463                'slug' => 'parent4',
     464            )
     465        );
     466        $child4  = self::factory()->category->create(
     467            array(
     468                'name'   => 'Child',
     469                'slug'   => 'child4',
     470                'parent' => $parent4,
     471            )
     472        );
     473
     474        $args = array(
     475            'echo'         => 0,
     476            'hide_empty'   => 0,
     477            'exclude_tree' => $parent,
     478        );
     479
     480        $actual = wp_list_categories(
     481            array(
     482                'echo'         => 0,
     483                'hide_empty'   => 0,
     484                'exclude'      => "$parent,$parent2",
     485                'exclude_tree' => "$parent3,$parent4",
     486            )
     487        );
    350488
    351489        $this->assertContains( '<li class="cat-item cat-item-' . $c . '">', $actual );
     
    366504     */
    367505    public function test_array_exclude_tree_should_be_merged_with_exclude() {
    368         $c = self::factory()->category->create();
    369         $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
    370         $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
    371         $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
    372         $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
    373         $parent3 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent3' ) );
    374         $child3 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child3', 'parent' => $parent3 ) );
    375         $parent4 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent4' ) );
    376         $child4 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child4', 'parent' => $parent4 ) );
    377 
    378 
    379         $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
    380 
    381         $actual = wp_list_categories( array(
    382             'echo' => 0,
    383             'hide_empty' => 0,
    384             'exclude' => array( $parent, $parent2 ),
    385             'exclude_tree' => array( $parent3, $parent4 ),
    386         ) );
     506        $c       = self::factory()->category->create();
     507        $parent  = self::factory()->category->create(
     508            array(
     509                'name' => 'Parent',
     510                'slug' => 'parent',
     511            )
     512        );
     513        $child   = self::factory()->category->create(
     514            array(
     515                'name'   => 'Child',
     516                'slug'   => 'child',
     517                'parent' => $parent,
     518            )
     519        );
     520        $parent2 = self::factory()->category->create(
     521            array(
     522                'name' => 'Parent',
     523                'slug' => 'parent2',
     524            )
     525        );
     526        $child2  = self::factory()->category->create(
     527            array(
     528                'name'   => 'Child',
     529                'slug'   => 'child2',
     530                'parent' => $parent2,
     531            )
     532        );
     533        $parent3 = self::factory()->category->create(
     534            array(
     535                'name' => 'Parent',
     536                'slug' => 'parent3',
     537            )
     538        );
     539        $child3  = self::factory()->category->create(
     540            array(
     541                'name'   => 'Child',
     542                'slug'   => 'child3',
     543                'parent' => $parent3,
     544            )
     545        );
     546        $parent4 = self::factory()->category->create(
     547            array(
     548                'name' => 'Parent',
     549                'slug' => 'parent4',
     550            )
     551        );
     552        $child4  = self::factory()->category->create(
     553            array(
     554                'name'   => 'Child',
     555                'slug'   => 'child4',
     556                'parent' => $parent4,
     557            )
     558        );
     559
     560        $args = array(
     561            'echo'         => 0,
     562            'hide_empty'   => 0,
     563            'exclude_tree' => $parent,
     564        );
     565
     566        $actual = wp_list_categories(
     567            array(
     568                'echo'         => 0,
     569                'hide_empty'   => 0,
     570                'exclude'      => array( $parent, $parent2 ),
     571                'exclude_tree' => array( $parent3, $parent4 ),
     572            )
     573        );
    387574
    388575        $this->assertContains( '<li class="cat-item cat-item-' . $c . '">', $actual );
     
    403590     */
    404591    public function test_class_containing_current_cat_ancestor() {
    405         $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
    406         $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
    407         $child2 = self::factory()->category->create( array( 'name' => 'Child 2', 'slug' => 'child2', 'parent' => $parent ) );
    408         $grandchild = self::factory()->category->create( array( 'name' => 'Grand Child', 'slug' => 'child', 'parent' => $child ) );
    409 
    410         $actual = wp_list_categories( array(
    411             'echo'             => 0,
    412             'hide_empty'       => false,
    413             'current_category' => $grandchild,
    414         ) );
     592        $parent     = self::factory()->category->create(
     593            array(
     594                'name' => 'Parent',
     595                'slug' => 'parent',
     596            )
     597        );
     598        $child      = self::factory()->category->create(
     599            array(
     600                'name'   => 'Child',
     601                'slug'   => 'child',
     602                'parent' => $parent,
     603            )
     604        );
     605        $child2     = self::factory()->category->create(
     606            array(
     607                'name'   => 'Child 2',
     608                'slug'   => 'child2',
     609                'parent' => $parent,
     610            )
     611        );
     612        $grandchild = self::factory()->category->create(
     613            array(
     614                'name'   => 'Grand Child',
     615                'slug'   => 'child',
     616                'parent' => $child,
     617            )
     618        );
     619
     620        $actual = wp_list_categories(
     621            array(
     622                'echo'             => 0,
     623                'hide_empty'       => false,
     624                'current_category' => $grandchild,
     625            )
     626        );
    415627
    416628        $this->assertRegExp( '/class="[^"]*cat-item-' . $parent . '[^"]*current-cat-ancestor[^"]*"/', $actual );
Note: See TracChangeset for help on using the changeset viewer.