Repository navigation
Tests: Clear the unloaded text domains after each WP_Translation_Controller_Tests test. - #16251
mayankmajeji wants to merge 2 commits into
Conversation
…troller_Tests` test. When an earlier class left `internationalized-plugin` translations loaded, the class's own `tear_down()` marked the domain as unloaded, so a later test of the class could not load it and left the locale switched for the rest of the run. Unset `$l10n_unloaded` after unloading, as the just-in-time loading and locale switcher tests do. 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 are recorded for the translation-controller test-isolation cleanup.
No open issues 🎉
What changed in this PR
This PR improves translation-controller test isolation by clearing unloaded text-domain state after each test, preventing order-dependent translation-loading failures.
Changes:
- Unsets
$GLOBALS['l10n_unloaded']after unloading both test domains, following cleanup patterns used by other localization tests.
| File | Description |
|---|---|
tests/phpunit/tests/l10n/wpTranslationController.php |
Clears unloaded-domain markers in tear_down() so later tests can reload translations. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
The four-test sequence reproduced the translation failure on both single-site and multisite. Could you limit the cleanup to the two domains this class unloads? Unsetting all of $GLOBALS['l10n_unloaded'] also makes unrelated domains eligible for just-in-time loading again. I tried unsetting just the wp-tests-domain and internationalized-plugin entries. All four tests passed in both modes, and the 19 translation controller tests passed in random order.
AI review · gpt-6.2-astra
Unsetting all of `$l10n_unloaded` would make unrelated domains eligible for just-in-time loading again.
|
Thanks @lancewillett, that makes sense. I've pushed 14604f6, which unsets only the Rechecked on PHP 8.4:
|
lancewillett
left a comment
There was a problem hiding this comment.
Confirmed the narrower cleanup fixes the original failure. With the same four tests in order, the translation check failed on trunk on both single-site and multisite. Clearing just these two domain markers passed all 25 assertions in each mode.
AI review · gpt-6.2-astra
Trac ticket: https://core.trac.wordpress.org/ticket/66755
WP_Translation_Controller_Tests::tear_down()callsunload_textdomain( 'internationalized-plugin' ). When real translations for that domain are loaded at that point,unload_textdomain()also adds it to the global$l10n_unloaded, and_load_textdomain_just_in_time()then never loads it again. Nothing clears that global, so a later test of the class that needs the domain cannot load it.That happens when an earlier class leaves
internationalized-plugintranslations loaded:WP_REST_Plugins_Controller_Test::test_get_items_status()reads the plugin headers, which adds the domain to$l10n(not yet translated).Tests_User_wpSendUserRequest::test_should_send_user_request_email_in_user_locale_when_site_is_not_en_us()switches the locale to send the email, which reloads the domain with real translations, and they stay after the locale is restored.WP_Translation_Controller_Teststest to run unloads the domain intear_down(), which adds it to$l10n_unloaded.test_switch_to_locale_translations_stay_loaded_custom_textdomain()switches toes_ES, cannot load theinternationalized-plugintranslations ("Failed asserting that false is true" at theis_textdomain_loaded()check), and stops beforerestore_previous_locale().Because the locale stays
es_ES, every later test that checks the locale fails too. In the run where this was found, 23 more tests failed inTests_General_GetLanguageAttributes,Tests_Formatting_GetBloginfo,Tests_L10n_GetLocaleandTests_Date_MaybeDeclineDate.Tests_L10n_LoadTextdomainJustInTimeandTests_L10n_wpLocaleSwitcheralready unset$GLOBALS['l10n_unloaded']in their owntear_down().What changes
WP_Translation_Controller_Tests::tear_down()unsets thewp-tests-domainandinternationalized-pluginentries of$GLOBALS['l10n_unloaded']after unloading those two text domains, so other domains stay as they are.Testing
Locally with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39, on trunk at r65790.
The config below runs
rest-api/rest-plugins-controller.php,user/wpSendUserRequest.phpandl10n/wpTranslationController.php, and the--filterkeeps the four tests above, in that order (test_load_textdomain()as the firstWP_Translation_Controller_Teststest).vendor/bin/phpunit -c chain.xml --filter '/::test_get_items_status$|::test_should_send_user_request_email_in_user_locale_when_site_is_not_en_us$|WP_Translation_Controller_Tests::test_(load_textdomain|switch_to_locale_translations_stay_loaded_custom_textdomain)$/': 1 failure on trunk, OK (4 tests, 25 assertions) with this change.<const name="WP_TESTS_MULTISITE" value="1" />added).Tests_User_wpSendUserRequesttest: OK on trunk.WP_Translation_Controller_Testsin default order, with--order-by=reverseand with--order-by=random --random-order-seed=7: OK with this change.--group l10n(291 tests, also on multisite) and--group i18n(304 tests): no failures with this change.-c tests/phpunit/multisite.xml --order-by=random --random-order-seed=1717on trunk at r65781 (24 failures). The random order depends on the set of tests, so the seed gives a different order on current trunk; the config reproduces the failure without a seed.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.