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/term/query.php

    r42209 r42343  
    1515        $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) );
    1616
    17         $q = new WP_Term_Query( array(
    18             'taxonomy' => 'wptests_tax_2',
    19             'fields' => 'ids',
    20             'hide_empty' => false,
    21         ) );
     17        $q = new WP_Term_Query(
     18            array(
     19                'taxonomy'   => 'wptests_tax_2',
     20                'fields'     => 'ids',
     21                'hide_empty' => false,
     22            )
     23        );
    2224
    2325        $this->assertEqualSets( array( $term_2 ), $q->terms );
     
    3133        $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) );
    3234
    33         $q = new WP_Term_Query( array(
    34             'taxonomy' => array( 'wptests_tax_2' ),
    35             'fields' => 'ids',
    36             'hide_empty' => false,
    37         ) );
     35        $q = new WP_Term_Query(
     36            array(
     37                'taxonomy'   => array( 'wptests_tax_2' ),
     38                'fields'     => 'ids',
     39                'hide_empty' => false,
     40            )
     41        );
    3842
    3943        $this->assertEqualSets( array( $term_2 ), $q->terms );
     
    5761        );
    5862
    59         $q = new WP_Term_Query( array(
    60             'term_taxonomy_id' => 12345,
    61             'fields' => 'ids',
    62             'hide_empty' => false,
    63         ) );
     63        $q = new WP_Term_Query(
     64            array(
     65                'term_taxonomy_id' => 12345,
     66                'fields'           => 'ids',
     67                'hide_empty'       => false,
     68            )
     69        );
    6470
    6571        $this->assertEqualSets( array( $terms[0] ), $q->terms );
     
    8995        );
    9096
    91         $q = new WP_Term_Query( array(
    92             'term_taxonomy_id' => array( 12345, 6789 ),
    93             'fields' => 'ids',
    94             'hide_empty' => false,
    95         ) );
     97        $q = new WP_Term_Query(
     98            array(
     99                'term_taxonomy_id' => array( 12345, 6789 ),
     100                'fields'           => 'ids',
     101                'hide_empty'       => false,
     102            )
     103        );
    96104
    97105        $this->assertEqualSets( array( $terms[0], $terms[2] ), $q->terms );
     
    110118        add_term_meta( $terms[2], 'foo', 100 );
    111119
    112         $q = new WP_Term_Query( array(
    113             'taxonomy' => array( 'wptests_tax' ),
    114             'fields' => 'ids',
    115             'hide_empty' => false,
    116             'meta_key' => 'foo',
    117             'orderby' => 'meta_value_num',
    118         ) );
     120        $q = new WP_Term_Query(
     121            array(
     122                'taxonomy'   => array( 'wptests_tax' ),
     123                'fields'     => 'ids',
     124                'hide_empty' => false,
     125                'meta_key'   => 'foo',
     126                'orderby'    => 'meta_value_num',
     127            )
     128        );
    119129
    120130        $found = array_map( 'intval', $q->terms );
     
    129139
    130140        add_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) );
    131         $q = new WP_Term_Query( array(
    132             'taxonomy' => array( 'wptests_tax' ),
    133             'orderby' => 'name',
    134         ) );
     141        $q = new WP_Term_Query(
     142            array(
     143                'taxonomy' => array( 'wptests_tax' ),
     144                'orderby'  => 'name',
     145            )
     146        );
    135147        remove_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) );
    136148
     
    152164        sort( $terms );
    153165
    154         $q = new WP_Term_Query( array(
    155             'taxonomy' => 'wptests_tax',
    156             'orderby' => 'term_order',
    157             'fields' => 'ids',
    158             'hide_empty' => false,
    159         ) );
     166        $q = new WP_Term_Query(
     167            array(
     168                'taxonomy'   => 'wptests_tax',
     169                'orderby'    => 'term_order',
     170                'fields'     => 'ids',
     171                'hide_empty' => false,
     172            )
     173        );
    160174
    161175        $this->assertSame( $terms, $q->get_terms() );
     
    170184        self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
    171185
    172         $q1 = new WP_Term_Query( array(
    173             'taxonomy' => 'wptests_tax_1',
    174             'hide_empty' => false
    175         ) );
     186        $q1 = new WP_Term_Query(
     187            array(
     188                'taxonomy'   => 'wptests_tax_1',
     189                'hide_empty' => false,
     190            )
     191        );
    176192
    177193        $this->assertNotEmpty( $q1->terms );
    178194
    179         $q2 = new WP_Term_Query( array(
    180             'taxonomy' => 'wptests_tax_1',
    181             'hide_empty' => false
    182         ) );
     195        $q2 = new WP_Term_Query(
     196            array(
     197                'taxonomy'   => 'wptests_tax_1',
     198                'hide_empty' => false,
     199            )
     200        );
    183201
    184202        $this->assertNotEmpty( $q2->terms );
     
    195213        $t2 = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax_1' ) );
    196214
    197         $query = new WP_Term_Query( array(
    198             'include' => "{$t1->term_id},{$t2->term_id}",
    199             'orderby' => 'include',
    200             'hide_empty' => false,
    201         ) );
     215        $query = new WP_Term_Query(
     216            array(
     217                'include'    => "{$t1->term_id},{$t2->term_id}",
     218                'orderby'    => 'include',
     219                'hide_empty' => false,
     220            )
     221        );
    202222        $terms = $query->get_terms();
    203223
     
    216236        wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
    217237
    218         $query = new WP_Term_Query( array(
    219             'taxonomy' => 'wptests_tax_1',
    220             'object_ids' => $p,
    221             'fields' => 'ids',
    222         ) );
     238        $query = new WP_Term_Query(
     239            array(
     240                'taxonomy'   => 'wptests_tax_1',
     241                'object_ids' => $p,
     242                'fields'     => 'ids',
     243            )
     244        );
    223245
    224246        $this->assertEqualSets( array( $t ), $query->terms );
     
    236258        wp_set_object_terms( $p, array( $t ), 'wptests_tax_1' );
    237259
    238         $query = new WP_Term_Query( array(
    239             'taxonomy' => 'wptests_tax_1',
    240             'object_ids' => array( $p ),
    241             'fields' => 'ids',
    242         ) );
     260        $query = new WP_Term_Query(
     261            array(
     262                'taxonomy'   => 'wptests_tax_1',
     263                'object_ids' => array( $p ),
     264                'fields'     => 'ids',
     265            )
     266        );
    243267
    244268        $this->assertEqualSets( array( $t ), $query->terms );
     
    251275        register_taxonomy( 'wptests_tax_1', 'post' );
    252276        $posts = self::factory()->post->create_many( 2 );
    253         $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
     277        $t     = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
    254278
    255279        foreach ( $posts as $p ) {
     
    257281        }
    258282
    259         $query = new WP_Term_Query( array(
    260             'taxonomy' => 'wptests_tax_1',
    261             'object_ids' => $posts,
    262             'fields' => 'all',
    263         ) );
     283        $query = new WP_Term_Query(
     284            array(
     285                'taxonomy'   => 'wptests_tax_1',
     286                'object_ids' => $posts,
     287                'fields'     => 'all',
     288            )
     289        );
    264290
    265291        $this->assertSame( 1, count( $query->terms ) );
     
    273299        register_taxonomy( 'wptests_tax_1', 'post' );
    274300        $posts = self::factory()->post->create_many( 2 );
    275         $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
     301        $t     = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) );
    276302
    277303        foreach ( $posts as $p ) {
     
    279305        }
    280306
    281         $query = new WP_Term_Query( array(
    282             'taxonomy' => 'wptests_tax_1',
    283             'object_ids' => $posts,
    284             'fields' => 'all_with_object_id',
    285         ) );
     307        $query = new WP_Term_Query(
     308            array(
     309                'taxonomy'   => 'wptests_tax_1',
     310                'object_ids' => $posts,
     311                'fields'     => 'all_with_object_id',
     312            )
     313        );
    286314
    287315        $this->assertSame( 2, count( $query->terms ) );
     
    298326        register_taxonomy( 'wptests_tax_1', 'post' );
    299327
    300         $p = self::factory()->post->create();
     328        $p     = self::factory()->post->create();
    301329        $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) );
    302330
    303331        wp_set_object_terms( $p, array( $terms[0] ), 'wptests_tax_1' );
    304332
    305         $query = new WP_Term_Query( array(
    306             'taxonomy' => 'wptests_tax_1',
    307             'object_ids' => $p,
    308             'fields' => 'ids',
    309         ) );
     333        $query = new WP_Term_Query(
     334            array(
     335                'taxonomy'   => 'wptests_tax_1',
     336                'object_ids' => $p,
     337                'fields'     => 'ids',
     338            )
     339        );
    310340        $found = $query->get_terms();
    311341
     
    314344        wp_set_object_terms( $p, array( $terms[1] ), 'wptests_tax_1' );
    315345
    316         $query = new WP_Term_Query( array(
    317             'taxonomy' => 'wptests_tax_1',
    318             'object_ids' => $p,
    319             'fields' => 'ids',
    320         ) );
     346        $query = new WP_Term_Query(
     347            array(
     348                'taxonomy'   => 'wptests_tax_1',
     349                'object_ids' => $p,
     350                'fields'     => 'ids',
     351            )
     352        );
    321353        $found = $query->get_terms();
    322354
     
    335367        $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) );
    336368
    337         $query = new WP_Term_Query( array(
    338             'taxonomy' => 'wptests_tax_1',
    339             'fields' => 'count',
    340             'hide_empty' => false,
    341         ) );
     369        $query = new WP_Term_Query(
     370            array(
     371                'taxonomy'   => 'wptests_tax_1',
     372                'fields'     => 'count',
     373                'hide_empty' => false,
     374            )
     375        );
    342376        $count = $query->get_terms();
    343377        $this->assertEquals( 2, $count );
     
    345379        $num_queries = $wpdb->num_queries;
    346380
    347         $query = new WP_Term_Query( array(
    348             'taxonomy' => 'wptests_tax_1',
    349             'fields' => 'count',
    350             'hide_empty' => false,
    351         ) );
     381        $query = new WP_Term_Query(
     382            array(
     383                'taxonomy'   => 'wptests_tax_1',
     384                'fields'     => 'count',
     385                'hide_empty' => false,
     386            )
     387        );
    352388        $count = $query->get_terms();
    353389        $this->assertEquals( 2, $count );
     
    364400        $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) );
    365401
    366         $query = new WP_Term_Query( array(
    367             'taxonomy' => 'wptests_tax_1',
    368             'fields' => 'count',
    369             'hide_empty' => false,
    370         ) );
     402        $query = new WP_Term_Query(
     403            array(
     404                'taxonomy'   => 'wptests_tax_1',
     405                'fields'     => 'count',
     406                'hide_empty' => false,
     407            )
     408        );
    371409        $count = $query->get_terms();
    372410        $this->assertEquals( 2, $count );
     
    374412        wp_delete_term( $terms[0], 'wptests_tax_1' );
    375413
    376         $query = new WP_Term_Query( array(
    377             'taxonomy' => 'wptests_tax_1',
    378             'fields' => 'count',
    379             'hide_empty' => false,
    380         ) );
     414        $query = new WP_Term_Query(
     415            array(
     416                'taxonomy'   => 'wptests_tax_1',
     417                'fields'     => 'count',
     418                'hide_empty' => false,
     419            )
     420        );
    381421        $count = $query->get_terms();
    382422        $this->assertEquals( 1, $count );
     
    387427     */
    388428    public function test_get_the_terms_should_respect_taxonomy_orderby() {
    389         register_taxonomy( 'wptests_tax', 'post', array(
    390             'sort' => true,
    391             'args' => array(
    392                 'orderby' => 'term_order',
    393             ),
    394         ) );
    395         $term_ids = self::factory()->term->create_many( 2, array(
    396             'taxonomy' => 'wptests_tax',
    397         ) );
    398         $post_id = self::factory()->post->create();
     429        register_taxonomy(
     430            'wptests_tax', 'post', array(
     431                'sort' => true,
     432                'args' => array(
     433                    'orderby' => 'term_order',
     434                ),
     435            )
     436        );
     437        $term_ids = self::factory()->term->create_many(
     438            2, array(
     439                'taxonomy' => 'wptests_tax',
     440            )
     441        );
     442        $post_id  = self::factory()->post->create();
    399443        wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' );
    400444        $terms = get_the_terms( $post_id, 'wptests_tax' );
     
    410454     */
    411455    public function test_wp_get_object_terms_should_respect_taxonomy_orderby() {
    412         register_taxonomy( 'wptests_tax', 'post', array(
    413             'sort' => true,
    414             'args' => array(
    415                 'orderby' => 'term_order',
    416             ),
    417         ) );
    418         $term_ids = self::factory()->term->create_many( 2, array(
    419             'taxonomy' => 'wptests_tax',
    420         ) );
    421         $post_id = self::factory()->post->create();
     456        register_taxonomy(
     457            'wptests_tax', 'post', array(
     458                'sort' => true,
     459                'args' => array(
     460                    'orderby' => 'term_order',
     461                ),
     462            )
     463        );
     464        $term_ids = self::factory()->term->create_many(
     465            2, array(
     466                'taxonomy' => 'wptests_tax',
     467            )
     468        );
     469        $post_id  = self::factory()->post->create();
    422470        wp_set_object_terms( $post_id, array( $term_ids[0], $term_ids[1] ), 'wptests_tax' );
    423471        $terms = wp_get_object_terms( $post_id, array( 'category', 'wptests_tax' ) );
     
    435483        register_post_type( 'wptests_pt' );
    436484        register_taxonomy( 'wptests_tax', 'wptests_pt' );
    437         $t1 = self::factory()->term->create( array(
    438             'taxonomy' => 'wptests_tax',
    439             'name' => 'foo',
    440             'slug' => 'bar',
    441         ) );
    442         $t2 = self::factory()->term->create( array(
    443             'taxonomy' => 'wptests_tax',
    444             'name' => 'bar',
    445             'slug' => 'foo',
    446         ) );
    447 
    448         $p = self::factory()->post->create( array(
    449             'post_type' => 'wptests_pt',
    450         ) );
     485        $t1 = self::factory()->term->create(
     486            array(
     487                'taxonomy' => 'wptests_tax',
     488                'name'     => 'foo',
     489                'slug'     => 'bar',
     490            )
     491        );
     492        $t2 = self::factory()->term->create(
     493            array(
     494                'taxonomy' => 'wptests_tax',
     495                'name'     => 'bar',
     496                'slug'     => 'foo',
     497            )
     498        );
     499
     500        $p = self::factory()->post->create(
     501            array(
     502                'post_type' => 'wptests_pt',
     503            )
     504        );
    451505
    452506        wp_set_object_terms( $p, array( $t1, $t2 ), 'wptests_tax' );
    453507
    454         $expected = wp_get_post_terms( $p, 'wptests_tax', array(
    455             'fields' => 'ids',
    456         ) );
    457 
    458         $found1 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
    459             'fields' => 'id=>parent',
    460         ) ) );
    461 
    462         $found2 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
    463             'fields' => 'id=>slug',
    464         ) ) );
    465 
    466         $found3 = array_keys( wp_get_object_terms( $p, 'wptests_tax', array(
    467             'fields' => 'id=>name',
    468         ) ) );
     508        $expected = wp_get_post_terms(
     509            $p, 'wptests_tax', array(
     510                'fields' => 'ids',
     511            )
     512        );
     513
     514        $found1 = array_keys(
     515            wp_get_object_terms(
     516                $p, 'wptests_tax', array(
     517                    'fields' => 'id=>parent',
     518                )
     519            )
     520        );
     521
     522        $found2 = array_keys(
     523            wp_get_object_terms(
     524                $p, 'wptests_tax', array(
     525                    'fields' => 'id=>slug',
     526                )
     527            )
     528        );
     529
     530        $found3 = array_keys(
     531            wp_get_object_terms(
     532                $p, 'wptests_tax', array(
     533                    'fields' => 'id=>name',
     534                )
     535            )
     536        );
    469537
    470538        $this->assertSame( $expected, $found1 );
     
    482550        register_taxonomy( 'wptests_tax', 'post' );
    483551
    484         $term_id = self::factory()->term->create( array(
    485             'taxonomy' => 'wptests_tax',
    486         ) );
     552        $term_id = self::factory()->term->create(
     553            array(
     554                'taxonomy' => 'wptests_tax',
     555            )
     556        );
    487557        wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' );
    488558
    489         $q = new WP_Term_Query();
     559        $q    = new WP_Term_Query();
    490560        $args = array(
    491561            'taxonomy' => 'wptests_tax',
     
    505575        register_taxonomy( 'wptests_tax', 'post' );
    506576
    507         $term_id = self::factory()->term->create( array(
    508             'taxonomy' => 'wptests_tax',
    509         ) );
     577        $term_id = self::factory()->term->create(
     578            array(
     579                'taxonomy' => 'wptests_tax',
     580            )
     581        );
    510582        wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' );
    511583
    512         $q = new WP_Term_Query();
     584        $q    = new WP_Term_Query();
    513585        $args = array(
    514586            'taxonomy' => 'wptests_tax',
     
    528600        register_taxonomy( 'wptests_tax', 'post' );
    529601
    530         $term_id = self::factory()->term->create( array(
    531             'taxonomy' => 'wptests_tax',
    532         ) );
     602        $term_id = self::factory()->term->create(
     603            array(
     604                'taxonomy' => 'wptests_tax',
     605            )
     606        );
    533607        wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' );
    534608
    535         $q = new WP_Term_Query( array(
    536             'taxonomy' => 'wptests_tax',
    537             'parent'   => $term_id,
    538         ) );
     609        $q = new WP_Term_Query(
     610            array(
     611                'taxonomy' => 'wptests_tax',
     612                'parent'   => $term_id,
     613            )
     614        );
    539615        $this->assertSame( array(), $q->terms );
    540616    }
Note: See TracChangeset for help on using the changeset viewer.