Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/23/2014 05:56:57 PM (12 years ago)
Author:
djpaul
Message:

Core: add new search_wildcard parameter to BP_User_Query.

This new parameter controls where BuddyPress places MySQL wildcard characters around the search term (when it's set).
Prior to this change, BuddyPress added a wildcard character to both ends of the search term, but for some use cases, a more restrictive search pattern is required; you can specify "left", "right", or "both" (the default) to pick where the wildcard is added.

Fixes #5769

File:
1 edited

Legend:

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

    r8087 r8675  
    220220                $this->assertEquals( $user_id, $found_user_id );
    221221        }
     222
     223        public function test_bp_user_query_search_wildcards() {
     224                $u1 = $this->create_user( array(
     225                        'user_login' => 'xfoo',
     226                ) );
     227                xprofile_set_field_data( 1, $u1, "Bar" );
     228                $q1 = new BP_User_Query( array( 'search_terms' => 'foo', 'search_wildcard' => 'left' ) );
     229
     230                $u2 = $this->create_user( array(
     231                        'user_login' => 'foox',
     232                ) );
     233                xprofile_set_field_data( 1, $u2, "Bar" );
     234                $q2 = new BP_User_Query( array( 'search_terms' => 'foo', 'search_wildcard' => 'right' ) );
     235
     236                $u3 = $this->create_user( array(
     237                        'user_login' => 'xfoox',
     238                ) );
     239                xprofile_set_field_data( 1, $u3, "Bar" );
     240                $q3 = new BP_User_Query( array( 'search_terms' => 'foo', 'search_wildcard' => 'both' ) );
     241
     242                $this->assertNotEmpty( $q1->results );
     243                $q1 = array_pop( $q1->results );
     244                $this->assertEquals( $u1, $q1->ID );
     245
     246                $this->assertNotEmpty( $q2->results );
     247                $q2 = array_pop( $q2->results );
     248                $this->assertEquals( $u2, $q2->ID );
     249
     250                $this->assertNotEmpty( $q3->results );
     251                foreach ( $q3->results as $user ) {
     252                        $this->assertTrue( in_array( $user->ID, array( $u1, $u2, $u3 ) ) );
     253                }
     254        }
     255
    222256        /**
    223257         * @group exclude
Note: See TracChangeset for help on using the changeset viewer.