Skip to:
Content

BuddyPress.org

Ticket #5649: 5649.02.patch

File 5649.02.patch, 2.3 KB (added by imath, 11 years ago)
  • src/bp-xprofile/bp-xprofile-classes.php

    diff --git src/bp-xprofile/bp-xprofile-classes.php src/bp-xprofile/bp-xprofile-classes.php
    index 522bb45..69a5144 100644
    class BP_XProfile_Group { 
    150150
    151151                $where_sql = '';
    152152
    153                 if ( !empty( $profile_group_id ) )
     153                if ( ! empty( $profile_group_id ) ) {
    154154                        $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
    155                 elseif ( $exclude_groups )
    156                         $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})");
     155                } else if ( $exclude_groups ) {
     156                        $exclude_groups = join( ',', wp_parse_id_list( $exclude_groups ) );
     157                        $where_sql = "WHERE g.id NOT IN ({$exclude_groups})";
     158                }
    157159
    158160                if ( ! empty( $hide_empty_groups ) ) {
    159161                        $group_ids = $wpdb->get_col( "SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" );
  • tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php

    diff --git tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php
    index 46f548f..699911b 100644
    class BP_Tests_BP_XProfile_Group extends BP_UnitTestCase { 
    6767
    6868                $this->assertSame( $expected, $found );
    6969        }
     70
     71        /**
     72         * @group get_xprofile_groups
     73         */
     74        public function test_get_xprofile_groups() {
     75                $g1 = $this->factory->xprofile_group->create();
     76                $g2 = $this->factory->xprofile_group->create();
     77                $g3 = $this->factory->xprofile_group->create();
     78
     79                $all = BP_XProfile_Group::get();
     80                $all_results = array_map( 'absint', wp_list_pluck( $all, 'id' ) );
     81
     82                $e1 = array( $g1, $g2 );
     83                $groups1 = BP_XProfile_Group::get( array(
     84                        'exclude_groups'      => implode( ',', $e1 ),
     85                ) );
     86
     87                $r_groups1 = array_map( 'absint', wp_list_pluck( $groups1, 'id' ) );
     88                $found1 = array_diff( $all_results, $r_groups1 );
     89
     90                $this->assertSame( $e1, array_merge( $found1, array() ) );
     91
     92
     93                $e2 = array( $g2, $g3 );
     94                $groups2 = BP_XProfile_Group::get( array(
     95                        'exclude_groups'      => implode( ',', $e2 ),
     96                ) );
     97
     98                $r_groups2 = array_map( 'absint', wp_list_pluck( $groups2, 'id' ) );
     99                $found2 = array_diff( $all_results, $r_groups2 );
     100
     101                $this->assertSame( $e2, array_merge( $found2, array() ) );
     102        }
    70103}