[wp-trac] [WordPress Trac] #61337: Tests: Cached data in `WP_Theme_JSON_Resolver` causes cross pollution in unit tests

WordPress Trac noreply at wordpress.org
Fri May 31 14:45:38 UTC 2024


#61337: Tests: Cached data in `WP_Theme_JSON_Resolver` causes cross pollution in
unit tests
------------------------------+-----------------------
 Reporter:  joemcgill         |      Owner:  joemcgill
     Type:  defect (bug)      |     Status:  assigned
 Priority:  normal            |  Milestone:  6.6
Component:  Build/Test Tools  |    Version:
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------
 While working on #59595, @thekt12 and I discovered that while all of the
 tests in the `Tests_Theme_WpAddGlobalStylesForBlocks` class were passing
 when run together, there were a few that failed when run in isolation,
 specifically:

 - `test_blocks_inline_styles_get_rendered()`
 - `test_third_party_blocks_inline_styles_for_elements_get_rendered()`

 In both cases, the tests were relying on cached data that had been set up
 in previous tests by calling `$this->set_up_third_party_block();` to still
 be returned by the `WP_Theme_JSON_Resolver` class even though these tests
 don't call `$this->set_up_third_party_block()` themselves.

 To confirm, run the following to see all tests in the class pass:

 `npm run test:php -- --filter Tests_Theme_WpAddGlobalStylesForBlocks`

 And the following to see an example of a test that fails in isolation

 `npm run test:php -- --filter test_blocks_inline_styles_get_rendered`

 The reason this happens is that the theme gets reset between each test
 that extends the `WP_Theme_UnitTestCase` but the
 `wp_clean_theme_json_cache()` function was not being called to clean Theme
 JSON related caches (including the
 `WP_Theme_JSON_Resolver::clean_cached_data()` method).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61337>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list