Skip to:
Content

BuddyPress.org

Changeset 7143


Ignore:
Timestamp:
06/04/2013 03:04:18 AM (12 years ago)
Author:
boonebgorges
Message:

In BP_Group_Member_Query, when no members are found of a type, ensure the query fails to return results

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r7141 r7143  
    994994
    995995        $group_member_ids = $this->get_group_member_ids();
     996
     997        // If the group member query returned no users, bail with an
     998        // array that will guarantee no matches for BP_User_Query
     999        if ( empty( $group_member_ids ) ) {
     1000            return array( 0 );
     1001        }
    9961002
    9971003        if ( ! empty( $include ) ) {
  • trunk/tests/testcases/groups/class-bp-group-member-query.php

    r7141 r7143  
    223223    }
    224224
     225    public function test_group_has_no_members() {
     226        $g = $this->factory->group->create();
     227        $u1 = $this->create_user();
     228
     229        $query_members = new BP_Group_Member_Query( array(
     230            'group_id' => $g,
     231            'group_role' => array( 'member', 'mod', 'admin' ),
     232        ) );
     233
     234        $ids = wp_parse_id_list( array_keys( $query_members->results ) );
     235        $this->assertEquals( array(), $ids );
     236    }
     237
     238    public function test_group_has_no_members_of_role_mod() {
     239        $g = $this->factory->group->create();
     240        $u1 = $this->create_user();
     241
     242        $this->add_user_to_group( $u1, $g, array( 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ) ) );
     243
     244        $query_members = new BP_Group_Member_Query( array(
     245            'group_id' => $g,
     246            'group_role' => array( 'mod' ),
     247        ) );
     248
     249        $ids = wp_parse_id_list( array_keys( $query_members->results ) );
     250        $this->assertEquals( array(), $ids );
     251    }
    225252
    226253}
Note: See TracChangeset for help on using the changeset viewer.