Skip to:
Content

bbPress.org

Changeset 5894


Ignore:
Timestamp:
08/08/2015 05:28:04 AM (11 years ago)
Author:
netweb
Message:

Replies: Clarify inline doc surrounding bbp_show_lead_topic() in bbp_get_reply_position()

This changest clarify's the docs on how bbp_show_lead_topic() affects a reply's menu order in a topics reply loop and determining the correct pagination of reply URL's.

Includes unit tests for bbp_reply_position() and bbp_get_reply_url()

Fixes #2845

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/template.php

    r5829 r5894  
    18181818        }
    18191819
    1820         // Bump the position by one if the lead topic is in the replies loop
     1820        // Bump the position by one if the topic is included in the reply loop
    18211821        if ( ! bbp_show_lead_topic() ) {
    18221822            $reply_position++;
  • trunk/tests/phpunit/testcases/replies/template/reply.php

    r5876 r5894  
    8181     * @covers ::bbp_reply_url
    8282     * @covers ::bbp_get_reply_url
    83      * @todo   Implement test_bbp_get_reply_url().
     83     *
     84     * @ticket BBP2845
    8485     */
    8586    public function test_bbp_get_reply_url() {
    86         // Remove the following lines when you implement this test.
    87         $this->markTestIncomplete(
    88             'This test has not been implemented yet.'
    89         );
     87        if ( is_multisite() ) {
     88            $this->markTestSkipped( 'Skipping URL tests in multisite for now.' );
     89        }
     90
     91        $f = $this->factory->forum->create();
     92
     93        $t = $this->factory->topic->create( array(
     94            'post_parent' => $f,
     95            'topic_meta' => array(
     96                'forum_id' => $f,
     97            ),
     98        ) );
     99
     100        $r = $this->factory->reply->create_many( 7, array(
     101            'post_parent' => $t,
     102            'reply_meta' => array(
     103                'forum_id' => $f,
     104                'topic_id' => $t,
     105            ),
     106        ) );
     107
     108        // Store the original reply pagination option value.
     109        $default_reply_page = bbp_get_replies_per_page();
     110
     111        // Lower the reply pagination value to test without so many replies.
     112        update_option( '_bbp_replies_per_page', 3 );
     113
     114        // Reply menu position is unaltered when bbp_show_lead_topic() true.
     115        add_filter( 'bbp_show_lead_topic', '__return_true' );
     116
     117        // 1st reply is on the first page, 3 replies and 1 topic per page.
     118        $reply_url = bbp_get_topic_permalink( $t ) . '/#post-' . bbp_get_reply_id( $r[0] );
     119        $this->assertSame( $reply_url, bbp_get_reply_url( $r[0] ) );
     120
     121        // 2nd reply is on the first page, 3 replies and 1 topic per page.
     122        $reply_url = bbp_get_topic_permalink( $t ) . '/#post-' . bbp_get_reply_id( $r[1] );
     123        $this->assertSame( $reply_url, bbp_get_reply_url( $r[1] ) );
     124
     125        // 3rd reply is on the first page, 3 replies and 1 topic per page.
     126        $reply_url = bbp_get_topic_permalink( $t ) . '/#post-' . bbp_get_reply_id( $r[2] );
     127        $this->assertSame( $reply_url, bbp_get_reply_url( $r[2] ) );
     128
     129        // 4th reply is on the second page, 3 replies and 1 topic per page.
     130        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[3] );
     131        $this->assertSame( $reply_url, bbp_get_reply_url( $r[3] ) );
     132
     133        // 5th reply is on the second page, 3 replies and 1 topic per page.
     134        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[4] );
     135        $this->assertSame( $reply_url, bbp_get_reply_url( $r[4] ) );
     136
     137        // 6th reply is on the second page, 3 replies and 1 topic per page.
     138        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[5] );
     139        $this->assertSame( $reply_url, bbp_get_reply_url( $r[5] ) );
     140
     141        // 7th reply is on the third page, 3 replies and 1 topic per page.
     142        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=3#post-' . bbp_get_reply_id( $r[6] );
     143        $this->assertSame( $reply_url, bbp_get_reply_url( $r[6] ) );
     144
     145        // Reply menu position is bumped by 1 when bbp_show_lead_topic() false.
     146        add_filter( 'bbp_show_lead_topic', '__return_false' );
     147
     148        // 1st reply is on the first page, 2 replies and 1 topic per first page.
     149        $reply_url = bbp_get_topic_permalink( $t ) . '/#post-' . bbp_get_reply_id( $r[0] );
     150        $this->assertSame( $reply_url, bbp_get_reply_url( $r[0] ) );
     151
     152        // 2nd reply is on the first page, 2 replies and 1 topic per first page.
     153        $reply_url = bbp_get_topic_permalink( $t ) . '/#post-' . bbp_get_reply_id( $r[1] );
     154        $this->assertSame( $reply_url, bbp_get_reply_url( $r[1] ) );
     155
     156        // 3rd reply is on the second page, 2 replies and 1 topic per first page.
     157        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[2] );
     158        $this->assertSame( $reply_url, bbp_get_reply_url( $r[2] ) );
     159
     160        // 4th reply is on the second page, 3 replies per subsequent page.
     161        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[3] );
     162        $this->assertSame( $reply_url, bbp_get_reply_url( $r[3] ) );
     163
     164        // 5th reply is on the second page, 3 replies per subsequent page.
     165        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=2#post-' . bbp_get_reply_id( $r[4] );
     166        $this->assertSame( $reply_url, bbp_get_reply_url( $r[4] ) );
     167
     168        // 6th reply is on the third page, 3 replies per subsequent page.
     169        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=3#post-' . bbp_get_reply_id( $r[5] );
     170        $this->assertSame( $reply_url, bbp_get_reply_url( $r[5] ) );
     171
     172        // 7th reply is on the third page, 3 replies per subsequent page.
     173        $reply_url = bbp_get_topic_permalink( $t ) . '&paged=3#post-' . bbp_get_reply_id( $r[6] );
     174        $this->assertSame( $reply_url, bbp_get_reply_url( $r[6] ) );
     175
     176        // Restore the original reply pagination option value.
     177        update_option( '_bbp_replies_per_page', $default_reply_page );
    90178    }
    91179
     
    401489     * @covers ::bbp_reply_position
    402490     * @covers ::bbp_get_reply_position
    403      * @todo   Implement test_bbp_get_reply_position().
     491     *
     492     * @ticket BBP2845
    404493     */
    405494    public function test_bbp_get_reply_position() {
    406         // Remove the following lines when you implement this test.
    407         $this->markTestIncomplete(
    408             'This test has not been implemented yet.'
    409         );
     495        $f = $this->factory->forum->create();
     496
     497        $t = $this->factory->topic->create( array(
     498            'post_parent' => $f,
     499            'topic_meta' => array(
     500                'forum_id' => $f,
     501            ),
     502        ) );
     503
     504        $r = $this->factory->reply->create_many( 7, array(
     505            'post_parent' => $t,
     506            'reply_meta' => array(
     507                'forum_id' => $f,
     508                'topic_id' => $t,
     509            ),
     510        ) );
     511
     512        // Reply menu position is unaltered when bbp_show_lead_topic() true.
     513        add_filter( 'bbp_show_lead_topic', '__return_true' );
     514
     515        $position = get_post_field( 'menu_order', $r[3] );
     516        $this->assertSame( 4, $position );
     517
     518        $position = bbp_get_reply_position_raw( $r[3] );
     519        $this->assertSame( 4, $position );
     520
     521        $position = bbp_get_reply_position( $r[3] );
     522        $this->assertSame( 4, $position );
     523
     524        // Force a reply's 'menu_order' to 0.
     525        wp_update_post( array(
     526            'ID'         => $r[3],
     527            'menu_order' => 0,
     528        ) );
     529
     530        $position = get_post_field( 'menu_order', $r[3] );
     531        $this->assertSame( 0, $position );
     532
     533        $position = bbp_get_reply_position_raw( $r[3] );
     534        $this->assertSame( 4, $position );
     535
     536        $position = bbp_get_reply_position( $r[3] );
     537        $this->assertSame( 4, $position );
     538
     539        // Reply menu position is bumped by 1 when bbp_show_lead_topic() false.
     540        add_filter( 'bbp_show_lead_topic', '__return_false' );
     541
     542        $position = get_post_field( 'menu_order', $r[3] );
     543        $this->assertSame( 4, $position );
     544
     545        $position = bbp_get_reply_position_raw( $r[3] );
     546        $this->assertSame( 4, $position );
     547
     548        $position = bbp_get_reply_position( $r[3] );
     549        $this->assertSame( 5, $position );
     550
     551        // Force a reply's 'menu_order' to 0.
     552        wp_update_post( array(
     553            'ID'         => $r[3],
     554            'menu_order' => 0,
     555        ) );
     556
     557        $position = get_post_field( 'menu_order', $r[3] );
     558        $this->assertSame( 0, $position );
     559
     560        $position = bbp_get_reply_position_raw( $r[3] );
     561        $this->assertSame( 4, $position );
     562
     563        $position = bbp_get_reply_position( $r[3] );
     564        $this->assertSame( 5, $position );
    410565    }
    411566
Note: See TracChangeset for help on using the changeset viewer.