Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/03/2014 06:14:06 PM (9 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.

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.