Skip to:
Content

BuddyPress.org

Changeset 11353


Ignore:
Timestamp:
12/29/2016 02:27:13 AM (8 years ago)
Author:
boonebgorges
Message:

Add tests for legacy friends query functions.

Props tw2113.
See #6889.

File:
1 edited

Legend:

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

    r11125 r11353  
    333333        $this->assertEquals( $first_query_count + 1, $wpdb->num_queries );
    334334    }
     335
     336    public function test_friends_get_recently_active() {
     337        $this->setExpectedDeprecated( 'BP_Core_User::get_users' );
     338        $u1 = $this->factory->user->create();
     339        $u2 = $this->factory->user->create();
     340        $u3 = $this->factory->user->create();
     341        $u4 = $this->factory->user->create();
     342
     343        // request friendship
     344        friends_add_friend( $u1, $u2, true );
     345        friends_add_friend( $u1, $u3, true );
     346        friends_add_friend( $u1, $u4, true );
     347
     348        bp_update_user_last_activity( $u2, date( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) ) );
     349        bp_update_user_last_activity( $u3, date( 'Y-m-d H:i:s', time() - ( 5 * DAY_IN_SECONDS ) ) );
     350        bp_update_user_last_activity( $u4, date( 'Y-m-d H:i:s', time() - ( 3 * DAY_IN_SECONDS ) ) );
     351
     352        $recent = friends_get_recently_active( $u1 );
     353
     354        $this->assertEquals( $recent['users'][0]->id, $u2 );
     355        $this->assertEquals( $recent['users'][1]->id, $u4 );
     356        $this->assertEquals( $recent['users'][2]->id, $u3 );
     357    }
     358
     359    public function test_friends_get_alphabetically() {
     360        $this->setExpectedDeprecated( 'BP_Core_User::get_users' );
     361        $u1 = $this->factory->user->create();
     362        $u2 = $this->factory->user->create();
     363        $u3 = $this->factory->user->create();
     364
     365        // request friendship
     366        friends_add_friend( $u1, $u2, true );
     367        friends_add_friend( $u1, $u3, true );
     368
     369        $field_id = bp_xprofile_fullname_field_id();
     370        xprofile_set_field_data( $field_id, $u2, 'Dave Lister' );
     371        xprofile_set_field_data( $field_id, $u3, 'Arnold Rimmer' );
     372
     373        $alpha = friends_get_alphabetically( $u1 );
     374
     375        $this->assertEquals( $alpha['users'][0]->id, $u3 );
     376        $this->assertEquals( $alpha['users'][1]->id, $u2 );
     377    }
     378
     379    public function test_friends_get_newest() {
     380        $this->setExpectedDeprecated( 'BP_Core_User::get_users' );
     381        $u1 = $this->factory->user->create();
     382        $u2 = $this->factory->user->create();
     383        $u3 = $this->factory->user->create();
     384        $u4 = $this->factory->user->create();
     385
     386        // request friendship
     387        friends_add_friend( $u1, $u2, true );
     388        friends_add_friend( $u1, $u3, true );
     389        friends_add_friend( $u1, $u4, true );
     390
     391        bp_update_user_last_activity( $u2, date( 'Y-m-d H:i:s', time() - ( 2 * DAY_IN_SECONDS ) ) );
     392        bp_update_user_last_activity( $u3, date( 'Y-m-d H:i:s', time() - ( 5 * DAY_IN_SECONDS ) ) );
     393        bp_update_user_last_activity( $u4, date( 'Y-m-d H:i:s', time() - ( 3 * DAY_IN_SECONDS ) ) );
     394
     395        $newest = friends_get_newest( $u1 );
     396
     397        $this->assertEquals( $newest['users'][0]->id, $u4 );
     398        $this->assertEquals( $newest['users'][1]->id, $u3 );
     399        $this->assertEquals( $newest['users'][2]->id, $u2 );
     400    }
    335401}
Note: See TracChangeset for help on using the changeset viewer.