Make WordPress Core


Ignore:
Timestamp:
09/30/2015 03:06:22 AM (11 years ago)
Author:
boonebgorges
Message:

Fix logical errors in some comment pagination tests.

The tests included in [34669] contained a couple of problems:

  • Comments were not always created in the expected order, due to the incorrect use of 'comment_date_gmt'.
  • 'asc'/'desc' and 'older'/'newer' were confused.
  • 'default_comments_page=newest' ('last') didn't properly account for the cpage=1 offset.

The code itself powering this pagination was correct; it's only the tests that
were wrong.

See #8071.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/commentsTemplate.php

    r34669 r34713  
    1616                        'comment_post_ID' => $p,
    1717                        'comment_content' => '1',
    18                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    19                 ) );
    20                 $comment_2 = $this->factory->comment->create( array(
    21                         'comment_post_ID' => $p,
    22                         'comment_content' => '2',
    23                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     18                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     19                ) );
     20                $comment_2 = $this->factory->comment->create( array(
     21                        'comment_post_ID' => $p,
     22                        'comment_content' => '2',
     23                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    2424                ) );
    2525
     
    3434
    3535                $found_cids = array_map( 'intval', $matches[1] );
    36                 $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
     36                $this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
    3737        }
    3838
     
    4646                        'comment_post_ID' => $p,
    4747                        'comment_content' => '1',
    48                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    49                 ) );
    50                 $comment_2 = $this->factory->comment->create( array(
    51                         'comment_post_ID' => $p,
    52                         'comment_content' => '2',
    53                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     48                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     49                ) );
     50                $comment_2 = $this->factory->comment->create( array(
     51                        'comment_post_ID' => $p,
     52                        'comment_content' => '2',
     53                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    5454                ) );
    5555
     
    6464
    6565                $found_cids = array_map( 'intval', $matches[1] );
    66                 $this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
     66                $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
    6767        }
    6868
     
    7676                        'comment_post_ID' => $p,
    7777                        'comment_content' => '1',
    78                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    79                 ) );
    80                 $comment_2 = $this->factory->comment->create( array(
    81                         'comment_post_ID' => $p,
    82                         'comment_content' => '2',
    83                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     78                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     79                ) );
     80                $comment_2 = $this->factory->comment->create( array(
     81                        'comment_post_ID' => $p,
     82                        'comment_content' => '2',
     83                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    8484                ) );
    8585
     
    9494
    9595                $found_cids = array_map( 'intval', $matches[1] );
    96                 $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
     96                $this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
    9797        }
    9898
     
    106106                        'comment_post_ID' => $p,
    107107                        'comment_content' => '1',
    108                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    109                 ) );
    110                 $comment_2 = $this->factory->comment->create( array(
    111                         'comment_post_ID' => $p,
    112                         'comment_content' => '2',
    113                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     108                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     109                ) );
     110                $comment_2 = $this->factory->comment->create( array(
     111                        'comment_post_ID' => $p,
     112                        'comment_content' => '2',
     113                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    114114                ) );
    115115
     
    124124
    125125                $found_cids = array_map( 'intval', $matches[1] );
    126                 $this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
     126                $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
    127127        }
    128128
     
    136136                        'comment_post_ID' => $p,
    137137                        'comment_content' => '1',
    138                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    139                 ) );
    140                 $comment_2 = $this->factory->comment->create( array(
    141                         'comment_post_ID' => $p,
    142                         'comment_content' => '2',
    143                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     138                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     139                ) );
     140                $comment_2 = $this->factory->comment->create( array(
     141                        'comment_post_ID' => $p,
     142                        'comment_content' => '2',
     143                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    144144                ) );
    145145                $comment_3 = $this->factory->comment->create( array(
    146146                        'comment_post_ID' => $p,
    147147                        'comment_content' => '3',
    148                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     148                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    149149                ) );
    150150                $comment_4 = $this->factory->comment->create( array(
    151151                        'comment_post_ID' => $p,
    152152                        'comment_content' => '4',
    153                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
     153                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
     154                ) );
     155                $comment_5 = $this->factory->comment->create( array(
     156                        'comment_post_ID' => $p,
     157                        'comment_content' => '3',
     158                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
     159                ) );
     160                $comment_6 = $this->factory->comment->create( array(
     161                        'comment_post_ID' => $p,
     162                        'comment_content' => '4',
     163                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
    154164                ) );
    155165
     
    157167                update_option( 'default_comments_page', 'newest' );
    158168
    159                 $this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
    160                 $found = get_echo( 'comments_template' );
    161 
    162                 // Life in the fast lane.
    163                 $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
    164 
    165                 $found_cids = array_map( 'intval', $matches[1] );
    166                 $this->assertSame( array( $comment_3, $comment_4 ), $found_cids );
     169                $link = add_query_arg( array(
     170                        'cpage' => 2,
     171                        'comments_per_page' => 2,
     172                ), get_permalink( $p ) );
     173
     174                $this->go_to( $link );
     175                $found = get_echo( 'comments_template' );
     176
     177                // Life in the fast lane.
     178                $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
     179
     180                $found_cids = array_map( 'intval', $matches[1] );
     181                $this->assertSame( array( $comment_4, $comment_3 ), $found_cids );
    167182        }
    168183
     
    176191                        'comment_post_ID' => $p,
    177192                        'comment_content' => '1',
    178                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    179                 ) );
    180                 $comment_2 = $this->factory->comment->create( array(
    181                         'comment_post_ID' => $p,
    182                         'comment_content' => '2',
    183                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     193                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     194                ) );
     195                $comment_2 = $this->factory->comment->create( array(
     196                        'comment_post_ID' => $p,
     197                        'comment_content' => '2',
     198                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    184199                ) );
    185200                $comment_3 = $this->factory->comment->create( array(
    186201                        'comment_post_ID' => $p,
    187202                        'comment_content' => '3',
    188                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     203                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    189204                ) );
    190205                $comment_4 = $this->factory->comment->create( array(
    191206                        'comment_post_ID' => $p,
    192207                        'comment_content' => '4',
    193                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
     208                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
     209                ) );
     210                $comment_5 = $this->factory->comment->create( array(
     211                        'comment_post_ID' => $p,
     212                        'comment_content' => '3',
     213                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 500 ),
     214                ) );
     215                $comment_6 = $this->factory->comment->create( array(
     216                        'comment_post_ID' => $p,
     217                        'comment_content' => '4',
     218                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 600 ),
    194219                ) );
    195220
     
    197222                update_option( 'default_comments_page', 'newest' );
    198223
    199                 $this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
    200                 $found = get_echo( 'comments_template' );
    201 
    202                 // Life in the fast lane.
    203                 $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
    204 
    205                 $found_cids = array_map( 'intval', $matches[1] );
    206                 $this->assertSame( array( $comment_4, $comment_3 ), $found_cids );
     224                $link = add_query_arg( array(
     225                        'cpage' => 2,
     226                        'comments_per_page' => 2,
     227                ), get_permalink( $p ) );
     228
     229                $this->go_to( $link );
     230                $found = get_echo( 'comments_template' );
     231
     232                // Life in the fast lane.
     233                $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
     234
     235                $found_cids = array_map( 'intval', $matches[1] );
     236                $this->assertSame( array( $comment_3, $comment_4 ), $found_cids );
    207237        }
    208238
     
    216246                        'comment_post_ID' => $p,
    217247                        'comment_content' => '1',
    218                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    219                 ) );
    220                 $comment_2 = $this->factory->comment->create( array(
    221                         'comment_post_ID' => $p,
    222                         'comment_content' => '2',
    223                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     248                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     249                ) );
     250                $comment_2 = $this->factory->comment->create( array(
     251                        'comment_post_ID' => $p,
     252                        'comment_content' => '2',
     253                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    224254                ) );
    225255                $comment_3 = $this->factory->comment->create( array(
    226256                        'comment_post_ID' => $p,
    227257                        'comment_content' => '3',
    228                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     258                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    229259                ) );
    230260                $comment_4 = $this->factory->comment->create( array(
    231261                        'comment_post_ID' => $p,
    232262                        'comment_content' => '4',
    233                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
     263                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
    234264                ) );
    235265
     
    237267                update_option( 'default_comments_page', 'oldest' );
    238268
    239                 $this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
    240                 $found = get_echo( 'comments_template' );
    241 
    242                 // Life in the fast lane.
    243                 $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
    244 
    245                 $found_cids = array_map( 'intval', $matches[1] );
    246                 $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
     269                $link = add_query_arg( array(
     270                        'cpage' => 2,
     271                        'comments_per_page' => 2,
     272                ), get_permalink( $p ) );
     273
     274                $this->go_to( $link );
     275                $found = get_echo( 'comments_template' );
     276
     277                // Life in the fast lane.
     278                $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
     279
     280                $found_cids = array_map( 'intval', $matches[1] );
     281                $this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
    247282        }
    248283
     
    256291                        'comment_post_ID' => $p,
    257292                        'comment_content' => '1',
    258                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
    259                 ) );
    260                 $comment_2 = $this->factory->comment->create( array(
    261                         'comment_post_ID' => $p,
    262                         'comment_content' => '2',
    263                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
     293                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ),
     294                ) );
     295                $comment_2 = $this->factory->comment->create( array(
     296                        'comment_post_ID' => $p,
     297                        'comment_content' => '2',
     298                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ),
    264299                ) );
    265300                $comment_3 = $this->factory->comment->create( array(
    266301                        'comment_post_ID' => $p,
    267302                        'comment_content' => '3',
    268                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
     303                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ),
    269304                ) );
    270305                $comment_4 = $this->factory->comment->create( array(
    271306                        'comment_post_ID' => $p,
    272307                        'comment_content' => '4',
    273                         'comment_post_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
     308                        'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ),
    274309                ) );
    275310
     
    277312                update_option( 'default_comments_page', 'oldest' );
    278313
    279                 $this->go_to( get_permalink( $p ) . '?cpage=2&comments_per_page=2' );
    280                 $found = get_echo( 'comments_template' );
    281 
    282                 // Life in the fast lane.
    283                 $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
    284 
    285                 $found_cids = array_map( 'intval', $matches[1] );
    286                 $this->assertSame( array( $comment_2, $comment_1 ), $found_cids );
     314                $link = add_query_arg( array(
     315                        'cpage' => 2,
     316                        'comments_per_page' => 2,
     317                ), get_permalink( $p ) );
     318
     319                $this->go_to( $link );
     320                $found = get_echo( 'comments_template' );
     321
     322                // Life in the fast lane.
     323                $comments = preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches );
     324
     325                $found_cids = array_map( 'intval', $matches[1] );
     326                $this->assertSame( array( $comment_1, $comment_2 ), $found_cids );
    287327        }
    288328}
Note: See TracChangeset for help on using the changeset viewer.