From f5fc714cf6693666992a44ea1e7768c104fe24ad Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 17 Sep 2020 11:28:05 +0000 Subject: [PATCH] Tests: Move the `data_wp_site_query_meta_query()` data provider next to the test it's used in. See #50767. git-svn-id: https://develop.svn.wordpress.org/trunk@48988 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/multisite/siteQuery.php | 65 ++++++++++----------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/tests/phpunit/tests/multisite/siteQuery.php b/tests/phpunit/tests/multisite/siteQuery.php index df579bb438..773a29164b 100644 --- a/tests/phpunit/tests/multisite/siteQuery.php +++ b/tests/phpunit/tests/multisite/siteQuery.php @@ -909,39 +909,6 @@ if ( is_multisite() ) : } } - - /** - * @ticket 45749 - * @ticket 47599 - */ - public function test_sites_pre_query_filter_should_bypass_database_query() { - global $wpdb; - - add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); - - $num_queries = $wpdb->num_queries; - - $q = new WP_Site_Query(); - $results = $q->query( array() ); - - remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); - - // Make sure no queries were executed. - $this->assertSame( $num_queries, $wpdb->num_queries ); - - // We manually inserted a non-existing site and overrode the results with it. - $this->assertSame( array( 555 ), $results ); - - // Make sure manually setting found_sites doesn't get overwritten. - $this->assertSame( 1, $q->found_sites ); - } - - public static function filter_sites_pre_query( $sites, $query ) { - $query->found_sites = 1; - - return array( 555 ); - } - public function data_wp_site_query_meta_query() { return array( array( @@ -1096,6 +1063,38 @@ if ( is_multisite() ) : ), ); } + + /** + * @ticket 45749 + * @ticket 47599 + */ + public function test_sites_pre_query_filter_should_bypass_database_query() { + global $wpdb; + + add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); + + $num_queries = $wpdb->num_queries; + + $q = new WP_Site_Query(); + $results = $q->query( array() ); + + remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); + + // Make sure no queries were executed. + $this->assertSame( $num_queries, $wpdb->num_queries ); + + // We manually inserted a non-existing site and overrode the results with it. + $this->assertSame( array( 555 ), $results ); + + // Make sure manually setting found_sites doesn't get overwritten. + $this->assertSame( 1, $q->found_sites ); + } + + public static function filter_sites_pre_query( $sites, $query ) { + $query->found_sites = 1; + + return array( 555 ); + } } endif;