Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/06/2014 07:09:04 PM (10 years ago)
Author:
boonebgorges
Message:

Add integration tests for bp_group_has_membership_requests()

These tests check to see that the results of a default query are correct, and
that the results are formatted as expected. This is in anticipation of
refactoring related to #5440

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/groups/template.php

    r8045 r8065  
    528528        $this->assertEquals( array( $users[ 9 ], $users[ 8 ], $users[ 7 ], $users[ 6 ], $users[ 5 ], ), $invites_template->invites );
    529529    }
     530
     531    /**
     532     * Checks for proper queried items
     533     *
     534     * @group bp_group_has_membership_requests
     535     * @group BP_Group_Membership_Requests_Template
     536     */
     537    public function test_bp_group_has_membership_requests_results() {
     538        $u1 = $this->create_user( array(
     539            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ),
     540        ) );
     541
     542        $g = $this->factory->group->create( array(
     543            'creator_id' => $u1,
     544        ) );
     545
     546        $users = array();
     547        $memberships = array();
     548        for ( $i = 1; $i < 15; $i++ ) {
     549            $users[ $i ] = $this->create_user( array(
     550                'last_activity' => gmdate( 'Y-m-d H:i:s', time() - $i ),
     551            ) );
     552
     553            $memberships[ $i ] = $this->add_user_to_group( $users[ $i ], $g, array(
     554                'date_modified' => gmdate( 'Y-m-d H:i:s', time() - $i ),
     555                'is_confirmed' => 0,
     556                'inviter_id' => 0,
     557                'invite_sent' => false,
     558            ) );
     559        }
     560
     561        // Fake the current group
     562        global $groups_template;
     563
     564        if ( ! isset( $groups_template ) ) {
     565            $groups_template = new stdClass;
     566        }
     567
     568        if ( ! isset( $groups_template->group ) ) {
     569            $groups_template->group = new stdClass;
     570        }
     571
     572        $groups_template->group->id = $g;
     573
     574        // Populate the global
     575        bp_group_has_membership_requests( array(
     576            'group_id' => $g,
     577        ) );
     578
     579        global $requests_template;
     580
     581        $expected_user_ids = array();
     582        $expected_mem_ids = array();
     583        for ( $j = 1; $j <= 10; $j++ ) {
     584            $expected_user_ids[] = (string) $users[ $j ];
     585            $expected_mem_ids[] = (string) $memberships[ $j ];
     586        }
     587
     588        $this->assertEquals( $expected_user_ids, wp_list_pluck( $requests_template->requests, 'user_id' ) );
     589        $this->assertEquals( $expected_mem_ids, wp_list_pluck( $requests_template->requests, 'id' ) );
     590    }
     591
     592    /**
     593     * Checks that the requests_template object is properly formatted
     594     *
     595     * @group bp_group_has_membership_requests
     596     * @group BP_Group_Membership_Requests_Template
     597     */
     598    public function test_bp_group_has_membership_requests_format() {
     599        $u1 = $this->create_user( array(
     600            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ),
     601        ) );
     602
     603        $g = $this->factory->group->create( array(
     604            'creator_id' => $u1,
     605        ) );
     606
     607        $time = time();
     608
     609        $user = $this->create_user( array(
     610            'last_activity' => gmdate( 'Y-m-d H:i:s', $time ),
     611        ) );
     612
     613        $membership = $this->add_user_to_group( $user, $g, array(
     614            'date_modified' => gmdate( 'Y-m-d H:i:s', $time ),
     615            'is_confirmed' => 0,
     616            'inviter_id' => 0,
     617            'invite_sent' => false,
     618        ) );
     619
     620        // Fake the current group
     621        global $groups_template;
     622
     623        if ( ! isset( $groups_template ) ) {
     624            $groups_template = new stdClass;
     625        }
     626
     627        if ( ! isset( $groups_template->group ) ) {
     628            $groups_template->group = new stdClass;
     629        }
     630
     631        $groups_template->group->id = $g;
     632
     633        // Populate the global
     634        bp_group_has_membership_requests( array(
     635            'group_id' => $g,
     636            'per_page' => 1,
     637            'max' => 1,
     638        ) );
     639
     640        global $requests_template;
     641
     642        $expected = new stdClass;
     643        $expected->id = $membership;
     644        $expected->group_id = $g;
     645        $expected->user_id = $user;
     646        $expected->inviter_id = '0';
     647        $expected->is_admin = '0';
     648        $expected->is_mod = '0';
     649        $expected->user_title = '';
     650        $expected->date_modified = gmdate( 'Y-m-d H:i:s', $time );
     651        $expected->comments = '';
     652        $expected->is_confirmed = '0';
     653        $expected->is_banned = '0';
     654        $expected->invite_sent = '0';
     655
     656        // Check each expected value. If there are more in the results,
     657        // that's OK
     658        foreach ( get_object_vars( $expected ) as $k => $v ) {
     659            $this->assertEquals( $v, $requests_template->requests[0]->{$k} );
     660        }
     661    }
    530662}
Note: See TracChangeset for help on using the changeset viewer.