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
This commit is contained in:
Sergey Biryukov 2020-09-17 11:28:05 +00:00
parent 64a0a9f108
commit f5fc714cf6

View File

@ -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() { public function data_wp_site_query_meta_query() {
return array( return array(
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; endif;