Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/11/2015 04:54:03 PM (9 years ago)
Author:
r-a-y
Message:

BP User Query: Remove invalid IDs from $user_ids property after query is run.

If the user_ids parameter is passed to BP_User_Query with invalid user
IDs, after the user query is run, the user_ids property still references
these invalid user IDs. This can lead to devs to assume that the user ID
exists when it does not.

This commit removes these invalid user IDs and includes a unit test.

See #6577.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/class-bp-user-query.php

    r9976 r10043  
    6767    }
    6868
     69    /**
     70     * @group user_ids
     71     */
     72    public function test_bp_user_query_user_ids_with_invalid_user_id() {
     73        $now = time();
     74        $u1 = $this->factory->user->create();
     75        $u2 = $this->factory->user->create();
     76
     77        // invalid user ID
     78        $u3 = $u2 + 1;
     79
     80        $old_user = get_current_user_id();
     81        $this->set_current_user( $u1 );
     82
     83        // pass 'user_ids' to user query to trigger this bug
     84        $q = new BP_User_Query( array(
     85            'user_ids' => array( $u2, $u3 )
     86        ) );
     87
     88        // $q->user_ids property should now not contain invalid user IDs
     89        $this->assertNotContains( $u3, $q->user_ids );
     90
     91        // clean up
     92        $this->set_current_user( $old_user );
     93    }
     94
    6995    public function test_bp_user_query_sort_by_popular() {
    7096        $u1 = $this->factory->user->create();
Note: See TracChangeset for help on using the changeset viewer.