Skip to:
Content

BuddyPress.org

Changeset 13981


Ignore:
Timestamp:
07/27/2024 04:54:18 PM (11 months ago)
Author:
espellcaste
Message:

Unit tests: Add test that confirms the multisite query for bp_core_get_active_member_count() excludes the spam status.

Props imath, johnjamesjacoby.

Closes https://github.com/buddypress/buddypress/pull/328
Fixes #6155

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-cache.php

    r13971 r13981  
    5454
    5555/**
    56  * Clear member count caches and transients.
     56 * Clear member count caches and/or transients.
    5757 *
    5858 * @since 1.6.0
  • trunk/src/bp-core/bp-core-template.php

    r13897 r13981  
    982982}
    983983    /**
    984      * Return the total member count in your BP instance.
     984     * Return the total member count for the site.
    985985     *
    986986     * Since BuddyPress 1.6, this function has used bp_core_get_active_member_count(),
     
    10001000
    10011001        /**
    1002          * Filters the total member count in your BP instance.
     1002         * Filters the total member count for the site.
    10031003         *
    10041004         * @since 1.2.0
    10051005         *
    1006          * @param int $value Member count.
     1006         * @param int $member_count Member count.
    10071007         */
    10081008        return apply_filters( 'bp_get_total_member_count', bp_core_get_active_member_count() );
  • trunk/src/bp-members/bp-members-functions.php

    r13897 r13981  
    615615
    616616    $count = get_transient( 'bp_active_member_count' );
     617
    617618    if ( false === $count ) {
    618619        $bp = buddypress();
  • trunk/tests/phpunit/testcases/members/functions.php

    r13980 r13981  
    764764        $this->assertNotEmpty( $user->roles );
    765765    }
     766
     767    /**
     768     * @ticket BP6155
     769     */
     770    public function test_bp_core_get_active_member_count_excludes_spammed_users() {
     771        $this->assertSame( 0, bp_core_get_active_member_count() );
     772        $this->assertSame( 0, bp_get_total_member_count() );
     773
     774        $u1 = self::factory()->user->create();
     775        $u2 = self::factory()->user->create();
     776
     777        // The two users were created, but they are not "active" yet.
     778        $this->assertSame( 0, bp_core_get_active_member_count() );
     779        $this->assertSame( 0, bp_get_total_member_count() );
     780
     781        // Fake their first activity to make them "active".
     782        do_action( 'bp_first_activity_for_member', $u1 );
     783        do_action( 'bp_first_activity_for_member', $u2 );
     784
     785        $this->assertSame( 2, bp_core_get_active_member_count() );
     786        $this->assertSame( 2, bp_get_total_member_count() );
     787
     788        // Spam user 2.
     789        if ( is_multisite() ) {
     790            wp_update_user( array( 'ID' => $u2, 'spam' => '1' ) );
     791        } else {
     792            bp_core_process_spammer_status( $u2, 'spam' );
     793        }
     794
     795        // Check if user 2 is a spammer.
     796        $this->assertTrue( bp_is_user_spammer( $u2 ) );
     797
     798        // Recount the active member count.
     799        $this->assertSame( 1, bp_core_get_active_member_count() );
     800        $this->assertSame( 1, bp_get_total_member_count() );
     801
     802        // Delete user 1.
     803        if ( is_multisite() ) {
     804            wpmu_delete_user( $u1 );
     805        } else {
     806            wp_delete_user( $u1 );
     807        }
     808
     809        $this->assertSame( 0, bp_core_get_active_member_count() );
     810        $this->assertSame( 0, bp_get_total_member_count() );
     811    }
    766812}
Note: See TracChangeset for help on using the changeset viewer.