Make WordPress Core

Changeset 32980


Ignore:
Timestamp:
06/28/2015 12:35:42 AM (11 years ago)
Author:
wonderboymusic
Message:

When searching for users using the search arg in get_users()/WP_User_Query, also search the user's email, url, and display name.

Adds unit tests.

Props mordauk, wonderboymusic.
Fixes #27304.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r32904 r32980  
    798798                                        $search_columns = array('user_url');
    799799                                else
    800                                         $search_columns = array('user_login', 'user_nicename');
     800                                        $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name');
    801801                        }
    802802
  • trunk/tests/phpunit/tests/user.php

    r32904 r32980  
    66 */
    77class Tests_User extends WP_UnitTestCase {
     8
     9        protected $user_data;
     10
     11        function setUp() {
     12                parent::setUp();
     13
     14                $this->user_data = array(
     15                        'user_login' => 'user1',
     16                        'user_nicename' => 'userone',
     17                        'user_pass'  => 'password',
     18                        'first_name' => 'John',
     19                        'last_name'  => 'Doe',
     20                        'display_name' => 'John Doe',
     21                        'user_email' => 'blackburn@battlefield3.com',
     22                        'user_url' => 'http://tacos.com'
     23                );
     24        }
    825
    926        function test_get_users_of_blog() {
    … …  
    637654                $this->assertEquals( $id2, email_exists( 'miller@battlefield3.com' ) );
    638655
    639                 if( ! is_wp_error( $id2 ) ){   
     656                if( ! is_wp_error( $id2 ) ){
    640657                        $return = wp_update_user( array(
    641658                                'ID'         => $id2,
    … …  
    650667                        if ( ! defined( 'WP_IMPORTING' ) ) {
    651668                                $this->assertWPError( $return );
    652                         }                       
     669                        }
    653670                }
    654671        }
    … …  
    700717                $this->assertEmpty( $user->user_activation_key );
    701718        }
     719
     720        public function test_search_users_login() {
     721                $id = $this->factory->user->create( $this->user_data );
     722
     723                $users = get_users( array( 'search' => 'user1', 'fields' => 'ID' ) );
     724
     725                $this->assertTrue( in_array( $id, $users ) );
     726        }
     727
     728        public function test_search_users_url() {
     729                $id = $this->factory->user->create( $this->user_data );
     730
     731                $users = get_users( array( 'search' => '*tacos*', 'fields' => 'ID' ) );
     732
     733                $this->assertTrue( in_array( $id, $users ) );
     734        }
     735
     736        public function test_search_users_email() {
     737                $id = $this->factory->user->create( $this->user_data );
     738
     739                $users = get_users( array( 'search' => '*battle*', 'fields' => 'ID' ) );
     740
     741                $this->assertTrue( in_array( $id, $users ) );
     742        }
     743
     744        public function test_search_users_nicename() {
     745                $id = $this->factory->user->create( $this->user_data );
     746
     747                $users = get_users( array( 'search' => '*one*', 'fields' => 'ID' ) );
     748
     749                $this->assertTrue( in_array( $id, $users ) );
     750        }
     751
     752        public function test_search_users_display_name() {
     753                $id = $this->factory->user->create( $this->user_data );
     754
     755                $users = get_users( array( 'search' => '*Doe*', 'fields' => 'ID' ) );
     756
     757                $this->assertTrue( in_array( $id, $users ) );
     758        }
    702759}
Note: See TracChangeset for help on using the changeset viewer.