Ejemplo n.º 1
0
 /**
  * @group friends_get_friendship_request_user_ids
  * @group friends_add_friend
  * @group friends_reject_friendship
  */
 public function test_requests_on_reject()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     // request friendship
     friends_add_friend($u2, $u1);
     // get request count for user 1 and assert
     $requests = friends_get_friendship_request_user_ids($u1);
     $this->assertEquals(array($u2), $requests);
     // user 1 rejects friendship
     $old_user = get_current_user_id();
     $this->set_current_user($u1);
     friends_reject_friendship(friends_get_friendship_id($u2, $u1));
     // refetch request count for user 1 and assert
     $requests = friends_get_friendship_request_user_ids($u1);
     $this->assertEquals(array(), $requests);
     $this->set_current_user($old_user);
 }
Ejemplo n.º 2
0
/**
 * Return the URL for rejecting the current friendship request in the loop.
 *
 * @return string reject-friendship URL.
 */
function bp_get_friend_reject_request_link()
{
    global $members_template;
    if (!($friendship_id = wp_cache_get('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id()))) {
        $friendship_id = friends_get_friendship_id($members_template->member->id, bp_loggedin_user_id());
        wp_cache_set('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp');
    }
    /**
     * Filters the URL for rejecting the current friendship request in the loop.
     *
     * @since 1.0.0
     *
     * @param string $value Reject-friendship URL.
     */
    return apply_filters('bp_get_friend_reject_request_link', wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship'));
}
Ejemplo n.º 3
0
 /**
  * @group friends_delete_activity
  */
 public function test_delete_friendship_activity_on_user_delete()
 {
     $old_user = get_current_user_id();
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     friends_add_friend($u2, $u1);
     $friendship_id = friends_get_friendship_id($u2, $u1);
     // Set current user to u1 to accept the friendship
     $this->set_current_user($u1);
     friends_accept_friendship($friendship_id);
     // Reset the current user
     $this->set_current_user($old_user);
     // Delete $u1.
     wp_delete_user($u1);
     // 'friendship_created' activity item should not exist.
     $friendship_activity = bp_activity_get(array('component' => buddypress()->friends->id, 'filter' => array('action' => array('friendship_created'), 'primary_id' => $friendship_id)));
     $this->assertEmpty($friendship_activity['activities']);
 }
function bp_get_friend_reject_request_link()
{
    global $members_template;
    if (!($friendship_id = wp_cache_get('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id()))) {
        $friendship_id = friends_get_friendship_id($members_template->member->id, bp_loggedin_user_id());
        wp_cache_set('friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp');
    }
    return apply_filters('bp_get_friend_reject_request_link', wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship'));
}
 /**
  * @group friendship_caching
  */
 public function test_new_bp_friends_friendship_object_should_hit_friendship_object_cache()
 {
     global $wpdb;
     $now = time();
     $u1 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now)));
     $u2 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 100)));
     friends_add_friend($u1, $u2, true);
     $fid = friends_get_friendship_id($u1, $u2);
     $friendship_obj = new BP_Friends_Friendship($fid, false, false);
     $first_query_count = $wpdb->num_queries;
     // Create it again.
     $friendship_obj = new BP_Friends_Friendship($fid, false, false);
     $this->assertEquals($first_query_count, $wpdb->num_queries);
 }
Ejemplo n.º 6
0
function bp_get_friend_reject_request_link()
{
    global $members_template, $bp;
    if (!($friendship_id = nxt_cache_get('friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id))) {
        $friendship_id = friends_get_friendship_id($members_template->member->id, $bp->loggedin_user->id);
        nxt_cache_set('friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp');
    }
    return apply_filters('bp_get_friend_reject_request_link', nxt_nonce_url($bp->loggedin_user->domain . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship'));
}
Ejemplo n.º 7
0
 /**
  * @group bp_cleanup_friendship_activities
  */
 public function test_bp_cleanup_friendship_activities()
 {
     $old_user = get_current_user_id();
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $users = array($u1, $u2);
     friends_add_friend($u2, $u1);
     $friendship_id = friends_get_friendship_id($u2, $u1);
     // Set current user to u1 to accepte the friendship and generate a public activity
     $this->set_current_user($u1);
     friends_accept_friendship($friendship_id);
     // Reset the current user
     $this->set_current_user($old_user);
     $users[] = $this->factory->user->create();
     $users[] = $this->factory->user->create();
     foreach ($users as $u) {
         bp_activity_add(array('user_id' => $u, 'item_id' => $friendship_id, 'type' => 'friendship_created', 'component' => buddypress()->friends->id, 'hide_sitewide' => true));
     }
     $hidden = bp_activity_get(array('component' => buddypress()->friends->id, 'filter' => array('action' => array('friendship_created')), 'show_hidden' => true));
     bp_cleanup_friendship_activities();
     $check = bp_activity_get(array('component' => buddypress()->friends->id, 'item_id' => $friendship_id, 'filter' => array('action' => array('friendship_created')), 'show_hidden' => true));
     $this->assertTrue(count($check['activities']) == 1);
 }