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/testcases/friends/class-bp-friends-friendship.php

    r8958 r9139  
    2020
    2121    public function test_search_friends() {
    22         $u1 = $this->create_user();
    23         $u2 = $this->create_user();
    24         $u3 = $this->create_user();
     22        $u1 = $this->factory->user->create();
     23        $u2 = $this->factory->user->create();
     24        $u3 = $this->factory->user->create();
    2525
    2626        xprofile_set_field_data( 1, $u2, 'Cool Dude' );
     
    3535
    3636    public function test_get_bulk_last_active() {
    37         $u1 = $this->create_user( array(
     37        $u1 = $this->factory->user->create( array(
    3838            'last_activity' => gmdate( 'Y-m-d H:i:s' ),
    3939        ) );
    40         $u2 = $this->create_user( array(
     40        $u2 = $this->factory->user->create( array(
    4141            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 1000 ),
    4242        ) );
    43         $u3 = $this->create_user( array(
     43        $u3 = $this->factory->user->create( array(
    4444            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 50 ),
    4545        ) );
     
    5151
    5252    public function test_search_users() {
    53         $u1 = $this->create_user();
    54         $u2 = $this->create_user();
    55         $u3 = $this->create_user();
     53        $u1 = $this->factory->user->create();
     54        $u2 = $this->factory->user->create();
     55        $u3 = $this->factory->user->create();
    5656
    5757        xprofile_set_field_data( 1, $u1, 'Freedom Isn\'t Free' );
     
    6565
    6666    public function test_search_users_count() {
    67         $u1 = $this->create_user();
    68         $u2 = $this->create_user();
    69         $u3 = $this->create_user();
     67        $u1 = $this->factory->user->create();
     68        $u2 = $this->factory->user->create();
     69        $u3 = $this->factory->user->create();
    7070
    7171        xprofile_set_field_data( 1, $u1, 'Freedom Isn\'t Free' );
     
    8282     */
    8383    public function test_check_is_friend_not_friends() {
    84         $u1 = $this->create_user();
    85         $u2 = $this->create_user();
     84        $u1 = $this->factory->user->create();
     85        $u2 = $this->factory->user->create();
    8686        $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
    8787    }
     
    9191     */
    9292    public function test_check_is_friend_pending() {
    93         $u1 = $this->create_user();
    94         $u2 = $this->create_user();
     93        $u1 = $this->factory->user->create();
     94        $u2 = $this->factory->user->create();
    9595        friends_add_friend( $u1, $u2, false );
    9696        $this->assertEquals( 'pending', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
     
    101101     */
    102102    public function test_check_is_friend_awaiting_response() {
    103         $u1 = $this->create_user();
    104         $u2 = $this->create_user();
     103        $u1 = $this->factory->user->create();
     104        $u2 = $this->factory->user->create();
    105105        friends_add_friend( $u1, $u2, false );
    106106        $this->assertEquals( 'awaiting_response', BP_Friends_Friendship::check_is_friend( $u2, $u1 ) );
     
    111111     */
    112112    public function test_check_is_friend_is_friend() {
    113         $u1 = $this->create_user();
    114         $u2 = $this->create_user();
     113        $u1 = $this->factory->user->create();
     114        $u2 = $this->factory->user->create();
    115115        friends_add_friend( $u1, $u2, true );
    116116        $this->assertEquals( 'is_friend', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
Note: See TracChangeset for help on using the changeset viewer.