Repository navigation
Tests: Clear the theme.json cache before each WP_Theme_UnitTestCase test. - #16226
mayankmajeji wants to merge 1 commit into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
|
@mayankmajeji Are you able to split the commits in to two:
Then can you force push just the first commit to this PR, wait for the tests to run and then push the fix? Depending on your permissions you might be able to get Claude to push, monitor the test status and push again. |
a1c01f1 to
4e0de9a
Compare
|
Thanks @mukeshpanchal27, done. The original failures only show up in some random orders, and CI runs the default order, so the bug needed a test that fails in the default order too. The first commit adds
Locally the new test also fails on trunk inside |
There was a problem hiding this comment.
🟡 Changes recommended
The regression test can pass without the fix when an existing resolver cache bypasses the temporary palette, so the cache must be cleared before priming to avoid class-order dependence.
1 open issue
What changed in this PR
This PR improves isolation for tests extending WP_Theme_UnitTestCase by clearing theme.json caches before each test, preventing cached data from earlier classes from affecting results.
Changes:
- Clears theme.json caches during setup, matching existing teardown behavior.
- Adds a regression test that seeds a temporary palette and checks that its stale CSS variable is absent after setup.
| File | Description |
|---|---|
tests/phpunit/tests/theme/wpThemeUnitTestCase.php |
Adds regression coverage for stale theme.json palette data. |
tests/phpunit/tests/theme/base.php |
Clears theme.json caches before each theme test. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
The one-line set_up() fix is justified. I reproduced both failures using only the existing classes, on single-site and multisite. With the reset, the same ordered runs passed (7 tests and 288 tests respectively).
Please keep that line and drop tests/phpunit/tests/theme/wpThemeUnitTestCase.php from the final patch. The two-commit demonstration was helpful. I also reproduced Copilot’s concern: without the fix, the new test fails alone but passes after Tests_Theme_wpThemeGetPostTemplates. The existing stylesheet test still fails after that same class and catches the real problem. Please keep those two reproduction commands in the description for future reviewers.
AI review · gpt-6
The resolver caches outlive a test class, so the first test of a `WP_Theme_UnitTestCase` class could read theme.json data from the previous class. Clear them in `set_up()` as `tear_down()` already does. See #66755.
3de6c62 to
2d78672
Compare
|
Thanks @lancewillett. Done: I force-pushed a single commit with only the You and Copilot are right about the test: its |
lancewillett
left a comment
There was a problem hiding this comment.
The revised patch keeps the single reset and removes the synthetic class. I verified the changed file matches the one I tested against both existing stylesheet failures. In the same class order, both site modes passed with the reset: 7 tests in the post-template pair and 288 in the theme JSON pair. Thanks for preserving both reproductions in the description.
AI review · gpt-6
…eme_UnitTestCase`. Prevent stylesheet tests from reading theme data cached by an earlier test class. Developed in: #16226 Props mayankmajeji, mukesh27. See #66755. git-svn-id: https://develop.svn.wordpress.org/trunk@65780 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #16226 landed in https://core.trac.wordpress.org/changeset/65780 |
…eme_UnitTestCase`. Prevent stylesheet tests from reading theme data cached by an earlier test class. Developed in: WordPress/wordpress-develop#16226 Props mayankmajeji, mukesh27. See #66755. Built from https://develop.svn.wordpress.org/trunk@65780 git-svn-id: http://core.svn.wordpress.org/trunk@64809 1a063a9b-81f0-0310-95a4-ce76da25c4cd

Trac ticket: https://core.trac.wordpress.org/ticket/66755
WP_Theme_UnitTestCase::tear_down()callswp_clean_theme_json_cache(), butset_up()only callswp_clean_themes_cache(). The static caches inWP_Theme_JSON_Resolver($theme,$mergedand the others reset byclean_cached_data()) last for the whole PHP process, so the first test of a theme class runs with whatever theme.json data the previous class left there. Inside a class, the previous test'stear_down()clears it, which is why the default order passes.Two
Tests_Theme_WpGetGlobalStylesheettests fail when they are the first test of their class to run:Tests_Theme_wpThemeGetPostTemplates, which switches toblock-theme,test_switching_themes_should_recalculate_stylesheet()finds the block theme's--wp--preset--font-size--custom: 100pxin the stylesheet for the default theme.Tests_Theme_wpThemeJson,test_theme_color_palette_presets_output_when_border_support_enabled()gets theme data computed before it addededitor-color-palette, so its colors are missing.Both pass on their own.
What changes
WP_Theme_UnitTestCase::set_up()callswp_clean_theme_json_cache()next towp_clean_themes_cache(), astear_down()already does.Testing
Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65764.
The
--filtermakes the stylesheet test the first test of its class, as in the random runs. Config A runstheme/wpThemeGetPostTemplates.phpand thentheme/wpGetGlobalStylesheet.php, config B runstheme/wpThemeJson.phpand thentheme/wpGetGlobalStylesheet.php(configs below).vendor/bin/phpunit -c pair-a.xml --filter 'Tests_Theme_wpThemeGetPostTemplates|test_switching_themes_should_recalculate_stylesheet': 1 failure on trunk ("Custom font size (100px) should not present for default theme"), OK (7 tests, 32 assertions) with this change.vendor/bin/phpunit -c pair-b.xml --filter 'Tests_Theme_wpThemeJson|test_theme_color_palette_presets_output_when_border_support_enabled': 1 failure on trunk (--wp--preset--color--nice-black: #000000missing), OK (288 tests, 516 assertions) with this change.<const name="WP_TESTS_MULTISITE" value="1" />added).vendor/bin/phpunit --group themes --order-by=random --random-order-seed=Nfor N = 1 to 10: OK (817 tests) with this change, and for seeds 2 and 7 with-c tests/phpunit/multisite.xml(821 tests).WP_Theme_UnitTestCase, each on its own in default order, with--order-by=reverseand with--order-by=random --random-order-seed=7: OK with this change.--group themesin random order (20 seeds): seed 2 and seed 7 failed on trunk.For config B, replace
theme/wpThemeGetPostTemplates.phpwiththeme/wpThemeJson.php.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigation, code, local testing and PR wording. I reviewed the reasoning, the code and the test results, and I take responsibility for the contribution.