Changeset 56656 for trunk/tests/phpunit/tests/query/cacheResults.php
- Timestamp:
- 09/21/2023 07:32:55 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/query/cacheResults.php
r55349 r56656 1081 1081 1082 1082 /** 1083 * @ticket 58599 1084 */ 1085 public function test_query_posts_fields_request() { 1086 global $wpdb; 1087 1088 $args = array( 1089 'update_post_meta_cache' => false, 1090 'update_post_term_cache' => false, 1091 'no_found_rows' => true, 1092 ); 1093 1094 add_filter( 'posts_fields_request', array( $this, 'filter_posts_fields_request' ) ); 1095 1096 $before = get_num_queries(); 1097 $query1 = new WP_Query(); 1098 $posts1 = $query1->query( $args ); 1099 $after = get_num_queries(); 1100 1101 foreach ( $posts1 as $_post ) { 1102 $this->assertNotSame( get_post( $_post->ID )->post_content, $_post->post_content ); 1103 } 1104 1105 $this->assertSame( 2, $after - $before, 'There should only be 2 queries run, one for request and one prime post objects.' ); 1106 1107 $this->assertStringContainsString( 1108 "SELECT $wpdb->posts.*", 1109 $wpdb->last_query, 1110 'Check that _prime_post_caches is called.' 1111 ); 1112 } 1113 1114 public function filter_posts_fields_request( $fields ) { 1115 global $wpdb; 1116 return "{$wpdb->posts}.ID"; 1117 } 1118 1119 /** 1120 * @ticket 58599 1121 * @dataProvider data_query_filter_posts_results 1122 */ 1123 public function test_query_filter_posts_results( $filter ) { 1124 global $wpdb; 1125 1126 $args = array( 1127 'update_post_meta_cache' => false, 1128 'update_post_term_cache' => false, 1129 'no_found_rows' => true, 1130 ); 1131 1132 add_filter( $filter, array( $this, 'filter_posts_results' ) ); 1133 1134 $before = get_num_queries(); 1135 $query1 = new WP_Query(); 1136 $posts1 = $query1->query( $args ); 1137 $after = get_num_queries(); 1138 1139 $this->assertCount( 1, $posts1 ); 1140 1141 $this->assertSame( 2, $after - $before, 'There should only be 2 queries run, one for request and one prime post objects.' ); 1142 1143 $this->assertStringContainsString( 1144 "SELECT $wpdb->posts.*", 1145 $wpdb->last_query, 1146 'Check that _prime_post_caches is called.' 1147 ); 1148 } 1149 1150 public function filter_posts_results() { 1151 return array( get_post( self::$posts[0] ) ); 1152 } 1153 1154 public function data_query_filter_posts_results() { 1155 return array( 1156 array( 'posts_results' ), 1157 array( 'the_posts' ), 1158 ); 1159 } 1160 1161 /** 1083 1162 * @ticket 22176 1084 1163 */
Note: See TracChangeset
for help on using the changeset viewer.