Skip to:
Content

bbPress.org

Changeset 7797


Ignore:
Timestamp:
10/04/2026 09:07:33 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover role, freshness, and visibility repairs.

Verify that admin repair routines remap forum roles, rebuild topic and forum freshness metadata, and recalculate private and hidden forum lists.

In trunk, for 2.7.

See #3695.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/admin/tools.php

    r7796 r7797  
    901901        /**
    902902         * @covers ::bbp_admin_repair_user_roles
    903          * @todo   Implement test_bbp_admin_repair_user_roles().
    904903         */
    905904        public function test_bbp_admin_repair_user_roles() {
    906                 // Remove the following lines when you implement this test.
    907                 $this->markTestIncomplete(
    908                         'This test has not been implemented yet.'
    909                 );
     905                $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
     906                bbp_set_user_role( $user_id, bbp_get_blocked_role() );
     907
     908                $this->assertSame( 0, bbp_admin_repair_user_roles()[0] );
     909                $this->assertSame( bbp_get_default_role(), bbp_get_user_role( $user_id ) );
    910910        }
    911911
    912912        /**
    913913         * @covers ::bbp_admin_repair_freshness
    914          * @todo   Implement test_bbp_admin_repair_freshness().
    915914         */
    916915        public function test_bbp_admin_repair_freshness() {
    917                 // Remove the following lines when you implement this test.
    918                 $this->markTestIncomplete(
    919                         'This test has not been implemented yet.'
    920                 );
     916                $forum_id = $this->factory->forum->create();
     917                $topic_id = $this->factory->topic->create( array( 'post_parent' => $forum_id ) );
     918                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id ) );
     919                update_post_meta( $topic_id, '_bbp_last_reply_id', 999 );
     920                update_post_meta( $forum_id, '_bbp_last_topic_id', 999 );
     921
     922                $this->assertSame( 0, bbp_admin_repair_freshness()[0] );
     923                $this->assertSame( (string) $reply_id, get_post_meta( $topic_id, '_bbp_last_reply_id', true ) );
     924                $this->assertSame( (string) $topic_id, get_post_meta( $forum_id, '_bbp_last_topic_id', true ) );
    921925        }
    922926
    … …  
    952956        /**
    953957         * @covers ::bbp_admin_repair_forum_visibility
    954          * @todo   Implement test_bbp_admin_repair_forum_visibility().
    955958         */
    956959        public function test_bbp_admin_repair_forum_visibility() {
    957                 // Remove the following lines when you implement this test.
    958                 $this->markTestIncomplete(
    959                         'This test has not been implemented yet.'
    960                 );
     960                $private_id = $this->factory->forum->create( array( 'post_status' => bbp_get_private_status_id() ) );
     961                $hidden_id  = $this->factory->forum->create( array( 'post_status' => bbp_get_hidden_status_id() ) );
     962                update_option( '_bbp_private_forums', array() );
     963                update_option( '_bbp_hidden_forums', array() );
     964
     965                $this->assertSame( 0, bbp_admin_repair_forum_visibility()[0] );
     966                $this->assertContains( $private_id, get_option( '_bbp_private_forums' ) );
     967                $this->assertContains( $hidden_id, get_option( '_bbp_hidden_forums' ) );
    961968        }
    962969
Note: See TracChangeset for help on using the changeset viewer.