Skip to:
Content

BuddyPress.org

Changeset 9120


Ignore:
Timestamp:
11/03/2014 06:14:06 PM (6 years ago)
Author:
djpaul
Message:

Unit Tests, Groups: update the group factory to set the group's creator_id if one was not passed to the factory.

This is a quicker way of updating hundreds of unit tests where we've previously had a bug that was creating Groups without a valid group creator being set. See #5983 for related changes.

A few tests are counting the number of users in specific circumstances, so those eight tests have been individually updated so that they pass a valid creator_id without us having to refactor the entire test.

The test_group_has_no_members test has also been removed as it is impossible for a group to have no members. This test used to work because of this bug.

Location:
trunk/tests/phpunit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory.php

    r9117 r9120  
    7171    function create_object( $args ) {
    7272        if ( ! isset( $args['creator_id'] ) ) {
    73             $args['creator_id'] = get_current_user_id();
     73            if ( is_user_logged_in() ) {
     74                $args['creator_id'] = get_current_user_id();
     75
     76            // Create a user. This is based on from BP_UnitTestCase->create_user().
     77            } else {
     78                $last_activity      = date( 'Y-m-d H:i:s', strtotime( bp_core_current_time() ) - 60 * 60 * 24 * 365 );
     79                $user_factory       = new WP_UnitTest_Factory_For_User();
     80                $args['creator_id'] = $this->factory->user->create( array( 'role' => 'subscriber' ) );
     81
     82                bp_update_user_last_activity( $args['creator_id'] , $last_activity );
     83
     84                if ( bp_is_active( 'xprofile' ) ) {
     85                    $user = new WP_User( $args['creator_id']  );
     86                    xprofile_set_field_data( 1, $args['creator_id'] , $user->display_name );
     87                }
     88            }
    7489        }
    7590
     
    8095
    8196        groups_update_groupmeta( $group_id, 'total_member_count', 1 );
    82 
    8397        $last_activity = isset( $args['last_activity'] ) ? $args['last_activity'] : bp_core_current_time();
    8498        groups_update_groupmeta( $group_id, 'last_activity', $last_activity );
  • trunk/tests/phpunit/testcases/groups/class-bp-group-member-query.php

    r8958 r9120  
    119119
    120120    public function test_with_group_role_admin() {
    121         $g = $this->factory->group->create();
    122         $u1 = $this->create_user();
    123         $u2 = $this->create_user();
    124         $u3 = $this->create_user();
     121        $u1 = $this->create_user();
     122        $u2 = $this->create_user();
     123        $u3 = $this->create_user();
     124        $g  = $this->factory->group->create( array(
     125            'creator_id' => $u1
     126        ) );
    125127        $time = time();
    126128
     
    169171
    170172    public function test_with_group_role_member_admin() {
    171         $g = $this->factory->group->create();
    172         $u1 = $this->create_user();
    173         $u2 = $this->create_user();
    174         $u3 = $this->create_user();
     173        $u1 = $this->create_user();
     174        $u2 = $this->create_user();
     175        $u3 = $this->create_user();
     176        $g  = $this->factory->group->create( array(
     177            'creator_id' => $u1,
     178        ) );
    175179        $time = time();
    176180
     
    194198
    195199    public function test_with_group_role_mod_admin() {
    196         $g = $this->factory->group->create();
    197         $u1 = $this->create_user();
    198         $u2 = $this->create_user();
    199         $u3 = $this->create_user();
     200        $u1 = $this->create_user();
     201        $u2 = $this->create_user();
     202        $u3 = $this->create_user();
     203        $g  = $this->factory->group->create( array(
     204            'creator_id' => $u1,
     205        ) );
    200206        $time = time();
    201207
     
    219225
    220226    public function test_with_group_role_member_mod_admin() {
    221         $g = $this->factory->group->create();
    222         $u1 = $this->create_user();
    223         $u2 = $this->create_user();
    224         $u3 = $this->create_user();
     227        $u1 = $this->create_user();
     228        $u2 = $this->create_user();
     229        $u3 = $this->create_user();
     230        $g  = $this->factory->group->create( array(
     231            'creator_id' => $u1,
     232        ) );
    225233        $time = time();
    226234
     
    244252
    245253    public function test_with_group_role_member_mod_admin_banned() {
    246         $g = $this->factory->group->create();
    247254        $u1 = $this->create_user();
    248255        $u2 = $this->create_user();
    249256        $u3 = $this->create_user();
    250257        $u4 = $this->create_user();
     258        $g  = $this->factory->group->create( array(
     259            'creator_id' => $u1,
     260        ) );
    251261        $time = time();
    252262
     
    294304        $ids = wp_parse_id_list( array_keys( $query_members->results ) );
    295305        $this->assertEquals( array( $u1, ), $ids );
    296     }
    297 
    298     public function test_group_has_no_members() {
    299         $g = $this->factory->group->create();
    300         $u1 = $this->create_user();
    301 
    302         $query_members = new BP_Group_Member_Query( array(
    303             'group_id' => $g,
    304             'group_role' => array( 'member', 'mod', 'admin' ),
    305         ) );
    306 
    307         $ids = wp_parse_id_list( array_keys( $query_members->results ) );
    308         $this->assertEquals( array(), $ids );
    309306    }
    310307
  • trunk/tests/phpunit/testcases/groups/template.php

    r9047 r9120  
    132132     */
    133133    public function test_bp_group_has_members_vanilla() {
    134         $g = $this->factory->group->create();
    135134        $u1 = $this->create_user();
    136135        $u2 = $this->create_user();
     136        $g  = $this->factory->group->create( array(
     137            'creator_id' => $u1,
     138        ) );
    137139
    138140        $this->add_user_to_group( $u1, $g );
Note: See TracChangeset for help on using the changeset viewer.