Changeset 52275 for trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
- Timestamp:
- 11/30/2021 12:22:30 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
r52232 r52275 25 25 add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); 26 26 add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); 27 $this->queries = array(); 27 28 // Clear caches. 28 29 wp_clean_themes_cache(); … … 43 44 public function filter_set_locale_to_polish() { 44 45 return 'pl_PL'; 46 } 47 48 function filter_db_query( $query ) { 49 if ( preg_match( '#post_type = \'wp_global_styles\'#', $query ) ) { 50 $this->queries[] = $query; 51 } 52 return $query; 45 53 } 46 54 … … 313 321 ); 314 322 } 323 324 function test_get_user_data_from_custom_post_type_does_not_use_uncached_queries() { 325 add_filter( 'query', array( $this, 'filter_db_query' ) ); 326 $query_count = count( $this->queries ); 327 for ( $i = 0; $i < 3; $i++ ) { 328 WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme() ); 329 WP_Theme_JSON_Resolver::clean_cached_data(); 330 } 331 $query_count = count( $this->queries ) - $query_count; 332 $this->assertEquals( 1, $query_count, 'Only one SQL query should be peformed for multiple invocations of WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type()' ); 333 334 $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme() ); 335 $this->assertEmpty( $user_cpt ); 336 337 $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme(), true ); 338 $this->assertNotEmpty( $user_cpt ); 339 340 $query_count = count( $this->queries ); 341 for ( $i = 0; $i < 3; $i++ ) { 342 WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme() ); 343 WP_Theme_JSON_Resolver::clean_cached_data(); 344 } 345 $query_count = count( $this->queries ) - $query_count; 346 $this->assertEquals( 0, $query_count, 'Unexpected SQL queries detected for the wp_global_style post type' ); 347 remove_filter( 'query', array( $this, 'filter_db_query' ) ); 348 } 315 349 }
Note: See TracChangeset
for help on using the changeset viewer.