Skip to:
Content

bbPress.org

Changeset 7768


Ignore:
Timestamp:
10/02/2026 04:29:40 PM (6 weeks ago)
Author:
johnjamesjacoby
Message:

Forums: Preserve category status mismatches.

Combine each category ancestor's status with the preceding result so a matching outer category cannot erase an intermediate mismatch. Complete the forum status helper coverage and add a nested-category regression test.

In trunk, for 2.7.
See #3696.
See #3695.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.md

    r7765 r7768  
    4545### Fixed
    4646
     47- Kept closed category ancestors from being ignored by forum status checks.
    4748- Preserved topic subscriptions when topics and replies are edited in administration.
    4849- Cache a distinct count of current-site forum-role holders for forum statistics,
  • trunk/src/includes/forums/template.php

    r7669 r7768  
    17231723
    17241724                                        // Check the ancestor forum status
    1725                                         $retval = bbp_is_forum_status( $ancestor, $status_name, false );
    1726                                         if ( true === $retval ) {
     1725                                        $ancestor_matches = bbp_is_forum_status( $ancestor, $status_name, false );
     1726                                        if ( true === $ancestor_matches ) {
    17271727                                                ++$count;
    17281728                                        }
     1729
     1730                                        // Combine statuses across the category hierarchy.
     1731                                        $retval = ( 'OR' === $operator )
     1732                                                ? ( $retval || $ancestor_matches )
     1733                                                : ( $retval && $ancestor_matches );
    17291734                                }
    17301735
  • trunk/tests/phpunit/testcases/forums/template/status.php

    r5700 r7768  
    1717                $f = $this->factory->forum->create();
    1818
    19                 $forum = bbp_get_forum_status( $f );
    20                 $this->assertSame( 'open', $forum );
     19                $this->assertSame( 'open', bbp_get_forum_status( $f ) );
    2120
    2221                bbp_normalize_forum( $f );
    23                 $this->assertSame( 'open', $forum );
     22                $this->assertSame( 'open', bbp_get_forum_status( $f ) );
     23
     24                bbp_close_forum( $f );
     25                $this->assertSame( 'closed', bbp_get_forum_status( $f ) );
     26                $this->expectOutputString( 'closed' );
     27                bbp_forum_status( $f );
    2428        }
    2529
    … …  
    3135                $f = $this->factory->forum->create();
    3236
    33                 $forum = bbp_get_forum_type( $f );
    34                 $this->assertSame( 'forum', $forum );
     37                $this->assertSame( 'forum', bbp_get_forum_type( $f ) );
     38
     39                bbp_categorize_forum( $f );
     40                $this->assertSame( 'category', bbp_get_forum_type( $f ) );
    3541        }
    3642
    … …  
    94100        /**
    95101         * @covers ::bbp_is_forum_status
    96          * @todo   Implement test_bbp_is_forum_status().
    97102         */
    98103        public function test_bbp_is_forum_status() {
    99                 // Remove the following lines when you implement this test.
    100                 $this->markTestIncomplete(
    101                         'This test has not been implemented yet.'
    102                 );
     104                $forum_id = $this->factory->forum->create();
     105                $this->assertTrue( bbp_is_forum_status( $forum_id, 'open' ) );
     106                $this->assertFalse( bbp_is_forum_status( $forum_id, 'closed' ) );
     107
     108                bbp_close_forum( $forum_id );
     109                $this->assertTrue( bbp_is_forum_status( $forum_id, 'closed' ) );
     110                $this->assertFalse( bbp_is_forum_status( $forum_id, 'open' ) );
     111        }
     112
     113        /**
     114         * @covers ::bbp_is_forum_status
     115         */
     116        public function test_bbp_is_forum_status_checks_category_ancestors() {
     117                $category_id = $this->factory->forum->create();
     118                bbp_categorize_forum( $category_id );
     119                $forum_id = $this->factory->forum->create( array( 'post_parent' => $category_id ) );
     120                bbp_close_forum( $category_id );
     121
     122                $this->assertTrue( bbp_is_forum_status( $forum_id, 'open', false ) );
     123                $this->assertFalse( bbp_is_forum_status( $forum_id, 'open', true, 'AND' ) );
     124                $this->assertTrue( bbp_is_forum_status( $forum_id, 'open', true, 'OR' ) );
     125                $this->assertFalse( bbp_is_forum_status( $forum_id, 'closed', false, 'OR' ) );
     126                $this->assertTrue( bbp_is_forum_status( $forum_id, 'closed', true, 'or' ) );
     127                $this->assertFalse( bbp_is_forum_status( $forum_id, 'closed', true, 'AND' ) );
     128        }
     129
     130        /**
     131         * @covers ::bbp_is_forum_status
     132         */
     133        public function test_bbp_is_forum_status_requires_all_category_ancestors_for_and() {
     134                $root_id = $this->factory->forum->create();
     135                bbp_categorize_forum( $root_id );
     136                $middle_id = $this->factory->forum->create( array( 'post_parent' => $root_id ) );
     137                bbp_categorize_forum( $middle_id );
     138                $forum_id = $this->factory->forum->create( array( 'post_parent' => $middle_id ) );
     139                bbp_close_forum( $middle_id );
     140
     141                $this->assertSame( array( $middle_id, $root_id ), bbp_get_forum_ancestors( $forum_id ) );
     142                $this->assertFalse( bbp_is_forum_status( $forum_id, 'open', true, 'AND' ) );
     143
     144                bbp_close_forum( $forum_id );
     145                $this->assertTrue( bbp_is_forum_status( $forum_id, 'open', true, 'OR' ) );
     146        }
     147
     148        /**
     149         * @covers ::bbp_is_forum_status
     150         */
     151        public function test_bbp_is_forum_status_ignores_non_category_ancestors() {
     152                $parent_id = $this->factory->forum->create();
     153                $forum_id  = $this->factory->forum->create( array( 'post_parent' => $parent_id ) );
     154                bbp_close_forum( $parent_id );
     155
     156                $this->assertTrue( bbp_is_forum_status( $forum_id, 'open' ) );
     157                $this->assertFalse( bbp_is_forum_status( $forum_id, 'closed', true, 'OR' ) );
     158        }
     159
     160        /**
     161         * @covers ::bbp_is_forum_status
     162         */
     163        public function test_bbp_is_forum_status_filters_result_and_arguments() {
     164                $forum_id = $this->factory->forum->create();
     165                $filter   = function( $match, $count, $id, $status, $check_ancestors, $operator ) use ( $forum_id ) {
     166                        $this->assertFalse( $match );
     167                        $this->assertSame( 0, $count );
     168                        $this->assertSame( $forum_id, $id );
     169                        $this->assertSame( 'closed', $status );
     170                        $this->assertFalse( $check_ancestors );
     171                        $this->assertSame( 'OR', $operator );
     172                        return true;
     173                };
     174                add_filter( 'bbp_is_forum_status', $filter, 10, 6 );
     175                try {
     176                        $this->assertTrue( bbp_is_forum_status( $forum_id, 'closed', false, 'or' ) );
     177                } finally {
     178                        remove_filter( 'bbp_is_forum_status', $filter );
     179                }
    103180        }
    104181
Note: See TracChangeset for help on using the changeset viewer.