Skip to:
Content

BuddyPress.org

Ticket #6209: 6209-invites-requests.01.patch

File 6209-invites-requests.01.patch, 11.4 KB (added by dcavins, 5 years ago)

Test coverage for groups_delete_membership_request(), groups_reject_membership_request(), groups_reject_invite(), groups_uninvite_user(), groups_delete_invite()

  • tests/phpunit/testcases/groups/class-bp-groups-member.php

    diff --git tests/phpunit/testcases/groups/class-bp-groups-member.php tests/phpunit/testcases/groups/class-bp-groups-member.php
    index 7608130..0abe39e 100644
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    2525                return $invite->id;
    2626        }
    2727
     28        public static function create_group_membership_request( $user_id, $group_id ) {
     29                $request                = new BP_Groups_Member;
     30                $request->group_id      = $group_id;
     31                $request->user_id       = $user_id;
     32                $request->date_modified = bp_core_current_time();
     33                $request->inviter_id    = 0;
     34                $request->is_confirmed  = 0;
     35
     36                $request->save();
     37                return $request->id;
     38        }
     39
    2840        public function test_get_recently_joined_with_filter() {
    2941                $g1 = $this->factory->group->create( array(
    3042                        'name' => 'Tab',
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 
    223235
    224236                $this->set_current_user( $old_current_user );
    225237        }
     238
     239        /**
     240         * @group bp_groups_invitations and bp_group_membership_requests
     241         *
     242         * These functions all use BP_Groups_Member::delete()
     243         *              groups_delete_membership_request( $membership_id, $user_id = 0, $group_id = 0 )
     244         *              groups_reject_membership_request( $membership_id, $user_id = 0, $group_id = 0 )
     245         *              groups_reject_invite( $user_id, $group_id )
     246         *              groups_uninvite_user( $user_id, $group_id )
     247         * This function uses a targeted BP_Groups_Member::delete_invite()
     248         *              groups_delete_invite( $user_id, $group_id )
     249         */
     250        public function test_bp_groups_reject_membership_request() {
     251                $u1 = $this->factory->user->create();
     252                $u2 = $this->factory->user->create();
     253                $u3 = $this->factory->user->create();
     254                $g = $this->factory->group->create( array(
     255                        'status' => 'private',
     256                ) );
     257
     258                $now = time();
     259                $this->add_user_to_group( $u1, $g, array(
     260                        'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     261                ) );
     262
     263                // Membership requests should be removed.
     264                self::create_group_membership_request( $u3, $g );
     265                $u3_has_request_before = groups_check_for_membership_request( $u3, $g );
     266                // Result of groups_check_for_membership_request is a numeric string.
     267                $this->assertTrue( is_numeric( $u3_has_request_before ) && $u3_has_request_before > 0 );
     268                groups_reject_membership_request( null, $u3, $g );
     269                $u3_has_request_after = groups_check_for_membership_request( $u3, $g );
     270                $this->assertEquals( $u3_has_request_after, 0 );
     271
     272                // Outstanding invitations should be left intact.
     273                // @TODO: Fails
     274                self::invite_user_to_group( $u2, $g, $u1 );
     275                $u2_has_invite_before = groups_check_user_has_invite( $u2, $g );
     276                // Result of groups_check_user_has_invite is a numeric string.
     277                $this->assertTrue( is_numeric( $u2_has_invite_before ) && $u2_has_invite_before > 0 );
     278                groups_reject_membership_request( null, $u2, $g );
     279                $u2_has_invite_after = groups_check_user_has_invite( $u2, $g );
     280                // If nothing changed, the before and after values will be the same.
     281                // $this->assertEquals( $u2_has_invite_before, $u2_has_invite_after );
     282
     283                // Confirmed memberships should be left intact.
     284                // @TODO: Fails
     285                $u1_is_member_before = groups_is_user_member( $u1, $g );
     286                // Result of groups_is_user_member is a numeric string.
     287                $this->assertTrue( is_numeric( $u1_is_member_before ) && $u1_is_member_before > 0 );
     288                groups_reject_membership_request( null, $u1, $g );
     289                $u1_is_member_after = groups_is_user_member( $u1, $g );
     290                // If nothing changed, the before and after values will be the same.
     291                // $this->assertEquals( $u1_is_member_before, $u1_is_member_after );
     292        }
     293
     294        public function test_bp_groups_delete_membership_request() {
     295                $u1 = $this->factory->user->create();
     296                $u2 = $this->factory->user->create();
     297                $u3 = $this->factory->user->create();
     298                $g = $this->factory->group->create( array(
     299                        'status' => 'private',
     300                ) );
     301
     302                $now = time();
     303                $this->add_user_to_group( $u1, $g, array(
     304                        'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     305                ) );
     306
     307                // Membership requests should be removed.
     308                self::create_group_membership_request( $u3, $g );
     309                $u3_has_request_before = groups_check_for_membership_request( $u3, $g );
     310                // Result of groups_check_for_membership_request is a numeric string.
     311                $this->assertTrue( is_numeric( $u3_has_request_before ) && $u3_has_request_before > 0 );
     312                groups_delete_membership_request( null, $u3, $g );
     313                $u3_has_request_after = groups_check_for_membership_request( $u3, $g );
     314                $this->assertEquals( $u3_has_request_after, 0 );
     315
     316                // Outstanding invitations should be left intact.
     317                // @TODO: Fails
     318                self::invite_user_to_group( $u2, $g, $u1 );
     319                $u2_has_invite_before = groups_check_user_has_invite( $u2, $g );
     320                // Result of groups_check_user_has_invite is a numeric string.
     321                $this->assertTrue( is_numeric( $u2_has_invite_before ) && $u2_has_invite_before > 0 );
     322                groups_delete_membership_request( null, $u2, $g );
     323                $u2_has_invite_after = groups_check_user_has_invite( $u2, $g );
     324                // If nothing changed, the before and after values will be the same.
     325                // $this->assertEquals( $u2_has_invite_before, $u2_has_invite_after );
     326
     327                // Confirmed memberships should be left intact.
     328                // @TODO: Fails
     329                $u1_is_member_before = groups_is_user_member( $u1, $g );
     330                // Result of groups_is_user_member is a numeric string.
     331                $this->assertTrue( is_numeric( $u1_is_member_before ) && $u1_is_member_before > 0 );
     332                groups_delete_membership_request( null, $u1, $g );
     333                $u1_is_member_after = groups_is_user_member( $u1, $g );
     334                // If nothing changed, the before and after values will be the same.
     335                // $this->assertEquals( $u1_is_member_before, $u1_is_member_after );
     336        }
     337
     338        public function test_bp_groups_reject_invite() {
     339                $u1 = $this->factory->user->create();
     340                $u2 = $this->factory->user->create();
     341                $u3 = $this->factory->user->create();
     342                $g = $this->factory->group->create( array(
     343                        'status' => 'private',
     344                ) );
     345
     346                $now = time();
     347                $this->add_user_to_group( $u1, $g, array(
     348                        'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     349                ) );
     350
     351                // The invitation should be removed.
     352                self::invite_user_to_group( $u2, $g, $u1 );
     353                $u2_has_invite_before = groups_check_user_has_invite( $u2, $g );
     354                // Result of groups_check_user_has_invite is a numeric string.
     355                $this->assertTrue( is_numeric( $u2_has_invite_before ) && $u2_has_invite_before > 0 );
     356                groups_reject_invite( $u2, $g );
     357                $u2_has_invite_after = groups_check_user_has_invite( $u2, $g );
     358                $this->assertEquals( $u2_has_invite_after, 0 );
     359
     360                // Membership requests should be left intact.
     361                // @TODO: Fails
     362                self::create_group_membership_request( $u3, $g );
     363                $u3_has_request_before = groups_check_for_membership_request( $u3, $g );
     364                // Result of groups_check_for_membership_request is a numeric string.
     365                $this->assertTrue( is_numeric( $u3_has_request_before ) && $u3_has_request_before > 0 );
     366                groups_reject_invite( $u3, $g );
     367                $u3_has_request_after = groups_check_for_membership_request( $u3, $g );
     368                // If nothing changed, the before and after values will be the same.
     369                // $this->assertEquals( $u3_has_request_before, $u3_has_request_after );
     370
     371                // Confirmed memberships should be left intact.
     372                // @TODO: Fails
     373                $u1_is_member_before = groups_is_user_member( $u1, $g );
     374                // Result of groups_is_user_member is a numeric string.
     375                $this->assertTrue( is_numeric( $u1_is_member_before ) && $u1_is_member_before > 0 );
     376                groups_reject_invite( $u1, $g );
     377                $u1_is_member_after = groups_is_user_member( $u1, $g );
     378                // If nothing changed, the before and after values will be the same.
     379                // $this->assertEquals( $u1_is_member_before, $u1_is_member_after );
     380        }
     381
     382        public function test_bp_groups_delete_invite() {
     383                $u1 = $this->factory->user->create();
     384                $u2 = $this->factory->user->create();
     385                $u3 = $this->factory->user->create();
     386                $g = $this->factory->group->create( array(
     387                        'status' => 'private',
     388                ) );
     389
     390                $now = time();
     391                $this->add_user_to_group( $u1, $g, array(
     392                        'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     393                ) );
     394
     395                // The invitation should be removed.
     396                self::invite_user_to_group( $u2, $g, $u1 );
     397                $u2_has_invite_before = groups_check_user_has_invite( $u2, $g );
     398                // Result of groups_check_user_has_invite is a numeric string.
     399                $this->assertTrue( is_numeric( $u2_has_invite_before ) && $u2_has_invite_before > 0 );
     400                groups_delete_invite( $u2, $g );
     401                $u2_has_invite_after = groups_check_user_has_invite( $u2, $g );
     402                $this->assertEquals( $u2_has_invite_after, 0 );
     403
     404                // Membership requests should be left intact.
     405                self::create_group_membership_request( $u3, $g );
     406                $u3_has_request_before = groups_check_for_membership_request( $u3, $g );
     407                // Result of groups_check_for_membership_request is a numeric string.
     408                $this->assertTrue( is_numeric( $u3_has_request_before ) && $u3_has_request_before > 0 );
     409                groups_delete_invite( $u3, $g );
     410                $u3_has_request_after = groups_check_for_membership_request( $u3, $g );
     411                // If nothing changed, the before and after values will be the same.
     412                $this->assertEquals( $u3_has_request_before, $u3_has_request_after );
     413
     414                // Confirmed memberships should be left intact.
     415                $u1_is_member_before = groups_is_user_member( $u1, $g );
     416                // Result of groups_is_user_member is a numeric string.
     417                $this->assertTrue( is_numeric( $u1_is_member_before ) && $u1_is_member_before > 0 );
     418                groups_delete_invite( $u1, $g );
     419                $u1_is_member_after = groups_is_user_member( $u1, $g );
     420                // If nothing changed, the before and after values will be the same.
     421                $this->assertEquals( $u1_is_member_before, $u1_is_member_after );
     422        }
     423
     424        public function test_bp_groups_uninvite_user() {
     425                $u1 = $this->factory->user->create();
     426                $u2 = $this->factory->user->create();
     427                $u3 = $this->factory->user->create();
     428                $g = $this->factory->group->create( array(
     429                        'status' => 'private',
     430                ) );
     431
     432                $now = time();
     433                $this->add_user_to_group( $u1, $g, array(
     434                        'date_modified' => date( 'Y-m-d H:i:s', $now - 60 ),
     435                ) );
     436
     437                // The invitation should be removed.
     438                self::invite_user_to_group( $u2, $g, $u1 );
     439                $u2_has_invite_before = groups_check_user_has_invite( $u2, $g );
     440                // Result of groups_check_user_has_invite is a numeric string.
     441                $this->assertTrue( is_numeric( $u2_has_invite_before ) && $u2_has_invite_before > 0 );
     442                groups_uninvite_user( $u2, $g );
     443                $u2_has_invite_after = groups_check_user_has_invite( $u2, $g );
     444                $this->assertEquals( $u2_has_invite_after, 0 );
     445
     446                // Membership requests should be left intact.
     447                // @TODO: Fails
     448                self::create_group_membership_request( $u3, $g );
     449                $u3_has_request_before = groups_check_for_membership_request( $u3, $g );
     450                // Result of groups_check_for_membership_request is a numeric string.
     451                $this->assertTrue( is_numeric( $u3_has_request_before ) && $u3_has_request_before > 0 );
     452                groups_uninvite_user( $u3, $g );
     453                $u3_has_request_after = groups_check_for_membership_request( $u3, $g );
     454                // If nothing changed, the before and after values will be the same.
     455                // $this->assertEquals( $u3_has_request_before, $u3_has_request_after );
     456
     457                // Confirmed memberships should be left intact.
     458                // @TODO: Fails
     459                $u1_is_member_before = groups_is_user_member( $u1, $g );
     460                // Result of groups_is_user_member is a numeric string.
     461                $this->assertTrue( is_numeric( $u1_is_member_before ) && $u1_is_member_before > 0 );
     462                groups_uninvite_user( $u1, $g );
     463                $u1_is_member_after = groups_is_user_member( $u1, $g );
     464                // If nothing changed, the before and after values will be the same.
     465                // $this->assertEquals( $u1_is_member_before, $u1_is_member_after );
     466        }
    226467}
    227468