Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/27/2014 09:11:26 PM (11 years ago)
Author:
imath
Message:

When using BP_User_Query with meta_key and meta_value arguments, make sure no results are displayed if no user match the meta arguments.

Fixes #5904

File:
1 edited

Legend:

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

    r8958 r9051  
    368368    }
    369369
     370    /**
     371     * @group meta
     372     * @group BP5904
     373     */
     374    public function test_bp_user_query_with_user_meta_argument() {
     375        $u1 = $this->create_user();
     376        $u2 = $this->create_user();
     377
     378        bp_update_user_meta( $u2, 'foo', 'bar' );
     379
     380        $q = new BP_User_Query( array(
     381            'meta_key'        => 'foo',
     382            'meta_value'      => 'bar',
     383        ) );
     384
     385        $found_user_ids = array_values( wp_parse_id_list( wp_list_pluck( $q->results, 'ID' ) ) );
     386
     387        // Do a assertNotContains because there are weird issues with user #1 as created by WP
     388        $this->assertNotContains( $u1, $found_user_ids );
     389        $this->assertEquals( array( $u2 ), $found_user_ids );
     390    }
     391
     392    /**
     393     * @group meta
     394     * @group BP5904
     395     */
     396    public function test_bp_user_query_with_user_meta_argument_no_user() {
     397        $u1 = $this->create_user();
     398        $u2 = $this->create_user();
     399
     400        $q = new BP_User_Query( array(
     401            'meta_key'        => 'foo',
     402            'meta_value'      => 'bar',
     403        ) );
     404
     405        $found_user_ids = array_values( wp_parse_id_list( wp_list_pluck( $q->results, 'ID' ) ) );
     406
     407        $this->assertEmpty( $found_user_ids );
     408    }
     409
    370410}
Note: See TracChangeset for help on using the changeset viewer.