Skip to:
Content

bbPress.org

Changeset 7821


Ignore:
Timestamp:
10/04/2026 06:24:47 PM (3 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover user nicename and author-change helpers.

Exercise nicename lookup and ID conversion, including input sanitization and filters. Assert that changing topic and reply authors recalculates engagement membership, and identify existing profile-permission coverage.

In trunk, for 2.7.

See #3695.

Location:
trunk/tests/phpunit/testcases/users/functions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/users/functions/counts.php

    r7526 r7821  
    654654        /**
    655655         * @covers ::bbp_update_counts_on_post_author_change
     656         * @covers ::bbp_recalculate_engagements_on_post_author_change
    656657         */
    657658        public function test_changing_post_authors_updates_user_counts() {
    … …  
    675676                wp_update_post( array( 'ID' => $topic_id, 'post_author' => $new_user_id ) );
    676677                $this->assertSame( 2, bbp_get_topic_voice_count( $topic_id, true ) );
     678                $this->assertEqualsCanonicalizing( array( $old_user_id, $new_user_id ), bbp_get_topic_engagements( $topic_id ) );
    677679
    678680                wp_update_post( array( 'ID' => $reply_id, 'post_author' => $new_user_id ) );
    679681                $this->assertSame( 1, bbp_get_topic_voice_count( $topic_id, true ) );
     682                $this->assertSame( array( $new_user_id ), bbp_get_topic_engagements( $topic_id ) );
    680683
    681684                $this->assertSame( 0, bbp_get_user_topic_count( $old_user_id, true ) );
  • trunk/tests/phpunit/testcases/users/functions/functions.php

    r7820 r7821  
    261261
    262262                $this->assertTrue( $r );
     263        }
     264
     265        /**
     266         * @covers ::bbp_get_user_ids_from_nicenames
     267         */
     268        public function test_bbp_get_user_ids_from_nicenames() {
     269                $first_id  = $this->factory->user->create( array( 'user_nicename' => 'bbp-nicename-a' ) );
     270                $second_id = $this->factory->user->create( array( 'user_nicename' => 'bbp-nicename-b' ) );
     271                $seen      = null;
     272                $record    = function ( $ids, $nicenames ) use ( &$seen ) {
     273                        $seen = $nicenames;
     274                        return $ids;
     275                };
     276
     277                $this->assertSame( array(), bbp_get_user_ids_from_nicenames() );
     278                $this->assertSame( array(), bbp_get_user_ids_from_nicenames( 'missing-nicename' ) );
     279                add_filter( 'bbp_get_user_ids_from_nicenames', $record, 10, 2 );
     280
     281                try {
     282                        $ids = bbp_get_user_ids_from_nicenames( 'BBP NICENAME A,BBP NICENAME B' );
     283                        $this->assertEqualsCanonicalizing( array( $first_id, $second_id ), array_map( 'intval', $ids ) );
     284                        $this->assertSame( array( 'bbp-nicename-a', 'bbp-nicename-b' ), $seen );
     285                } finally {
     286                        remove_filter( 'bbp_get_user_ids_from_nicenames', $record, 10 );
     287                }
     288        }
     289
     290        /**
     291         * @covers ::bbp_get_user_nicenames_from_ids
     292         */
     293        public function test_bbp_get_user_nicenames_from_ids() {
     294                $first_id  = $this->factory->user->create( array( 'user_nicename' => 'bbp-nicename-a' ) );
     295                $second_id = $this->factory->user->create( array( 'user_nicename' => 'bbp-nicename-b' ) );
     296                $input     = array( $first_id, $second_id );
     297                $seen      = null;
     298                $record    = function ( $nicenames, $ids ) use ( &$seen ) {
     299                        $seen = $ids;
     300                        return $nicenames;
     301                };
     302
     303                $this->assertSame( array(), bbp_get_user_nicenames_from_ids() );
     304                $this->assertSame( array(), bbp_get_user_nicenames_from_ids( array( PHP_INT_MAX ) ) );
     305                add_filter( 'bbp_get_user_nicenames_from_ids', $record, 10, 2 );
     306
     307                try {
     308                        $nicenames = bbp_get_user_nicenames_from_ids( $input );
     309                        $this->assertEqualsCanonicalizing( array( 'bbp-nicename-a', 'bbp-nicename-b' ), $nicenames );
     310                        $this->assertSame( $input, $seen );
     311                } finally {
     312                        remove_filter( 'bbp_get_user_nicenames_from_ids', $record, 10 );
     313                }
    263314        }
    264315
  • trunk/tests/phpunit/testcases/users/functions/permissions.php

    r7689 r7821  
    317317        }
    318318
     319        /**
     320         * @covers ::bbp_filter_user_edit_post_data
     321         */
    319322        public function test_user_edit_post_data_enforces_field_permissions() {
    320323                $moderator_id = $this->factory->user->create();
    … …  
    349352        }
    350353
     354        /**
     355         * @covers ::bbp_filter_user_edit_post_data
     356         */
    351357        public function test_user_edit_post_data_removes_contact_methods_with_profile_fields() {
    352358                $moderator_id = $this->factory->user->create();
    … …  
    373379        }
    374380
     381        /**
     382         * @covers ::bbp_user_email_change_requires_confirmation
     383         */
    375384        public function test_email_confirmation_policy_distinguishes_self_and_moderator_edits() {
    376385                $moderator_id = $this->factory->user->create();
Note: See TracChangeset for help on using the changeset viewer.