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/comment/getPageOfComment.php

    r39663 r42343  
    2929                $comment_first = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-14 00:00:00' ) );
    3030
    31                 $this->assertEquals( 4, get_page_of_comment( $comment_last[0],  array( 'per_page' => 3 ) ) );
    32                 $this->assertEquals( 2, get_page_of_comment( $comment_last[0],  array( 'per_page' => 10 ) ) );
    33 
    34                 $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' =>  3 ) ) );
     31                $this->assertEquals( 4, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) );
     32                $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 10 ) ) );
     33
     34                $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 3 ) ) );
    3535                $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 10 ) ) );
    3636        }
    3737
    3838        public function test_type_pings() {
    39                 $p = self::factory()->post->create();
     39                $p   = self::factory()->post->create();
    4040                $now = time();
    4141
    4242                $trackbacks = array();
    4343                for ( $i = 0; $i <= 3; $i++ ) {
    44                         $trackbacks[ $i ] = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'trackback', 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
    45                         $now -= 10 * $i;
     44                        $trackbacks[ $i ] = self::factory()->comment->create(
     45                                array(
     46                                        'comment_post_ID'  => $p,
     47                                        'comment_type'     => 'trackback',
     48                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     49                                )
     50                        );
     51                        $now             -= 10 * $i;
    4652                }
    4753
    4854                $pingbacks = array();
    4955                for ( $i = 0; $i <= 6; $i++ ) {
    50                         $pingbacks[ $i ] = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'pingback', 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
    51                         $now -= 10 * $i;
    52                 }
    53 
    54                 $this->assertEquals( 2, get_page_of_comment( $trackbacks[0], array( 'per_page' => 2, 'type' => 'trackback' ) ) );
    55                 $this->assertEquals( 3, get_page_of_comment( $pingbacks[0], array( 'per_page' => 2, 'type' => 'pingback' ) ) );
    56                 $this->assertEquals( 5, get_page_of_comment( $trackbacks[0], array( 'per_page' => 2, 'type' => 'pings' ) ) );
     56                        $pingbacks[ $i ] = self::factory()->comment->create(
     57                                array(
     58                                        'comment_post_ID'  => $p,
     59                                        'comment_type'     => 'pingback',
     60                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     61                                )
     62                        );
     63                        $now            -= 10 * $i;
     64                }
     65
     66                $this->assertEquals(
     67                        2, get_page_of_comment(
     68                                $trackbacks[0], array(
     69                                        'per_page' => 2,
     70                                        'type'     => 'trackback',
     71                                )
     72                        )
     73                );
     74                $this->assertEquals(
     75                        3, get_page_of_comment(
     76                                $pingbacks[0], array(
     77                                        'per_page' => 2,
     78                                        'type'     => 'pingback',
     79                                )
     80                        )
     81                );
     82                $this->assertEquals(
     83                        5, get_page_of_comment(
     84                                $trackbacks[0], array(
     85                                        'per_page' => 2,
     86                                        'type'     => 'pings',
     87                                )
     88                        )
     89                );
    5790        }
    5891
     
    70103
    71104                $num_queries = $wpdb->num_queries;
    72                 $page_2 = get_page_of_comment( $c, array( 'per_page' => 3 ) );
     105                $page_2      = get_page_of_comment( $c, array( 'per_page' => 3 ) );
    73106
    74107                $this->assertSame( $page_1, $page_2 );
     
    82115                global $wpdb;
    83116
    84                 $p = self::factory()->post->create();
    85                 $comment = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'comment' ) );
    86 
    87                 $now = time();
     117                $p       = self::factory()->post->create();
     118                $comment = self::factory()->comment->create(
     119                        array(
     120                                'comment_post_ID' => $p,
     121                                'comment_type'    => 'comment',
     122                        )
     123                );
     124
     125                $now        = time();
    88126                $trackbacks = array();
    89127                for ( $i = 0; $i <= 5; $i++ ) {
    90                         $trackbacks[ $i ] = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'trackback', 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( 10 * $i ) ) ) );
     128                        $trackbacks[ $i ] = self::factory()->comment->create(
     129                                array(
     130                                        'comment_post_ID'  => $p,
     131                                        'comment_type'     => 'trackback',
     132                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( 10 * $i ) ),
     133                                )
     134                        );
    91135                }
    92136
    93137                // Prime cache for trackbacks.
    94                 $page_trackbacks = get_page_of_comment( $trackbacks[1], array( 'per_page' => 3, 'type' => 'trackback' ) );
     138                $page_trackbacks = get_page_of_comment(
     139                        $trackbacks[1], array(
     140                                'per_page' => 3,
     141                                'type'     => 'trackback',
     142                        )
     143                );
    95144                $this->assertEquals( 2, $page_trackbacks );
    96145
    97                 $num_queries = $wpdb->num_queries;
    98                 $page_comments = get_page_of_comment( $comment, array( 'per_page' => 3, 'type' => 'comment' ) );
     146                $num_queries   = $wpdb->num_queries;
     147                $page_comments = get_page_of_comment(
     148                        $comment, array(
     149                                'per_page' => 3,
     150                                'type'     => 'comment',
     151                        )
     152                );
    99153                $this->assertEquals( 1, $page_comments );
    100154
     
    107161        public function test_cache_should_be_invalidated_when_comment_is_approved() {
    108162                $p = self::factory()->post->create();
    109                 $c = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => 0 ) );
     163                $c = self::factory()->comment->create(
     164                        array(
     165                                'comment_post_ID'  => $p,
     166                                'comment_approved' => 0,
     167                        )
     168                );
    110169
    111170                // Prime cache.
     
    156215                $now = time();
    157216
    158                 $p = self::factory()->post->create();
    159                 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
    160                 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) );
    161                 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => 0, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) );
     217                $p  = self::factory()->post->create();
     218                $c1 = self::factory()->comment->create(
     219                        array(
     220                                'comment_post_ID'  => $p,
     221                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     222                        )
     223                );
     224                $c2 = self::factory()->comment->create(
     225                        array(
     226                                'comment_post_ID'  => $p,
     227                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ),
     228                        )
     229                );
     230                $c3 = self::factory()->comment->create(
     231                        array(
     232                                'comment_post_ID'  => $p,
     233                                'comment_approved' => 0,
     234                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ),
     235                        )
     236                );
    162237
    163238                $this->assertEquals( 1, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) );
     
    174249                $posts = self::factory()->post->create_many( 2 );
    175250
    176                 $now = time();
     251                $now        = time();
    177252                $comments_0 = $comments_1 = array();
    178253                for ( $i = 0; $i < 5; $i++ ) {
    179                         $comments_0[] = self::factory()->comment->create( array( 'comment_post_ID' => $posts[0], 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) );
    180                         $comments_1[] = self::factory()->comment->create( array( 'comment_post_ID' => $posts[1], 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) );
     254                        $comments_0[] = self::factory()->comment->create(
     255                                array(
     256                                        'comment_post_ID'  => $posts[0],
     257                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ),
     258                                )
     259                        );
     260                        $comments_1[] = self::factory()->comment->create(
     261                                array(
     262                                        'comment_post_ID'  => $posts[1],
     263                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ),
     264                                )
     265                        );
    181266                }
    182267
     
    194279                $post = self::factory()->post->create();
    195280
    196                 $now = time();
     281                $now             = time();
    197282                $comment_parents = $comment_children = array();
    198283                for ( $i = 0; $i < 5; $i++ ) {
    199                         $parent = self::factory()->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) );
     284                        $parent                = self::factory()->comment->create(
     285                                array(
     286                                        'comment_post_ID'  => $post,
     287                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ),
     288                                )
     289                        );
    200290                        $comment_parents[ $i ] = $parent;
    201291
    202                         $child = self::factory()->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 59 ) ), 'comment_parent' => $parent ) );
     292                        $child                  = self::factory()->comment->create(
     293                                array(
     294                                        'comment_post_ID'  => $post,
     295                                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 59 ) ),
     296                                        'comment_parent'   => $parent,
     297                                )
     298                        );
    203299                        $comment_children[ $i ] = $child;
    204300                }
     
    208304
    209305                $args = array(
    210                         'per_page' => 3,
     306                        'per_page'  => 3,
    211307                        'max_depth' => 2,
    212308                );
     
    229325                $now = time();
    230326
    231                 $p = self::factory()->post->create();
    232                 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
    233                 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) );
    234                 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) );
     327                $p  = self::factory()->post->create();
     328                $c1 = self::factory()->comment->create(
     329                        array(
     330                                'comment_post_ID'  => $p,
     331                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     332                        )
     333                );
     334                $c2 = self::factory()->comment->create(
     335                        array(
     336                                'comment_post_ID'  => $p,
     337                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ),
     338                        )
     339                );
     340                $c3 = self::factory()->comment->create(
     341                        array(
     342                                'comment_post_ID'  => $p,
     343                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ),
     344                        )
     345                );
    235346
    236347                update_option( 'page_comments', 1 );
     
    247358                $now = time();
    248359
    249                 $p = self::factory()->post->create();
    250                 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
    251                 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) );
    252                 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) );
    253                 $c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ) ) );
     360                $p  = self::factory()->post->create();
     361                $c1 = self::factory()->comment->create(
     362                        array(
     363                                'comment_post_ID'  => $p,
     364                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     365                        )
     366                );
     367                $c2 = self::factory()->comment->create(
     368                        array(
     369                                'comment_post_ID'  => $p,
     370                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ),
     371                        )
     372                );
     373                $c3 = self::factory()->comment->create(
     374                        array(
     375                                'comment_post_ID'  => $p,
     376                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ),
     377                        )
     378                );
     379                $c4 = self::factory()->comment->create(
     380                        array(
     381                                'comment_post_ID'  => $p,
     382                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ),
     383                        )
     384                );
    254385
    255386                update_option( 'comment_order', 'desc' );
     
    267398                $now = time();
    268399
    269                 $p = self::factory()->post->create();
    270                 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) );
    271                 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) );
    272                 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) );
    273                 $c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ) ) );
     400                $p  = self::factory()->post->create();
     401                $c1 = self::factory()->comment->create(
     402                        array(
     403                                'comment_post_ID'  => $p,
     404                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     405                        )
     406                );
     407                $c2 = self::factory()->comment->create(
     408                        array(
     409                                'comment_post_ID'  => $p,
     410                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ),
     411                        )
     412                );
     413                $c3 = self::factory()->comment->create(
     414                        array(
     415                                'comment_post_ID'  => $p,
     416                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ),
     417                        )
     418                );
     419                $c4 = self::factory()->comment->create(
     420                        array(
     421                                'comment_post_ID'  => $p,
     422                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ),
     423                        )
     424                );
    274425
    275426                update_option( 'default_comment_page', 'newest' );
Note: See TracChangeset for help on using the changeset viewer.