From 3262ff0cc82a2e442501d385b09d5501d4ce8f81 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 7 Mar 2015 15:44:28 +0000 Subject: [PATCH] Tests for some existing 'orderby' functionality in `WP_*_Query` classes. * In `WP_Query` and `WP_Comment_Query`, ensure that 'orderby' can parse multiple values for 'orderby' when passed as a space-separated string. * In `WP_User_Query`, ensure that "shorthand" orderbys (like 'login' and 'name') are converted to their full versions (like 'user_login' and 'display_name'). See #31265. git-svn-id: https://develop.svn.wordpress.org/trunk@31662 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/comment/query.php | 11 +++++++++++ tests/phpunit/tests/query.php | 11 +++++++++++ tests/phpunit/tests/user/query.php | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 7003f2ab0b..27a23870f8 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -1108,6 +1108,17 @@ class Tests_Comment_Query extends WP_UnitTestCase { $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); } + public function test_orderby_space_separated() { + global $wpdb; + + $q = new WP_Comment_Query(); + $q->query( array( + 'orderby' => 'comment_agent comment_approved', + ) ); + + $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); + } + public function test_orderby_comma_separated() { global $wpdb; diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index c1aa6df309..f12dccc41d 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -122,4 +122,15 @@ class Tests_Query extends WP_UnitTestCase { public function filter_parse_query_to_remove_tax( $q ) { unset( $q->query_vars['wptests_tax'] ); } + + public function test_orderby_space_separated() { + global $wpdb; + + $q = new WP_Query( array( + 'orderby' => 'title date', + 'order' => 'DESC', + ) ); + + $this->assertContains( "ORDER BY $wpdb->posts.post_title DESC, $wpdb->posts.post_date DESC", $q->request ); + } } diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index 37b8d6759a..c2adee1e84 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -113,6 +113,27 @@ class Tests_User_Query extends WP_UnitTestCase { } } + /** + * @dataProvider orderby_should_convert_non_prefixed_keys_data + */ + public function test_orderby_should_convert_non_prefixed_keys( $short_key, $full_key ) { + $q = new WP_User_Query( array( + 'orderby' => $short_key, + ) ); + + $this->assertContains( "ORDER BY $full_key", $q->query_orderby ); + } + + public function orderby_should_convert_non_prefixed_keys_data() { + return array( + array( 'nicename', 'user_nicename' ), + array( 'email', 'user_email' ), + array( 'url', 'user_url' ), + array( 'registered', 'user_registered' ), + array( 'name', 'display_name' ), + ); + } + public function test_orderby_meta_value() { $users = $this->factory->user->create_many( 3, array( 'role' => 'author'