Repository navigation
Tests: Restore the theme in the template REST tests that switch to block-theme. - #16266
mayankmajeji wants to merge 1 commit into
Conversation
…lock-theme`. `test_get_item_dates_are_null_for_file_backed_template()` and `test_get_template_fallback()` left block-theme's theme.json data in the resolver caches, so a later block render in `Tests_Media` picked up its duotone settings. Switch back to the previous theme in a `finally` block, which clears those caches. See #66755.
|
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:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the theme-restoration test changes.
No open issues 🎉
What changed in this PR
This PR improves REST template test isolation by restoring the original theme after two tests use block-theme, triggering cache invalidation and preventing theme data from leaking into later tests.
Changes:
- Save the active stylesheet before switching themes in both tests.
- Restore it in
finallyblocks, including when assertions fail, without changing existing test assertions.
| File | Description |
|---|---|
tests/phpunit/tests/rest-api/wpRestTemplatesController.php |
Adds theme restoration to the file-backed template date and template fallback tests. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
Both theme-switching tests independently caused the following media test to fail. Restoring the original theme in each finally block made all four producer/consumer runs pass across single-site and multisite. The controller class also passed in randomized order.
AI review · gpt-6.2-astra
Trac ticket: https://core.trac.wordpress.org/ticket/66755
Follow-up to comment:74 and comment:82.
Tests_REST_WpRestTemplatesController::test_get_item_dates_are_null_for_file_backed_template()and::test_get_template_fallback()callswitch_theme( 'block-theme' )and never switch back. The test case rolls back the theme options, butwp_clean_theme_json_cache()only runs onswitch_theme, so theWP_Theme_JSON_Resolvercaches keep block-theme's data. A later block render then picks up block-theme's duotone settings, andTests_Media::test_wp_filter_content_tags_does_not_lazy_load_first_featured_image_in_block_theme()getswp-duotone-custom-duotoneon the featured image.What changes
get_stylesheet()before switching and callswitch_theme()with it in afinallyblock, which runs the existing cache invalidation hook.Testing
Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65798.
The config below runs
rest-api/wpRestTemplatesController.phpand thenmedia.php.vendor/bin/phpunit -c pair.xml --filter '/test_get_item_dates_are_null_for_file_backed_template|test_wp_filter_content_tags_does_not_lazy_load_first_featured_image_in_block_theme/': 1 failure on trunk, OK (2 tests, 4 assertions) with this change, on single site and multisite.test_get_template_fallback$in place of the first test: 1 failure on trunk, OK (2 tests, 4 assertions) with this change, on single site and multisite.test_get_item_with_valid_theme_dirname()data sets also switch themes, but they do not affect the media test (OK on trunk), so they are unchanged.Tests_REST_WpRestTemplatesControllerwith--order-by=reverseand--order-by=random --random-order-seed=7: OK (50 tests).I also looked for a test that renders blocks while
block-themeis active. The only one isTests_Block_Template, which switches inset_up()and back intear_down(). Each of its template rendering tests, and the whole class, followed by the media test passes on single site and multisite (35 tests), so there is no separate duotone reproducer to add.