Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/05/2017 12:00:40 AM (8 years ago)
Author:
dcavins
Message:

Add 'slug' parameter to BP_Groups_Group::get().

Add $slug parameter to groups_get_groups() and its underlying
function BP_Groups_Group::get(). Find a group or groups by passing a
single slug, a comma- or space-separated list of slugs, or any array of
slugs.

Fixes #7496.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php

    r11384 r11523  
    20122012        $this->assertEqualSets( array( $g1, $g4 ), $found );
    20132013    }
     2014
     2015    /**
     2016     * @group get_by_slug
     2017     */
     2018    public function test_get_by_slug() {
     2019        $g1 = $this->factory->group->create(array(
     2020            'slug'      => 'apr'
     2021        ) );
     2022        $g2 = $this->factory->group->create( array(
     2023            'slug'      => 'jan'
     2024        ) );
     2025        $g3 = $this->factory->group->create( array(
     2026            'slug'      => 'mar'
     2027        ) );
     2028
     2029        $groups = BP_Groups_Group::get( array(
     2030            'slug' => array( 'apr', 'mar' ),
     2031        ) );
     2032
     2033        $found = wp_list_pluck( $groups['groups'], 'id' );
     2034        $this->assertEqualSets( array( $g1, $g3 ), $found );
     2035    }
     2036
     2037    /**
     2038     * @group get_by_slug
     2039     */
     2040    public function test_get_by_slug_accept_string() {
     2041        $g1 = $this->factory->group->create(array(
     2042            'slug'      => 'apr'
     2043        ) );
     2044        $g2 = $this->factory->group->create( array(
     2045            'slug'      => 'jan'
     2046        ) );
     2047        $g3 = $this->factory->group->create( array(
     2048            'slug'      => 'mar'
     2049        ) );
     2050
     2051        $groups = BP_Groups_Group::get( array(
     2052            'slug' => 'jan',
     2053        ) );
     2054
     2055        $found = wp_list_pluck( $groups['groups'], 'id' );
     2056        $this->assertEqualSets( array( $g2 ), $found );
     2057    }
     2058
     2059    /**
     2060     * @group get_by_slug
     2061     */
     2062    public function test_get_by_slug_accept_comma_separated_string() {
     2063        $g1 = $this->factory->group->create(array(
     2064            'slug'      => 'apr'
     2065        ) );
     2066        $g2 = $this->factory->group->create( array(
     2067            'slug'      => 'jan'
     2068        ) );
     2069        $g3 = $this->factory->group->create( array(
     2070            'slug'      => 'mar'
     2071        ) );
     2072
     2073        $groups = BP_Groups_Group::get( array(
     2074            'slug' => 'apr, mar',
     2075        ) );
     2076
     2077        $found = wp_list_pluck( $groups['groups'], 'id' );
     2078        $this->assertEqualSets( array( $g1, $g3 ), $found );
     2079    }
     2080
     2081    /**
     2082     * @group get_by_slug
     2083     */
     2084    public function test_get_by_slug_accept_space_separated_string() {
     2085        $g1 = $this->factory->group->create(array(
     2086            'slug'      => 'apr'
     2087        ) );
     2088        $g2 = $this->factory->group->create( array(
     2089            'slug'      => 'jan'
     2090        ) );
     2091        $g3 = $this->factory->group->create( array(
     2092            'slug'      => 'mar'
     2093        ) );
     2094
     2095        $groups = BP_Groups_Group::get( array(
     2096            'slug' => 'apr mar',
     2097        ) );
     2098
     2099        $found = wp_list_pluck( $groups['groups'], 'id' );
     2100        $this->assertEqualSets( array( $g1, $g3 ), $found );
     2101    }
     2102
    20142103}
    20152104
Note: See TracChangeset for help on using the changeset viewer.