Skip to:
Content

BuddyPress.org

Ticket #7677: 7677.02.patch

File 7677.02.patch, 1.8 KB (added by cyclic, 4 years ago)

updated patch with test to check group->mods as well as group->admins

  • src/bp-groups/classes/class-bp-groups-group.php

    diff --git src/bp-groups/classes/class-bp-groups-group.php src/bp-groups/classes/class-bp-groups-group.php
    index 0add64940..5f79e6fb9 100644
    class BP_Groups_Group { 
    560560                $mod_ids = BP_Groups_Member::get_group_moderator_ids( $this->id );
    561561                $mod_ids_plucked = wp_list_pluck( $mod_ids, 'user_id' );
    562562
    563                 $admin_mod_users = get_users( array(
    564                         'include' => array_merge( $admin_ids_plucked, $mod_ids_plucked ),
    565                         'blog_id' => null,
    566                 ) );
     563                $admin_mod_ids = array_merge( $admin_ids_plucked, $mod_ids_plucked );
     564                $admin_mod_users = array();
     565
     566                if ( ! empty( $admin_mod_ids ) ) {
     567                        $admin_mod_users = get_users( array(
     568                                'include' => $admin_mod_ids,
     569                                'blog_id' => null,
     570                        ) );
     571                }
    567572
    568573                $admin_objects = $mod_objects = array();
    569574                foreach ( $admin_mod_users as $admin_mod_user ) {
  • tests/phpunit/testcases/groups/class-bp-groups-group.php

    diff --git tests/phpunit/testcases/groups/class-bp-groups-group.php tests/phpunit/testcases/groups/class-bp-groups-group.php
    index 816b856b3..d6800f9bf 100644
    class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { 
    15151515                $this->assertEqualSets( array( $user_1->ID ), wp_list_pluck( $group->admins, 'user_id' ) );
    15161516        }
    15171517
     1518        /**
     1519         * @ticket BP7677
     1520         * @group rw
     1521         */
     1522        public function test_demoting_sole_admin() {
     1523                $user = self::factory()->user->create_and_get();
     1524                $group = self::factory()->group->create_and_get( array(
     1525                        'creator_id' => $user->ID,
     1526                ) );
     1527                $member = new BP_Groups_Member( $user->ID, $group->id );
     1528                $member->demote();
     1529
     1530                $this->assertEmpty( $group->admins );
     1531                $this->assertEmpty( $group->mods );
     1532        }
     1533
    15181534        /**
    15191535         * @ticket BP5451
    15201536         */