Skip to:
Content

BuddyPress.org

Changeset 11125


Ignore:
Timestamp:
09/20/2016 09:58:13 PM (5 years ago)
Author:
dcavins
Message:

Friends tests: Set date_created to ensure reliable ordering.

Some of the tests for friendship functionality use assertEquals(),
which requires that the elements of arrays be in the same order and
each value be equal. In some cases, the order of the elements returned
by functions like friends_get_friendship_request_user_ids() was
unreliable, probably because phpunit was working quickly enough that
the date_created was indeterminate. This change set manually sets the
earlier friendship back in time so that the return values can be
checked reliably.

See #6978.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/friends/functions.php

    r11124 r11125  
    2828        friends_add_friend( $u3, $u1 );
    2929
     30        // Set the time of the earlier friendship for reliable ordering of the results.
     31        $fid = friends_get_friendship_id( $u2, $u1 );
     32        $friendship = new BP_Friends_Friendship( $fid, false, false );
     33        $friendship->date_created = date( 'Y-m-d H:i:s', time() - 60 );
     34        $friendship->save();
     35
    3036        // get request count for user 1 and assert
    3137        $requests = friends_get_friendship_request_user_ids( $u1 );
    32         $this->assertEquals( array( $u2, $u3 ), $requests );
     38        $this->assertEquals( array( $u3, $u2 ), $requests );
    3339
    3440        // accept friendship
     
    5561        // request friendship
    5662        friends_add_friend( $u2, $u1 );
     63        // Set the time of the earlier friendship for reliable ordering of the results.
     64        $fid = friends_get_friendship_id( $u2, $u1 );
     65        $friendship = new BP_Friends_Friendship( $fid, false, false );
     66        $friendship->date_created = date( 'Y-m-d H:i:s', time() - 60 );
     67        $friendship->save();
    5768
    5869        // get request count for user 1 and assert
     
    6576        // refetch request count for user 1 and assert
    6677        $requests = friends_get_friendship_request_user_ids( $u1 );
    67         $this->assertEquals( array( $u2, $u3 ), $requests );
     78        $this->assertEquals( array( $u3, $u2 ), $requests );
    6879    }
    6980
Note: See TracChangeset for help on using the changeset viewer.