#61337 closed defect (bug) (fixed)
Tests: Cached data in `WP_Theme_JSON_Resolver` causes cross pollution in unit tests
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
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).
Change History (5)
This ticket was mentioned in PR #6696 on WordPress/wordpress-develop by @joemcgill.
9 months ago
#1
- Keywords has-patch has-unit-tests added
#2
@
9 months ago
@isabel_brison could you confirm that I'm not missing something with this change, since you've recently updated these unit tests?
This clears the theme json related caches in the
WP_Theme_UnitTestCase:::tear_down()
method to avoid cross pollution between tests when a theme is changed during a test run and fixes a few tests that were only passing by relying on this cross pollution.Trac ticket: https://core.trac.wordpress.org/ticket/61337