Make WordPress Core


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

    r38654 r42343  
    1212        /**
    1313         * @ticket 24785
    14          *
    1514         */
    1615        function test_nested_loop_reset_postdata() {
    17                 $post_id = self::factory()->post->create();
     16                $post_id        = self::factory()->post->create();
    1817                $nested_post_id = self::factory()->post->create();
    1918
    2019                $first_query = new WP_Query( array( 'post__in' => array( $post_id ) ) );
    21                 while ( $first_query->have_posts() ) { $first_query->the_post();
     20                while ( $first_query->have_posts() ) {
     21                        $first_query->the_post();
    2222                        $second_query = new WP_Query( array( 'post__in' => array( $nested_post_id ) ) );
    2323                        while ( $second_query->have_posts() ) {
    … …  
    9595                remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
    9696                register_taxonomy( 'wptests_tax', 'post' );
    97                 $terms = self::factory()->term->create_many( 2, array(
    98                         'taxonomy' => 'wptests_tax',
    99                 ) );
     97                $terms = self::factory()->term->create_many(
     98                        2, array(
     99                                'taxonomy' => 'wptests_tax',
     100                        )
     101                );
    100102
    101103                $posts = self::factory()->post->create_many( 2 );
    … …  
    105107
    106108                add_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) );
    107                 $q = new WP_Query( array(
    108                         'fields' => 'ids',
    109                         'wptests_tax' => $terms[1],
    110                 ) );
     109                $q = new WP_Query(
     110                        array(
     111                                'fields'      => 'ids',
     112                                'wptests_tax' => $terms[1],
     113                        )
     114                );
    111115
    112116                remove_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) );
    … …  
    125129                register_taxonomy( 'wptests_tax', 'post' );
    126130
    127                 $q = new WP_Query( array(
    128                         'tax_query' => array(
    129                                 array(
    130                                         'taxonomy' => 'wptests_tax',
    131                                         'operator' => 'NOT EXISTS',
     131                $q = new WP_Query(
     132                        array(
     133                                'tax_query' => array(
     134                                        array(
     135                                                'taxonomy' => 'wptests_tax',
     136                                                'operator' => 'NOT EXISTS',
     137                                        ),
    132138                                ),
    133                         ),
    134                 ) );
     139                        )
     140                );
    135141
    136142                $queried_object = $q->get_queried_object();
    … …  
    141147                global $wpdb;
    142148
    143                 $q = new WP_Query( array(
    144                         'orderby' => 'title date',
    145                         'order' => 'DESC',
    146                 ) );
     149                $q = new WP_Query(
     150                        array(
     151                                'orderby' => 'title date',
     152                                'order'   => 'DESC',
     153                        )
     154                );
    147155
    148156                $this->assertContains( "ORDER BY $wpdb->posts.post_title DESC, $wpdb->posts.post_date DESC", $q->request );
    … …  
    150158
    151159        public function test_cat_querystring_single_term() {
    152                 $c1 = self::factory()->category->create( array(
    153                         'name' => 'Test Category 1',
    154                         'slug' => 'test1',
    155                 ) );
    156                 $c2 = self::factory()->category->create( array(
    157                         'name' => 'Test Category 2',
    158                         'slug' => 'test2',
    159                 ) );
     160                $c1 = self::factory()->category->create(
     161                        array(
     162                                'name' => 'Test Category 1',
     163                                'slug' => 'test1',
     164                        )
     165                );
     166                $c2 = self::factory()->category->create(
     167                        array(
     168                                'name' => 'Test Category 2',
     169                                'slug' => 'test2',
     170                        )
     171                );
    160172
    161173                $p1 = self::factory()->post->create();
    … …  
    167179                wp_set_object_terms( $p3, $c2, 'category' );
    168180
    169                 $url = add_query_arg( array(
    170                         'cat' => $c1,
    171                 ), '/' );
     181                $url = add_query_arg(
     182                        array(
     183                                'cat' => $c1,
     184                        ), '/'
     185                );
    172186
    173187                $this->go_to( $url );
    … …  
    179193
    180194        public function test_category_querystring_multiple_terms_comma_separated() {
    181                 $c1 = self::factory()->category->create( array(
    182                         'name' => 'Test Category 1',
    183                         'slug' => 'test1',
    184                 ) );
    185                 $c2 = self::factory()->category->create( array(
    186                         'name' => 'Test Category 2',
    187                         'slug' => 'test2',
    188                 ) );
    189                 $c3 = self::factory()->category->create( array(
    190                         'name' => 'Test Category 3',
    191                         'slug' => 'test3',
    192                 ) );
     195                $c1 = self::factory()->category->create(
     196                        array(
     197                                'name' => 'Test Category 1',
     198                                'slug' => 'test1',
     199                        )
     200                );
     201                $c2 = self::factory()->category->create(
     202                        array(
     203                                'name' => 'Test Category 2',
     204                                'slug' => 'test2',
     205                        )
     206                );
     207                $c3 = self::factory()->category->create(
     208                        array(
     209                                'name' => 'Test Category 3',
     210                                'slug' => 'test3',
     211                        )
     212                );
    193213
    194214                $p1 = self::factory()->post->create();
    … …  
    202222                wp_set_object_terms( $p4, $c3, 'category' );
    203223
    204                 $url = add_query_arg( array(
    205                         'cat' => implode( ',',array( $c1,$c2 ) ),
    206                 ), '/' );
     224                $url = add_query_arg(
     225                        array(
     226                                'cat' => implode( ',', array( $c1, $c2 ) ),
     227                        ), '/'
     228                );
    207229
    208230                $this->go_to( $url );
    … …  
    217239         */
    218240        public function test_category_querystring_multiple_terms_formatted_as_array() {
    219                 $c1 = self::factory()->category->create( array(
    220                         'name' => 'Test Category 1',
    221                         'slug' => 'test1',
    222                 ) );
    223                 $c2 = self::factory()->category->create( array(
    224                         'name' => 'Test Category 2',
    225                         'slug' => 'test2',
    226                 ) );
    227                 $c3 = self::factory()->category->create( array(
    228                         'name' => 'Test Category 3',
    229                         'slug' => 'test3',
    230                 ) );
     241                $c1 = self::factory()->category->create(
     242                        array(
     243                                'name' => 'Test Category 1',
     244                                'slug' => 'test1',
     245                        )
     246                );
     247                $c2 = self::factory()->category->create(
     248                        array(
     249                                'name' => 'Test Category 2',
     250                                'slug' => 'test2',
     251                        )
     252                );
     253                $c3 = self::factory()->category->create(
     254                        array(
     255                                'name' => 'Test Category 3',
     256                                'slug' => 'test3',
     257                        )
     258                );
    231259
    232260                $p1 = self::factory()->post->create();
    … …  
    240268                wp_set_object_terms( $p4, $c3, 'category' );
    241269
    242                 $url = add_query_arg( array(
    243                         'cat' => array( $c1, $c2 ),
    244                 ), '/' );
     270                $url = add_query_arg(
     271                        array(
     272                                'cat' => array( $c1, $c2 ),
     273                        ), '/'
     274                );
    245275
    246276                $this->go_to( $url );
    … …  
    253283
    254284        public function test_tag_querystring_single_term() {
    255                 $t1 = self::factory()->tag->create_and_get( array(
    256                         'name' => 'Test Tag 1',
    257                         'slug' => 'test1',
    258                 ) );
    259                 $t2 = self::factory()->tag->create_and_get( array(
    260                         'name' => 'Test Tag 2',
    261                         'slug' => 'test2',
    262                 ) );
     285                $t1 = self::factory()->tag->create_and_get(
     286                        array(
     287                                'name' => 'Test Tag 1',
     288                                'slug' => 'test1',
     289                        )
     290                );
     291                $t2 = self::factory()->tag->create_and_get(
     292                        array(
     293                                'name' => 'Test Tag 2',
     294                                'slug' => 'test2',
     295                        )
     296                );
    263297
    264298                $p1 = self::factory()->post->create();
    … …  
    270304                wp_set_object_terms( $p3, $t2->slug, 'post_tag' );
    271305
    272                 $url = add_query_arg( array(
    273                         'tag' => $t1->slug,
    274                 ), '/' );
     306                $url = add_query_arg(
     307                        array(
     308                                'tag' => $t1->slug,
     309                        ), '/'
     310                );
    275311
    276312                $this->go_to( $url );
    … …  
    282318
    283319        public function test_tag_querystring_multiple_terms_comma_separated() {
    284                 $c1 = self::factory()->tag->create_and_get( array(
    285                         'name' => 'Test Tag 1',
    286                         'slug' => 'test1',
    287                 ) );
    288                 $c2 = self::factory()->tag->create_and_get( array(
    289                         'name' => 'Test Tag 2',
    290                         'slug' => 'test2',
    291                 ) );
    292                 $c3 = self::factory()->tag->create_and_get( array(
    293                         'name' => 'Test Tag 3',
    294                         'slug' => 'test3',
    295                 ) );
     320                $c1 = self::factory()->tag->create_and_get(
     321                        array(
     322                                'name' => 'Test Tag 1',
     323                                'slug' => 'test1',
     324                        )
     325                );
     326                $c2 = self::factory()->tag->create_and_get(
     327                        array(
     328                                'name' => 'Test Tag 2',
     329                                'slug' => 'test2',
     330                        )
     331                );
     332                $c3 = self::factory()->tag->create_and_get(
     333                        array(
     334                                'name' => 'Test Tag 3',
     335                                'slug' => 'test3',
     336                        )
     337                );
    296338
    297339                $p1 = self::factory()->post->create();
    … …  
    305347                wp_set_object_terms( $p4, $c3->slug, 'post_tag' );
    306348
    307                 $url = add_query_arg( array(
    308                         'tag' => implode( ',',array( $c1->slug,$c2->slug ) ),
    309                 ), '/' );
     349                $url = add_query_arg(
     350                        array(
     351                                'tag' => implode( ',', array( $c1->slug, $c2->slug ) ),
     352                        ), '/'
     353                );
    310354
    311355                $this->go_to( $url );
    … …  
    320364         */
    321365        public function test_tag_querystring_multiple_terms_formatted_as_array() {
    322                 $c1 = self::factory()->tag->create_and_get( array(
    323                         'name' => 'Test Tag 1',
    324                         'slug' => 'test1',
    325                 ) );
    326                 $c2 = self::factory()->tag->create_and_get( array(
    327                         'name' => 'Test Tag 2',
    328                         'slug' => 'test2',
    329                 ) );
    330                 $c3 = self::factory()->tag->create_and_get( array(
    331                         'name' => 'Test Tag 3',
    332                         'slug' => 'test3',
    333                 ) );
     366                $c1 = self::factory()->tag->create_and_get(
     367                        array(
     368                                'name' => 'Test Tag 1',
     369                                'slug' => 'test1',
     370                        )
     371                );
     372                $c2 = self::factory()->tag->create_and_get(
     373                        array(
     374                                'name' => 'Test Tag 2',
     375                                'slug' => 'test2',
     376                        )
     377                );
     378                $c3 = self::factory()->tag->create_and_get(
     379                        array(
     380                                'name' => 'Test Tag 3',
     381                                'slug' => 'test3',
     382                        )
     383                );
    334384
    335385                $p1 = self::factory()->post->create();
    … …  
    343393                wp_set_object_terms( $p4, $c3->slug, 'post_tag' );
    344394
    345                 $url = add_query_arg( array(
    346                         'tag' => array($c1->slug,$c2->slug),
    347                 ), '/' );
     395                $url = add_query_arg(
     396                        array(
     397                                'tag' => array( $c1->slug, $c2->slug ),
     398                        ), '/'
     399                );
    348400
    349401                $this->go_to( $url );
    … …  
    369421                wp_set_object_terms( $p3, 'test2', 'test_tax_cat' );
    370422
    371                 $url = add_query_arg( array(
    372                         'test_tax_cat' => 'test1',
    373                 ), '/' );
     423                $url = add_query_arg(
     424                        array(
     425                                'test_tax_cat' => 'test1',
     426                        ), '/'
     427                );
    374428
    375429                $this->go_to( $url );
    … …  
    393447                wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' );
    394448                wp_set_object_terms( $p3, 'test2', 'test_tax_cat' );
    395                 wp_set_object_terms( $p4, "test3", 'test_tax_cat' );
    396 
    397                 $url = add_query_arg( array(
    398                         'test_tax_cat' => 'test1,test2',
    399                 ), '/' );
     449                wp_set_object_terms( $p4, 'test3', 'test_tax_cat' );
     450
     451                $url = add_query_arg(
     452                        array(
     453                                'test_tax_cat' => 'test1,test2',
     454                        ), '/'
     455                );
    400456
    401457                $this->go_to( $url );
    … …  
    422478                wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' );
    423479                wp_set_object_terms( $p3, 'test2', 'test_tax_cat' );
    424                 wp_set_object_terms( $p4, "test3", 'test_tax_cat' );
    425 
    426                 $url = add_query_arg( array(
    427                         'test_tax_cat' => array( 'test1', 'test2' ),
    428                 ), '/' );
     480                wp_set_object_terms( $p4, 'test3', 'test_tax_cat' );
     481
     482                $url = add_query_arg(
     483                        array(
     484                                'test_tax_cat' => array( 'test1', 'test2' ),
     485                        ), '/'
     486                );
    429487
    430488                $this->go_to( $url );
    … …  
    437495         */
    438496        public function test_pages_dont_404_when_queried_post_id_is_modified() {
    439                 $post_id = self::factory()->post->create( array( 'post_title' => 'A Test Page', 'post_type' => 'page' ) );
     497                $post_id = self::factory()->post->create(
     498                        array(
     499                                'post_title' => 'A Test Page',
     500                                'post_type'  => 'page',
     501                        )
     502                );
    440503
    441504                add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) );
    … …  
    456519                global $wp_rewrite;
    457520
    458                 register_post_type( 'guide', array( 'name' => 'Guide', 'public' => true, 'hierarchical' => true ) );
     521                register_post_type(
     522                        'guide', array(
     523                                'name'         => 'Guide',
     524                                'public'       => true,
     525                                'hierarchical' => true,
     526                        )
     527                );
    459528                $wp_rewrite->flush_rules();
    460                 $post_id = self::factory()->post->create( array( 'post_title' => 'A Test Guide', 'post_type' => 'guide' ) );
     529                $post_id = self::factory()->post->create(
     530                        array(
     531                                'post_title' => 'A Test Guide',
     532                                'post_type'  => 'guide',
     533                        )
     534                );
    461535
    462536                add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) );
    … …  
    479553         */
    480554        public function test_offset_0_should_override_page() {
    481                 $q = new WP_Query( array(
    482                         'paged' => 2,
    483                         'posts_per_page' => 5,
    484                         'offset' => 0,
    485                 ) );
     555                $q = new WP_Query(
     556                        array(
     557                                'paged'          => 2,
     558                                'posts_per_page' => 5,
     559                                'offset'         => 0,
     560                        )
     561                );
    486562
    487563                $this->assertContains( 'LIMIT 0, 5', $q->request );
    … …  
    492568         */
    493569        public function test_offset_should_be_ignored_when_not_set() {
    494                 $q = new WP_Query( array(
    495                         'paged' => 2,
    496                         'posts_per_page' => 5,
    497                 ) );
     570                $q = new WP_Query(
     571                        array(
     572                                'paged'          => 2,
     573                                'posts_per_page' => 5,
     574                        )
     575                );
    498576
    499577                $this->assertContains( 'LIMIT 5, 5', $q->request );
    … …  
    504582         */
    505583        public function test_offset_should_be_ignored_when_passed_a_non_numeric_value() {
    506                 $q = new WP_Query( array(
    507                         'paged' => 2,
    508                         'posts_per_page' => 5,
    509                         'offset' => '',
    510                 ) );
     584                $q = new WP_Query(
     585                        array(
     586                                'paged'          => 2,
     587                                'posts_per_page' => 5,
     588                                'offset'         => '',
     589                        )
     590                );
    511591
    512592                $this->assertContains( 'LIMIT 5, 5', $q->request );
    … …  
    520600                $p2 = self::factory()->post->create( array( 'comment_status' => 'closed' ) );
    521601
    522                 $q = new WP_Query( array(
    523                         'fields' => 'ids',
    524                         'comment_status' => 'closed',
    525                 ) );
     602                $q = new WP_Query(
     603                        array(
     604                                'fields'         => 'ids',
     605                                'comment_status' => 'closed',
     606                        )
     607                );
    526608
    527609                $this->assertSame( array( $p2 ), $q->posts );
    … …  
    535617                $p2 = self::factory()->post->create( array( 'ping_status' => 'closed' ) );
    536618
    537                 $q = new WP_Query( array(
    538                         'fields' => 'ids',
    539                         'ping_status' => 'closed',
    540                 ) );
     619                $q = new WP_Query(
     620                        array(
     621                                'fields'      => 'ids',
     622                                'ping_status' => 'closed',
     623                        )
     624                );
    541625
    542626                $this->assertSame( array( $p2 ), $q->posts );
    … …  
    550634                register_taxonomy( 'tax2', 'post' );
    551635
    552                 $term1 = $this->factory->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1' ) );
    553                 $term2 = $this->factory->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2' ) );
     636                $term1   = $this->factory->term->create(
     637                        array(
     638                                'taxonomy' => 'tax1',
     639                                'name'     => 'term1',
     640                        )
     641                );
     642                $term2   = $this->factory->term->create(
     643                        array(
     644                                'taxonomy' => 'tax2',
     645                                'name'     => 'term2',
     646                        )
     647                );
    554648                $post_id = $this->factory->post->create();
    555649                wp_set_object_terms( $post_id, 'term1', 'tax1' );
    … …  
    570664                register_taxonomy( 'tax2', 'post' );
    571665
    572                 $term1 = $this->factory->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1' ) );
    573                 $term2 = $this->factory->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2' ) );
     666                $term1   = $this->factory->term->create(
     667                        array(
     668                                'taxonomy' => 'tax1',
     669                                'name'     => 'term1',
     670                        )
     671                );
     672                $term2   = $this->factory->term->create(
     673                        array(
     674                                'taxonomy' => 'tax2',
     675                                'name'     => 'term2',
     676                        )
     677                );
    574678                $post_id = $this->factory->post->create();
    575679                wp_set_object_terms( $post_id, 'term1', 'tax1' );
Note: See TracChangeset for help on using the changeset viewer.