Make WordPress Core

Ticket #50233: 50233.1.diff

File 50233.1.diff, 2.5 KB (added by sumanm, 4 years ago)

added unit tests for comments limit pagination

  • src/wp-includes/canonical.php

     
    2727 * or query in an attempt to figure the correct page to go to.
    2828 *
    2929 * @since 2.3.0
    30  *
     30 * @since 5.6.0 checks comments page count to limit pagination
    3131 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    3232 * @global bool       $is_IIS
    3333 * @global WP_Query   $wp_query   WordPress Query object.
     
    490490                                && ( 'newest' === $default_comments_page && $cpage > 0
    491491                                        || 'newest' !== $default_comments_page && $cpage > 1 )
    492492                        ) {
    493                                 $addl_path  = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' );
    494                                 $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' );
    495 
     493                                //checks comments page count to limit pagination
     494                                $per_page             = get_option( 'comments_per_page' );
     495                                $comments_total_pages = ceil( ( $wp_query->post->comment_count ) / $per_page );//get total number of pages for comments
     496                                if ( $cpage <= $comments_total_pages ) {
     497                                         $addl_path  = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' );
     498                                         $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' );
     499                                }
    496500                                $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
    497501                        }
    498 
     502                       
    499503                        // Strip off trailing /index.php/.
    500504                        $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] );
    501505                        $redirect['path'] = user_trailingslashit( $redirect['path'] );
  • tests/phpunit/tests/link/wpGetCanonicalURL.php

     
    152152        }
    153153
    154154        /**
     155         *  Limit pagination for comments.
     156         *
     157         *  @ticket 50233
     158         */
     159        public function test_comments_limit_paged_with_plain_permalink_structure() {
     160                $cpage = 5;
     161
     162                $link = add_query_arg(
     163                        array(
     164                                'cpage' => $cpage,
     165                                'foo'   => 'bar',
     166                        ),
     167                        get_permalink( self::$post_id )
     168                );
     169               
     170                $this->go_to( $link );
     171
     172                $expected = get_permalink( self::$post_id ) . '#comments';
     173
     174                $this->assertSame( $expected, wp_get_canonical_url( self::$post_id ) );
     175        }
     176
     177
     178        /**
    155179         * Filter callback for testing of filter usage.
    156180         *
    157181         * @return string