Skip to:
Content

bbPress.org

Ticket #2702: 2702.4.diff

File 2702.4.diff, 5.4 KB (added by tharsheblows, 9 years ago)

replies and topic pagination patches and unit tests

  • src/includes/common/formatting.php

     
    389389        $r = preg_replace( '#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', "$1$3</a>", $r );
    390390        return $r;
    391391}
     392
     393/**
     394 * Removes the first page query string &paged=1
     395 *
     396 * @since
     397 *
     398 * @return string The query string for the first page
     399 */
     400function bbp_pagination_paged_1_replace( $matches ){
     401        return str_replace( '&#038;paged=1', '', $matches[0] );
     402}
  • src/includes/replies/template.php

     
    273273                        if ( bbp_use_pretty_urls() ) {
    274274                                $bbp->reply_query->pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $bbp->reply_query->pagination_links );
    275275                        } else {
    276                                 $bbp->reply_query->pagination_links = str_replace( '&#038;paged=1', '', $bbp->reply_query->pagination_links );
     276                                $bbp->reply_query->pagination_links = preg_replace_callback( '/&#038;paged=1[^0-9]/',
     277                                        'bbp_pagination_paged_1_replace',
     278                                $bbp->reply_query->pagination_links );
    277279                        }
    278280                }
    279281        }
  • src/includes/topics/template.php

     
    908908                        if ( bbp_use_pretty_urls() ) {
    909909                                $pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links );
    910910                        } else {
    911                                 $pagination_links = str_replace( '&#038;paged=1', '', $pagination_links );
     911                                $pagination_links = preg_replace_callback( '/&#038;paged=1[^0-9]/',
     912                                        'bbp_pagination_paged_1_replace',
     913                                $pagination_links );
    912914                        }
    913915
    914916                        // Add before and after to pagination links
  • tests/phpunit/testcases/replies/template/loop.php

     
    2121        }
    2222
    2323        /**
     24     * @ticket BBP2702
     25     */
     26        public function test_replies_pagination_when_pages_are_greater_than_nine() {
     27
     28                $bbp = bbpress();
     29
     30                if ( is_multisite() ) {
     31                        $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
     32                }
     33
     34                $f = $this->factory->forum->create();
     35                $t = $this->factory->topic->create( array(
     36                        'post_parent' => $f,
     37                        'topic_meta' => array(
     38                                'forum_id' => $f,
     39                        ),
     40                ) );
     41
     42                $r = $this->factory->reply->create_many( 15, array(
     43                        'post_parent' => $t,
     44                        'reply_meta' => array(
     45                                'forum_id' => $f,
     46                                'topic_id' => $t,
     47                        ),
     48                ) );
     49
     50                // Default query args from bbp_has_replies are going to be used as the args
     51                $args = array(
     52                        'posts_per_page' => 1,          // use 1 per page for testing
     53                );
     54
     55                $request_uri = $_SERVER['REQUEST_URI'];
     56            $_SERVER['REQUEST_URI'] = add_query_arg( 'topic=' . $t, '', $request_uri );
     57
     58            // test unpretty permalinks (default)
     59                bbp_has_replies( $args );
     60
     61                $paged_link = $_SERVER['REQUEST_URI'] . '&#038;paged=';
     62                $page2 = $paged_link . '2';
     63                $page16 = $paged_link . '16';
     64
     65                $expected =<<<EXPECTED
     66<span class='page-numbers current'>1</span>
     67<a class='page-numbers' href='$page2'>2</a>
     68<span class="page-numbers dots">&hellip;</span>
     69<a class='page-numbers' href='$page16'>16</a>
     70<a class="next page-numbers" href="$page2">&rarr;</a>
     71EXPECTED;
     72
     73                $links = bbp_get_topic_pagination_links();
     74                $this->assertEquals( $expected, $links );
     75
     76                $_SERVER['REQUEST_URI'] = $request_uri;
     77
     78        }
     79
     80
     81        /**
    2482         * @covers ::bbp_replies
    2583         * @todo   Implement test_bbp_replies().
    2684         */
  • tests/phpunit/testcases/topics/template/loop.php

     
    2121        }
    2222
    2323        /**
     24     * @ticket BBP2702
     25     */
     26        public function test_topics_pagination_when_pages_are_greater_than_nine() {
     27
     28                $bbp = bbpress();
     29
     30                if ( is_multisite() ) {
     31                        $this->markTestSkipped( 'Skipping URL tests in multiste for now.' );
     32                }
     33
     34                $f = $this->factory->forum->create();
     35                $t = $this->factory->topic->create_many( 15, array(
     36                        'post_parent' => $f,
     37                        'topic_meta' => array(
     38                                'forum_id' => $f,
     39                        ),
     40                ) );
     41
     42                // Default query args from bbp_has_replies are going to be used as the args
     43                $args = array(
     44                        'posts_per_page' => 1,          // use 1 per page for testing
     45                );
     46
     47                $request_uri = $_SERVER['REQUEST_URI'];
     48            $_SERVER['REQUEST_URI'] = add_query_arg( 'forum=' . $f, '', $request_uri );
     49
     50            // test unpretty permalinks (default)
     51                bbp_has_replies( $args );
     52
     53                $paged_link = $_SERVER['REQUEST_URI'] . '&#038;paged=';
     54                $page2 = $paged_link . '2';
     55                $page15 = $paged_link . '15';
     56
     57                $expected =<<<EXPECTED
     58<span class='page-numbers current'>1</span>
     59<a class='page-numbers' href='$page2'>2</a>
     60<span class="page-numbers dots">&hellip;</span>
     61<a class='page-numbers' href='$page15'>15</a>
     62<a class="next page-numbers" href="$page2">&rarr;</a>
     63EXPECTED;
     64
     65                $links = bbp_get_topic_pagination_links();
     66                $this->assertEquals( $expected, $links );
     67
     68                $_SERVER['REQUEST_URI'] = $request_uri;
     69
     70        }
     71
     72        /**
    2473         * @covers ::bbp_topics
    2574         * @todo   Implement test_bbp_topics().
    2675         */