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

    r37655 r42343  
    1212
    1313        $comments = array();
    14         $now = time();
    15         for ( $i = 0; $i <= 5; $i++ ) {
    16             $comments[] = self::factory()->comment->create( array(
    17                 'comment_post_ID' => $p,
    18                 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
    19                 'comment_author' => 'Commenter ' . $i,
    20             ) );
    21         }
    22 
    23         update_option( 'page_comments', true );
    24         update_option( 'comments_per_page', 2 );
    25 
    26         $this->go_to( get_permalink( $p ) );
    27 
    28         // comments_template() populates $wp_query->comments
    29         get_echo( 'comments_template' );
    30 
    31         $found = wp_list_comments( array(
    32             'page' => 2,
    33             'echo' => false,
    34         ) );
     14        $now      = time();
     15        for ( $i = 0; $i <= 5; $i++ ) {
     16            $comments[] = self::factory()->comment->create(
     17                array(
     18                    'comment_post_ID'  => $p,
     19                    'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     20                    'comment_author'   => 'Commenter ' . $i,
     21                )
     22            );
     23        }
     24
     25        update_option( 'page_comments', true );
     26        update_option( 'comments_per_page', 2 );
     27
     28        $this->go_to( get_permalink( $p ) );
     29
     30        // comments_template() populates $wp_query->comments
     31        get_echo( 'comments_template' );
     32
     33        $found = wp_list_comments(
     34            array(
     35                'page' => 2,
     36                'echo' => false,
     37            )
     38        );
    3539
    3640        preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
     
    4650
    4751        $comments = array();
    48         $now = time();
    49         for ( $i = 0; $i <= 5; $i++ ) {
    50             $comments[] = self::factory()->comment->create( array(
    51                 'comment_post_ID' => $p,
    52                 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
    53                 'comment_author' => 'Commenter ' . $i,
    54             ) );
    55         }
    56 
    57         update_option( 'page_comments', true );
    58         update_option( 'comments_per_page', 2 );
    59 
    60         $this->go_to( get_permalink( $p ) );
    61 
    62         // comments_template() populates $wp_query->comments
    63         get_echo( 'comments_template' );
    64 
    65         $found = wp_list_comments( array(
    66             'per_page' => 3,
    67             'echo' => false,
    68         ) );
     52        $now      = time();
     53        for ( $i = 0; $i <= 5; $i++ ) {
     54            $comments[] = self::factory()->comment->create(
     55                array(
     56                    'comment_post_ID'  => $p,
     57                    'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     58                    'comment_author'   => 'Commenter ' . $i,
     59                )
     60            );
     61        }
     62
     63        update_option( 'page_comments', true );
     64        update_option( 'comments_per_page', 2 );
     65
     66        $this->go_to( get_permalink( $p ) );
     67
     68        // comments_template() populates $wp_query->comments
     69        get_echo( 'comments_template' );
     70
     71        $found = wp_list_comments(
     72            array(
     73                'per_page' => 3,
     74                'echo'     => false,
     75            )
     76        );
    6977
    7078        preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
     
    8088
    8189        $comments = array();
    82         $now = time();
    83         for ( $i = 0; $i <= 5; $i++ ) {
    84             $comments[] = self::factory()->comment->create( array(
    85                 'comment_post_ID' => $p,
    86                 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
    87                 'comment_author' => 'Commenter ' . $i,
    88             ) );
    89         }
    90 
    91         update_option( 'page_comments', true );
    92         update_option( 'comments_per_page', 2 );
    93 
    94         $this->go_to( get_permalink( $p ) );
    95 
    96         // comments_template() populates $wp_query->comments
    97         get_echo( 'comments_template' );
    98 
    99         $found1 = wp_list_comments( array(
    100             'reverse_top_level' => true,
    101             'echo' => false,
    102         ) );
     90        $now      = time();
     91        for ( $i = 0; $i <= 5; $i++ ) {
     92            $comments[] = self::factory()->comment->create(
     93                array(
     94                    'comment_post_ID'  => $p,
     95                    'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     96                    'comment_author'   => 'Commenter ' . $i,
     97                )
     98            );
     99        }
     100
     101        update_option( 'page_comments', true );
     102        update_option( 'comments_per_page', 2 );
     103
     104        $this->go_to( get_permalink( $p ) );
     105
     106        // comments_template() populates $wp_query->comments
     107        get_echo( 'comments_template' );
     108
     109        $found1 = wp_list_comments(
     110            array(
     111                'reverse_top_level' => true,
     112                'echo'              => false,
     113            )
     114        );
    103115        preg_match_all( '|id="comment\-([0-9]+)"|', $found1, $matches );
    104116        $this->assertSame( array( $comments[0], $comments[1] ), array_map( 'intval', $matches[1] ) );
    105117
    106         $found2 = wp_list_comments( array(
    107             'reverse_top_level' => false,
    108             'echo' => false,
    109         ) );
     118        $found2 = wp_list_comments(
     119            array(
     120                'reverse_top_level' => false,
     121                'echo'              => false,
     122            )
     123        );
    110124        preg_match_all( '|id="comment\-([0-9]+)"|', $found2, $matches );
    111125        $this->assertSame( array( $comments[1], $comments[0] ), array_map( 'intval', $matches[1] ) );
     
    120134
    121135        $comments = array();
    122         $now = time();
    123         for ( $i = 0; $i <= 5; $i++ ) {
    124             $comments[] = self::factory()->comment->create( array(
    125                 'comment_post_ID' => $p,
    126                 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
    127                 'comment_author' => 'Commenter ' . $i,
    128             ) );
     136        $now      = time();
     137        for ( $i = 0; $i <= 5; $i++ ) {
     138            $comments[] = self::factory()->comment->create(
     139                array(
     140                    'comment_post_ID'  => $p,
     141                    'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     142                    'comment_author'   => 'Commenter ' . $i,
     143                )
     144            );
    129145        }
    130146
     
    138154        get_echo( 'comments_template' );
    139155
    140         $found = wp_list_comments( array(
    141             'echo' => false,
    142             'per_page' => 1,
    143             'page' => 2,
    144         ), $_comments );
     156        $found = wp_list_comments(
     157            array(
     158                'echo'     => false,
     159                'per_page' => 1,
     160                'page'     => 2,
     161            ), $_comments
     162        );
    145163
    146164        preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
     
    155173
    156174        $comments = array();
    157         $now = time();
    158         for ( $i = 0; $i <= 5; $i++ ) {
    159             $comments[] = self::factory()->comment->create( array(
    160                 'comment_post_ID' => $p,
    161                 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
    162                 'comment_author' => 'Commenter ' . $i,
    163             ) );
     175        $now      = time();
     176        for ( $i = 0; $i <= 5; $i++ ) {
     177            $comments[] = self::factory()->comment->create(
     178                array(
     179                    'comment_post_ID'  => $p,
     180                    'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     181                    'comment_author'   => 'Commenter ' . $i,
     182                )
     183            );
    164184        }
    165185
     
    178198        get_echo( 'comments_template' );
    179199
    180         $found = wp_list_comments( array(
    181             'echo' => false,
    182             'per_page' => 1,
    183             'page' => 2,
    184         ) );
     200        $found = wp_list_comments(
     201            array(
     202                'echo'     => false,
     203                'per_page' => 1,
     204                'page'     => 2,
     205            )
     206        );
    185207
    186208        preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
     
    196218
    197219        $comments = array();
    198         $now = time();
    199         for ( $i = 0; $i <= 5; $i++ ) {
    200             $comments[] = self::factory()->comment->create( array(
    201                 'comment_post_ID' => $p,
    202                 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
    203                 'comment_author' => 'Commenter ' . $i,
    204                 'user_id' => $u,
    205             ) );
     220        $now      = time();
     221        for ( $i = 0; $i <= 5; $i++ ) {
     222            $comments[] = self::factory()->comment->create(
     223                array(
     224                    'comment_post_ID'  => $p,
     225                    'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ),
     226                    'comment_author'   => 'Commenter ' . $i,
     227                    'user_id'          => $u,
     228                )
     229            );
    206230        }
    207231
     
    222246        get_echo( 'comments_template' );
    223247
    224         $found = wp_list_comments( array(
    225             'echo' => false,
    226             'per_page' => 1,
    227             'page' => 2,
    228         ) );
     248        $found = wp_list_comments(
     249            array(
     250                'echo'     => false,
     251                'per_page' => 1,
     252                'page'     => 2,
     253            )
     254        );
    229255
    230256        preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches );
Note: See TracChangeset for help on using the changeset viewer.