Changeset 48988
- Timestamp:
- 09/17/2020 11:28:05 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/siteQuery.php
r48987 r48988 908 908 $this->assertSameSets( $expected, $found ); 909 909 } 910 }911 912 913 /**914 * @ticket 45749915 * @ticket 47599916 */917 public function test_sites_pre_query_filter_should_bypass_database_query() {918 global $wpdb;919 920 add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );921 922 $num_queries = $wpdb->num_queries;923 924 $q = new WP_Site_Query();925 $results = $q->query( array() );926 927 remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );928 929 // Make sure no queries were executed.930 $this->assertSame( $num_queries, $wpdb->num_queries );931 932 // We manually inserted a non-existing site and overrode the results with it.933 $this->assertSame( array( 555 ), $results );934 935 // Make sure manually setting found_sites doesn't get overwritten.936 $this->assertSame( 1, $q->found_sites );937 }938 939 public static function filter_sites_pre_query( $sites, $query ) {940 $query->found_sites = 1;941 942 return array( 555 );943 910 } 944 911 … … 1097 1064 ); 1098 1065 } 1066 1067 /** 1068 * @ticket 45749 1069 * @ticket 47599 1070 */ 1071 public function test_sites_pre_query_filter_should_bypass_database_query() { 1072 global $wpdb; 1073 1074 add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); 1075 1076 $num_queries = $wpdb->num_queries; 1077 1078 $q = new WP_Site_Query(); 1079 $results = $q->query( array() ); 1080 1081 remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); 1082 1083 // Make sure no queries were executed. 1084 $this->assertSame( $num_queries, $wpdb->num_queries ); 1085 1086 // We manually inserted a non-existing site and overrode the results with it. 1087 $this->assertSame( array( 555 ), $results ); 1088 1089 // Make sure manually setting found_sites doesn't get overwritten. 1090 $this->assertSame( 1, $q->found_sites ); 1091 } 1092 1093 public static function filter_sites_pre_query( $sites, $query ) { 1094 $query->found_sites = 1; 1095 1096 return array( 555 ); 1097 } 1099 1098 } 1100 1099
Note: See TracChangeset
for help on using the changeset viewer.