Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/14/2014 02:01:18 PM (10 years ago)
Author:
boonebgorges
Message:

In automated tests, move user creation to a proper factory method.

BP user creation requires that a couple of extra pieces of data be set up
(last activity, display name, etc). So we previously had a wrapper in
BP_UnitTestCase called create_user() that performed the extra setup.
However, the wrapper made it impossible to use create_user() statically,
because the user_login and user_email iterator was not persistent from call to
call. (The create_user() syntax is also a break with the rest of our unit
tests, which is not ideal.)

This changeset introduces BP_UnitTest_Factory_For_User, which reproduces the
customizations of create_user(), but in a proper factory method. All
instances of create_user() throughout the test suite have also been replaced.

See #6009.

File:
1 edited

Legend:

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

    r9138 r9139  
    319319    }
    320320
    321     /**
    322      * When creating a new user, it's almost always necessary to have the
    323      * last_activity usermeta set right away, so that the user shows up in
    324      * directory queries. This is a shorthand wrapper for the user factory
    325      * create() method.
    326      *
    327      * Also set a display name
    328      */
    329     function create_user( $args = array() ) {
    330         $r = wp_parse_args( $args, array(
    331             'role' => 'subscriber',
    332             'last_activity' => date( 'Y-m-d H:i:s', strtotime( bp_core_current_time() ) - 60*60*24*365 ),
    333         ) );
    334 
    335         $last_activity = $r['last_activity'];
    336         unset( $r['last_activity'] );
    337 
    338         $user_id = $this->factory->user->create( $r );
    339 
    340         bp_update_user_last_activity( $user_id, $last_activity );
    341 
    342         if ( bp_is_active( 'xprofile' ) ) {
    343             $user = new WP_User( $user_id );
    344             xprofile_set_field_data( 1, $user_id, $user->display_name );
    345         }
    346 
    347         return $user_id;
    348     }
    349 
    350321    public static function add_user_to_group( $user_id, $group_id, $args = array() ) {
    351322        $r = wp_parse_args( $args, array(
Note: See TracChangeset for help on using the changeset viewer.