/**
 * Check whether a user has an outstanding membership request for a given group.
 *
 * @since 1.0.0
 *
 * @param int $user_id  ID of the user.
 * @param int $group_id ID of the group.
 * @return int|bool ID of the membership if found, otherwise false.
 */
function groups_check_for_membership_request($user_id, $group_id)
{
    $request = false;
    $user_groups = bp_get_user_groups($user_id, array('is_confirmed' => false, 'is_banned' => false, 'is_admin' => null, 'is_mod' => null));
    if (isset($user_groups[$group_id]) && 0 === $user_groups[$group_id]->inviter_id) {
        $request = $user_groups[$group_id]->id;
    }
    return $request;
}
 /**
  * @group cache
  */
 public function test_cache_should_be_invalidated_on_group_request_acceptance()
 {
     // For `wp_mail()`.
     $server_name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
     $_SERVER['SERVER_NAME'] = '';
     groups_send_membership_request(self::$user, self::$groups[2]);
     // Populate cache.
     $g1 = bp_get_user_groups(self::$user);
     $m = new BP_Groups_Member(self::$user, self::$groups[2]);
     groups_accept_membership_request($m->id, self::$user, self::$groups[2]);
     // For `wp_mail()`.
     if (is_null($server_name)) {
         unset($_SERVER['SERVER_NAME']);
     } else {
         $_SERVER['SERVER_NAME'] = $server_name;
     }
     $expected = array(self::$groups[0], self::$groups[1], self::$groups[2]);
     $found = bp_get_user_groups(self::$user);
     $this->assertEqualSets($expected, array_keys($found));
 }