Skip to:
Content

BuddyPress.org

Changeset 11948


Ignore:
Timestamp:
04/04/2018 10:23:16 AM (7 years ago)
Author:
djpaul
Message:

Tests, Friends: add test for friendship cache incrementor.

See #7436

Props r-a-y

File:
1 edited

Legend:

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

    r11865 r11948  
    281281
    282282    /**
     283     * @group friends_remove_friend
     284     */
     285    public function test_friends_check_is_friend_after_remove() {
     286        $now = time();
     287        $old_user = get_current_user_id();
     288        $u1 = $this->factory->user->create( array(
     289            'last_activity' => date( 'Y-m-d H:i:s', $now ),
     290        ) );
     291        $u2 = $this->factory->user->create( array(
     292            'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ),
     293        ) );
     294
     295        /*
     296         * Pretend user 1 is on the Members Directory page.
     297         *
     298         * Also primes the friendship cache in the process.
     299         * @see bp_friends_filter_user_query_populate_extras()
     300         */
     301        $this->set_current_user( $u1 );
     302        $this->go_to( bp_get_members_directory_permalink() );
     303        ob_start();
     304        bp_get_template_part( 'members/members-loop' );
     305        ob_end_clean();
     306
     307        // User 1 initiates friendship.
     308        friends_add_friend( $u1, $u2 );
     309
     310        /*
     311         * Pretend user 2 is logged in and accepts friendship.
     312         *
     313         * User 2 needs to be logged in for friends_accept_friendship() to work
     314         * properly.
     315         */
     316        $this->set_current_user( $u2 );
     317        friends_accept_friendship( friends_get_friendship_id( $u1, $u2 ) );
     318
     319        // Afterwards, user 1 decides to cancel friendship.
     320        $this->set_current_user( $u1 );
     321        friends_remove_friend( $u1, $u2 );
     322
     323        // Assert that users are no longer friends.
     324        $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) );
     325
     326        $this->set_current_user( $old_user );
     327    }
     328
     329    /**
    283330     * @group friendship_caching
    284331     */
Note: See TracChangeset for help on using the changeset viewer.