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/functions.php

    r8958 r9139  
    1313     */
    1414    public function test_requests_on_accept() {
    15         $u1 = $this->create_user();
    16         $u2 = $this->create_user();
    17         $u3 = $this->create_user();
     15        $u1 = $this->factory->user->create();
     16        $u2 = $this->factory->user->create();
     17        $u3 = $this->factory->user->create();
    1818
    1919        // request friendship
     
    4242     */
    4343    public function test_requests_on_request() {
    44         $u1 = $this->create_user();
    45         $u2 = $this->create_user();
    46         $u3 = $this->create_user();
     44        $u1 = $this->factory->user->create();
     45        $u2 = $this->factory->user->create();
     46        $u3 = $this->factory->user->create();
    4747
    4848        // request friendship
     
    6767     */
    6868    public function test_requests_on_withdraw() {
    69         $u1 = $this->create_user();
    70         $u2 = $this->create_user();
     69        $u1 = $this->factory->user->create();
     70        $u2 = $this->factory->user->create();
    7171
    7272        // request friendship
     
    9595     */
    9696    public function test_requests_on_reject() {
    97         $u1 = $this->create_user();
    98         $u2 = $this->create_user();
     97        $u1 = $this->factory->user->create();
     98        $u2 = $this->factory->user->create();
    9999
    100100        // request friendship
     
    121121     */
    122122    public function test_friends_add_friend_fail_on_self() {
    123         $u1 = $this->create_user();
     123        $u1 = $this->factory->user->create();
    124124        $this->assertFalse( friends_add_friend( $u1, $u1 ) );
    125125    }
     
    129129     */
    130130    public function test_friends_add_friend_already_friends() {
    131         $u1 = $this->create_user();
    132         $u2 = $this->create_user();
     131        $u1 = $this->factory->user->create();
     132        $u2 = $this->factory->user->create();
    133133
    134134        friends_add_friend( $u1, $u2, true );
     
    142142    public function test_friends_check_friendship_status_in_members_loop() {
    143143        $now = time();
    144         $u1 = $this->create_user( array(
     144        $u1 = $this->factory->user->create( array(
    145145            'last_activity' => date( 'Y-m-d H:i:s', $now ),
    146146        ) );
    147         $u2 = $this->create_user( array(
     147        $u2 = $this->factory->user->create( array(
    148148            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    149149        ) );
    150         $u3 = $this->create_user( array(
     150        $u3 = $this->factory->user->create( array(
    151151            'last_activity' => date( 'Y-m-d H:i:s', $now - 200 ),
    152152        ) );
    153         $u4 = $this->create_user( array(
     153        $u4 = $this->factory->user->create( array(
    154154            'last_activity' => date( 'Y-m-d H:i:s', $now - 300 ),
    155155        ) );
    156         $u5 = $this->create_user( array(
     156        $u5 = $this->factory->user->create( array(
    157157            'last_activity' => date( 'Y-m-d H:i:s', $now - 400 ),
    158158        ) );
     
    190190    public function test_friends_check_friendship_status_not_in_members_loop() {
    191191        $now = time();
    192         $u1 = $this->create_user( array(
     192        $u1 = $this->factory->user->create( array(
    193193            'last_activity' => date( 'Y-m-d H:i:s', $now ),
    194194        ) );
    195         $u2 = $this->create_user( array(
     195        $u2 = $this->factory->user->create( array(
    196196            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
    197197        ) );
    198         $u3 = $this->create_user( array(
     198        $u3 = $this->factory->user->create( array(
    199199            'last_activity' => date( 'Y-m-d H:i:s', $now - 200 ),
    200200        ) );
    201         $u4 = $this->create_user( array(
     201        $u4 = $this->factory->user->create( array(
    202202            'last_activity' => date( 'Y-m-d H:i:s', $now - 300 ),
    203203        ) );
    204         $u5 = $this->create_user( array(
     204        $u5 = $this->factory->user->create( array(
    205205            'last_activity' => date( 'Y-m-d H:i:s', $now - 400 ),
    206206        ) );
Note: See TracChangeset for help on using the changeset viewer.