Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/09/2021 02:01:40 PM (3 years ago)
Author:
espellcaste
Message:

Improving the group member count routine and the function helper.

The group member count routine was updated to avoid direct, uncached, SQL query and unnecessary cache refresh when a group's Members page was viewed.

is now being used to get the group member count which takes into account users' existence in the site,

the query is now cached and filterable.

was also updated to get the current group from if available.

Props imath
Fixes #7614 and see #6749

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/functions/get-group.php

    r13097 r13103  
    2323    }
    2424
     25    /**
     26     * @group bp_get_group
     27     */
    2528    public function test_bp_get_group_with_no_group() {
    2629        $this->assertFalse( bp_get_group() );
     
    2831    }
    2932
     33    /**
     34     * @group bp_get_group
     35     */
    3036    public function test_bp_get_group_with_id() {
    3137        $g = $this->factory->group->create();
     
    3642    }
    3743
     44    /**
     45     * @group bp_get_group
     46     */
    3847    public function test_bp_get_group_with_slug() {
    3948        $slug = 'test-group';
     
    5059    }
    5160
     61    /**
     62     * @group bp_get_group
     63     */
    5264    public function test_bp_get_group_with_object() {
    5365        $g = $this->factory->group->create_and_get();
     
    5668    }
    5769
     70    /**
     71     * @group bp_get_group
     72     */
    5873    public function test_bp_get_group_from_groups_template() {
    5974        $g = $this->factory->group->create( array( 'status' => 'private' ) );
    6075
    61         // Fake the current group.
    62         $GLOBALS['groups_template'] = new stdClass;
    63         $GLOBALS['groups_template']->group = groups_get_group( $g );
     76        if ( bp_has_groups( array( 'include' => array( $g ) ) ) ) {
     77            while ( bp_groups() ) {
     78                bp_the_group();
     79                $group = bp_get_group();
     80            }
     81        }
    6482
    65         $this->assertSame( $g, bp_get_group()->id );
     83        $this->assertSame( $g, $group->id );
     84    }
     85
     86    /**
     87     * @group bp_get_group
     88     */
     89    public function test_bp_get_group_from_current_group() {
     90        $bp = buddypress();
     91        $g  = $this->factory->group->create_and_get( array( 'name' => 'foo' ) );
     92
     93        // Set the current group.
     94        $bp->groups->current_group = $g;
     95
     96        // Change the name to check the current group was used.
     97        $bp->groups->current_group->name = 'bar';
     98
     99        // Override the name
     100        do_action( 'bp_groups_set_current_group' );
     101
     102        $this->assertSame( 'bar', bp_get_group( $g->id )->name );
    66103    }
    67104}
Note: See TracChangeset for help on using the changeset viewer.