mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00:00
Improve 'orderby' syntax for WP_User_Query.
This changeset ports a number of 'orderby' features from `WP_Query` and `WP_Comment_Query`: * Allow multiple 'orderby' values to be passed as a space-separated list. * Allow multiple 'orderby' values to be passed as a flat array. * Allow multi-dimensional 'orderby', with orderby fields as array keys and ASC/DESC as the corresponding values. See #31265. git-svn-id: https://develop.svn.wordpress.org/trunk@31663 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -230,6 +230,93 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
$this->assertEquals( array( $users[1], $users[0], $users[3] ), $q->get_results() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31265
|
||||
*/
|
||||
public function test_orderby_space_separated() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_User_Query( array(
|
||||
'orderby' => 'login nicename',
|
||||
'order' => 'ASC',
|
||||
) );
|
||||
|
||||
$this->assertContains( "ORDER BY user_login ASC, user_nicename ASC", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31265
|
||||
*/
|
||||
public function test_orderby_flat_array() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_User_Query( array(
|
||||
'orderby' => array( 'login', 'nicename' ),
|
||||
) );
|
||||
|
||||
$this->assertContains( "ORDER BY user_login ASC, user_nicename ASC", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31265
|
||||
*/
|
||||
public function test_orderby_array_contains_invalid_item() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_User_Query( array(
|
||||
'orderby' => array( 'login', 'foo', 'nicename' ),
|
||||
) );
|
||||
|
||||
$this->assertContains( "ORDER BY user_login ASC, user_nicename ASC", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31265
|
||||
*/
|
||||
public function test_orderby_array_contains_all_invalid_items() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_User_Query( array(
|
||||
'orderby' => array( 'foo', 'bar', 'baz' ),
|
||||
) );
|
||||
|
||||
$this->assertContains( "ORDER BY user_login", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31265
|
||||
*/
|
||||
public function test_orderby_array() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_User_Query( array(
|
||||
'orderby' => array(
|
||||
'login' => 'DESC',
|
||||
'nicename' => 'ASC',
|
||||
'email' => 'DESC',
|
||||
),
|
||||
) );
|
||||
|
||||
$this->assertContains( "ORDER BY user_login DESC, user_nicename ASC, user_email DESC", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 31265
|
||||
*/
|
||||
public function test_orderby_array_should_discard_invalid_columns() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_User_Query( array(
|
||||
'orderby' => array(
|
||||
'login' => 'DESC',
|
||||
'foo' => 'ASC',
|
||||
'email' => 'ASC',
|
||||
),
|
||||
) );
|
||||
|
||||
$this->assertContains( "ORDER BY user_login DESC, user_email ASC", $q->query_orderby );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21119
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user