From 38bcf065df9de0133674b1a7d40fba8e5cb4f709 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 17 Jul 2016 23:29:11 +0000 Subject: [PATCH] Multisite: Correct default values for `orderby` and `order` in `WP_Site_Query::__construct()`. Add a unit test. Props ramiy, SergeyBiryukov. See #35791. git-svn-id: https://develop.svn.wordpress.org/trunk@38085 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-site-query.php | 4 +-- tests/phpunit/tests/multisite/siteQuery.php | 27 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-site-query.php b/src/wp-includes/class-wp-site-query.php index 742b27b7b7..b8226a966b 100644 --- a/src/wp-includes/class-wp-site-query.php +++ b/src/wp-includes/class-wp-site-query.php @@ -155,8 +155,8 @@ class WP_Site_Query { 'number' => 100, 'offset' => '', 'no_found_rows' => true, - 'orderby' => 'ids', - 'order' => 'DESC', + 'orderby' => 'id', + 'order' => 'ASC', 'network_id' => 0, 'network__in' => '', 'network__not_in' => '', diff --git a/tests/phpunit/tests/multisite/siteQuery.php b/tests/phpunit/tests/multisite/siteQuery.php index 448023f97a..9c8070cfc2 100644 --- a/tests/phpunit/tests/multisite/siteQuery.php +++ b/tests/phpunit/tests/multisite/siteQuery.php @@ -163,6 +163,33 @@ class Tests_Multisite_Site_Query extends WP_UnitTestCase { $this->assertEqualSets( $expected, $found ); } + public function test_wp_site_query_by_network_id_with_order() { + $q = new WP_Site_Query(); + $found = $q->query( array( + 'fields' => 'ids', + 'network_id' => self::$network_ids['wordpress.org/'], + 'number' => 3, + 'order' => 'ASC', + ) ); + + $expected = array( + self::$site_ids['wordpress.org/'], + self::$site_ids['wordpress.org/foo/'], + self::$site_ids['wordpress.org/foo/bar/'], + ); + + $this->assertEquals( $expected, $found ); + + $found = $q->query( array( + 'fields' => 'ids', + 'network_id' => self::$network_ids['wordpress.org/'], + 'number' => 3, + 'order' => 'DESC', + ) ); + + $this->assertEquals( array_reverse( $expected ), $found ); + } + public function test_wp_site_query_by_network_id_with_existing_sites() { $q = new WP_Site_Query(); $found = $q->query( array(