Skip to:
Content

bbPress.org

Changeset 7807


Ignore:
Timestamp:
10/04/2026 12:28:35 PM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Replies: Correct ancestry and position comparisons.

Stop threaded reply ancestry at the root instead of appending a zero ID, and compare normalized integer positions so unchanged replies do not trigger redundant writes. Add regression coverage for both cases.

In trunk, for 2.7.

See #3698.
See #3699.
See #3695.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.md

    r7772 r7807  
    4545### Fixed
    4646
     47- Prevented threaded reply ancestry from including an invalid parent and avoided redundant reply-position writes.
    4748- Restored assigned moderator names in forum edit forms and corrected forum type and visibility dropdown behavior.
    4849- Kept closed category ancestors from being ignored by forum status checks.
  • trunk/src/includes/replies/functions.php

    r7765 r7807  
    11951195
    11961196                                // Loop detection: If the ancestor has been seen before, break.
    1197                                 if ( empty( $ancestor->post_parent ) || ( $grampy_id === $reply_id ) || in_array( $grampy_id, $ancestors, true ) ) {
     1197                                if ( empty( $grampy_id ) || empty( $ancestor->post_parent ) || ( $grampy_id === $reply_id ) || in_array( $grampy_id, $ancestors, true ) ) {
    11981198                                        break;
    11991199                                }
    … …  
    24392439
    24402440        // Get the current reply position
    2441         $current_position = get_post_field( 'menu_order', $reply_id );
     2441        $current_position = (int) get_post_field( 'menu_order', $reply_id );
    24422442
    24432443        // Bail if no change
  • trunk/tests/phpunit/testcases/replies/functions/reply.php

    r7804 r7807  
    257257        /**
    258258         * @covers ::bbp_get_reply_ancestors
    259          * @todo   Implement test_bbp_get_reply_ancestors().
    260259         */
    261260        public function test_bbp_get_reply_ancestors() {
    262                 // Remove the following lines when you implement this test.
    263                 $this->markTestIncomplete(
    264                         'This test has not been implemented yet.'
    265                 );
     261                $topic_id  = $this->factory->topic->create();
     262                $root_id   = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     263                $parent_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     264                $child_id  = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     265                bbp_update_reply_to( $parent_id, $root_id );
     266                bbp_update_reply_to( $child_id, $parent_id );
     267
     268                $this->assertSame( array(), bbp_get_reply_ancestors( $root_id ) );
     269                $this->assertSame( array( $root_id ), bbp_get_reply_ancestors( $parent_id ) );
     270                $this->assertSame( array( $parent_id, $root_id ), bbp_get_reply_ancestors( $child_id ) );
    266271        }
    267272
    … …  
    557562        /**
    558563         * @covers ::bbp_update_reply_position
    559          * @todo   Implement test_bbp_update_reply_position().
    560564         */
    561565        public function test_bbp_update_reply_position() {
    562                 // Remove the following lines when you implement this test.
    563                 $this->markTestIncomplete(
    564                         'This test has not been implemented yet.'
    565                 );
     566                $topic_id = $this->factory->topic->create();
     567                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     568
     569                $this->assertSame( 3, bbp_update_reply_position( $reply_id, 3 ) );
     570                $this->assertSame( 3, (int) get_post_field( 'menu_order', $reply_id ) );
     571                $this->assertFalse( bbp_update_reply_position( $reply_id, 3 ) );
    566572        }
    567573
Note: See TracChangeset for help on using the changeset viewer.