LocalisationCache: Add tests for preload behavior
The new block in testRecacheExtensionMessagesFiles() covers the underlying issue of T343343 and T343375; see change Icc3324aca7 for an explanation of the issue. In order for this test to not crash, we also need to adjust some of the other tests and data. MessagesEn.php defines $preloadedMessages, and LocalisationCache assumes (quite rightly so, really) that all of these messages will be found in the configured MessagesDirs. But in the test, we override MessagesDirs to point at the test’s JSON files, while still using the original MessagesEn.php with its $preloadedMessages. Now that we are triggering the preload mechanism (I think it wasn’t reached by the tests previously?), it triggers a PHP deprecation (since PHP 8) on the missing messages, which makes the test fail: > explode(): Passing null to parameter #2 ($string) of type string is deprecated I decided to fix this by adding fake entries for all $preloadedMessages to the test en.json file. This makes the other tests that compare the entire messages array fail, so instead only compare the three messages those tests care about ("present-*"). I don’t like this very much, but I dislike the other two approaches I can think of even more: check defined( 'MW_PHPUNIT_TEST' ) in the original MessagesEn.php file, or add a test-specific MessagesEn.php using the Language::getMessagesFileName hook. Bug: T342418 Bug: T343343 Bug: T343375 Change-Id: Iee11cb5c52cb9dd777b70a1daa06f41f2c3ca187
This commit is contained in:
parent
bd2e830346
commit
fee22e61d8
3 changed files with 159 additions and 19 deletions
|
|
@ -15,5 +15,15 @@ $specialPageAliases['en'] = [
|
|||
'Activeusers' => [ 'ActiveFolx' ],
|
||||
];
|
||||
|
||||
// $namespaceNames can be set
|
||||
$namespaceNames['en'] = [
|
||||
98 => 'LocalisationCacheTest',
|
||||
99 => 'LocalisationCacheTest_talk',
|
||||
];
|
||||
$namespaceNames['de'] = [
|
||||
98 => 'LokalisierungsPufferTest',
|
||||
99 => 'LokalisierungsPufferTest_Diskussion',
|
||||
];
|
||||
|
||||
// $rtl cannot be set
|
||||
$rtl['de'] = true;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,116 @@
|
|||
{
|
||||
"present-ba": "en",
|
||||
"present-ru": "en",
|
||||
"present-en": "en"
|
||||
"present-en": "en",
|
||||
"aboutpage": "All the $preloadedMessages in MessageEn.php must also be defined here:",
|
||||
"aboutsite": "",
|
||||
"accesskey-ca-edit": "",
|
||||
"accesskey-ca-history": "",
|
||||
"accesskey-ca-nstab-main": "",
|
||||
"accesskey-ca-talk": "",
|
||||
"accesskey-ca-viewsource": "",
|
||||
"accesskey-n-currentevents": "",
|
||||
"accesskey-n-help": "",
|
||||
"accesskey-n-mainpage-description": "",
|
||||
"accesskey-n-portal": "",
|
||||
"accesskey-n-randompage": "",
|
||||
"accesskey-n-recentchanges": "",
|
||||
"accesskey-p-logo": "",
|
||||
"accesskey-pt-login": "",
|
||||
"accesskey-pt-createaccount": "",
|
||||
"accesskey-search": "",
|
||||
"accesskey-search-fulltext": "",
|
||||
"accesskey-search-go": "",
|
||||
"accesskey-t-info": "",
|
||||
"accesskey-t-permalink": "",
|
||||
"accesskey-t-print": "",
|
||||
"accesskey-t-recentchangeslinked": "",
|
||||
"accesskey-t-specialpages": "",
|
||||
"accesskey-t-whatlinkshere": "",
|
||||
"actions": "",
|
||||
"anonnotice": "",
|
||||
"brackets": "",
|
||||
"comma-separator": "",
|
||||
"currentevents": "",
|
||||
"currentevents-url": "",
|
||||
"disclaimerpage": "",
|
||||
"disclaimers": "",
|
||||
"edit": "",
|
||||
"editsection": "",
|
||||
"editsectionhint": "",
|
||||
"help": "",
|
||||
"helppage": "",
|
||||
"interlanguage-link-title": "",
|
||||
"jumpto": "",
|
||||
"jumptonavigation": "",
|
||||
"jumptosearch": "",
|
||||
"lastmodifiedat": "",
|
||||
"mainpage": "",
|
||||
"mainpage-description": "",
|
||||
"mainpage-nstab": "",
|
||||
"namespaces": "",
|
||||
"navigation": "",
|
||||
"nav-login-createaccount": "",
|
||||
"nstab-main": "",
|
||||
"opensearch-desc": "",
|
||||
"pagecategories": "",
|
||||
"pagecategorieslink": "",
|
||||
"pagetitle": "",
|
||||
"pagetitle-view-mainpage": "",
|
||||
"permalink": "",
|
||||
"personaltools": "",
|
||||
"portal": "",
|
||||
"portal-url": "",
|
||||
"printableversion": "",
|
||||
"privacy": "",
|
||||
"privacypage": "",
|
||||
"randompage": "",
|
||||
"randompage-url": "",
|
||||
"recentchanges": "",
|
||||
"recentchangeslinked-toolbox": "",
|
||||
"recentchanges-url": "",
|
||||
"retrievedfrom": "",
|
||||
"search": "",
|
||||
"searcharticle": "",
|
||||
"searchbutton": "",
|
||||
"searchsuggest-search": "",
|
||||
"sidebar": "",
|
||||
"navigation-heading": "",
|
||||
"site-atom-feed": "",
|
||||
"sitenotice": "",
|
||||
"specialpages": "",
|
||||
"tagline": "",
|
||||
"talk": "",
|
||||
"toolbox": "",
|
||||
"tooltip-ca-edit": "",
|
||||
"tooltip-ca-history": "",
|
||||
"tooltip-ca-nstab-main": "",
|
||||
"tooltip-ca-talk": "",
|
||||
"tooltip-ca-viewsource": "",
|
||||
"tooltip-n-currentevents": "",
|
||||
"tooltip-n-help": "",
|
||||
"tooltip-n-mainpage-description": "",
|
||||
"tooltip-n-portal": "",
|
||||
"tooltip-n-randompage": "",
|
||||
"tooltip-n-recentchanges": "",
|
||||
"tooltip-p-logo": "",
|
||||
"tooltip-pt-login": "",
|
||||
"tooltip-pt-createaccount": "",
|
||||
"tooltip-search": "",
|
||||
"tooltip-search-fulltext": "",
|
||||
"tooltip-search-go": "",
|
||||
"tooltip-t-info": "",
|
||||
"tooltip-t-permalink": "",
|
||||
"tooltip-t-print": "",
|
||||
"tooltip-t-recentchangeslinked": "",
|
||||
"tooltip-t-specialpages": "",
|
||||
"tooltip-t-whatlinkshere": "",
|
||||
"variants": "",
|
||||
"vector-view-edit": "",
|
||||
"vector-view-history": "",
|
||||
"vector-view-view": "",
|
||||
"viewcount": "",
|
||||
"views": "",
|
||||
"whatlinkshere": "",
|
||||
"word-separator": ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,15 +83,12 @@ class LocalisationCacheTest extends MediaWikiIntegrationTestCase {
|
|||
public function testRecacheFallbacks() {
|
||||
$lc = $this->getMockLocalisationCache();
|
||||
$lc->recache( 'ba' );
|
||||
$this->assertEquals(
|
||||
[
|
||||
'present-ba' => 'ba',
|
||||
'present-ru' => 'ru',
|
||||
'present-en' => 'en',
|
||||
],
|
||||
$lc->getItem( 'ba', 'messages' ),
|
||||
'Fallbacks are only used to fill missing data'
|
||||
);
|
||||
$messages = $lc->getItem( 'ba', 'messages' );
|
||||
|
||||
// Fallbacks are only used to fill missing data
|
||||
$this->assertSame( 'ba', $messages['present-ba'] );
|
||||
$this->assertSame( 'ru', $messages['present-ru'] );
|
||||
$this->assertSame( 'en', $messages['present-en'] );
|
||||
}
|
||||
|
||||
public function testRecacheFallbacksWithHooks() {
|
||||
|
|
@ -113,26 +110,43 @@ class LocalisationCacheTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
] );
|
||||
$lc->recache( 'ba' );
|
||||
$this->assertEquals(
|
||||
[
|
||||
'present-ba' => 'ba',
|
||||
'present-ru' => 'ru-override',
|
||||
'present-en' => 'ru-override',
|
||||
],
|
||||
$lc->getItem( 'ba', 'messages' ),
|
||||
'Updates provided by hooks follow the normal fallback order.'
|
||||
);
|
||||
$messages = $lc->getItem( 'ba', 'messages' );
|
||||
|
||||
// Updates provided by hooks follow the normal fallback order.
|
||||
$this->assertSame( 'ba', $messages['present-ba'] );
|
||||
$this->assertSame( 'ru-override', $messages['present-ru'] );
|
||||
$this->assertSame( 'ru-override', $messages['present-en'] );
|
||||
}
|
||||
|
||||
public function testRecacheExtensionMessagesFiles(): void {
|
||||
global $IP;
|
||||
|
||||
// first, recache the l10n cache and test it
|
||||
$lc = $this->getMockLocalisationCache( [], [
|
||||
'ExtensionMessagesFiles' => [
|
||||
__METHOD__ => "$IP/tests/phpunit/data/localisationcache/ExtensionMessagesFiles.php",
|
||||
]
|
||||
] );
|
||||
$lc->recache( 'de' );
|
||||
$this->assertExtensionMessagesFiles( $lc );
|
||||
|
||||
// then, make another l10n cache sharing the first one’s LCStore and test that (T343375)
|
||||
$lc = $this->getMockLocalisationCache( [], [
|
||||
'ExtensionMessagesFiles' => [
|
||||
__METHOD__ => "$IP/tests/phpunit/data/localisationcache/ExtensionMessagesFiles.php",
|
||||
]
|
||||
] );
|
||||
// no recache this time, but load only the core data first by getting the fallbackSequence
|
||||
$lc->getItem( 'de', 'fallbackSequence' );
|
||||
$this->assertExtensionMessagesFiles( $lc );
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given LocalisationCache, which should be configured with
|
||||
* ExtensionMessagesFiles containing the ExtensionMessagesFiles.php test fixture file,
|
||||
* contains the expected data.
|
||||
*/
|
||||
private function assertExtensionMessagesFiles( LocalisationCache $lc ): void {
|
||||
$specialPageAliases = $lc->getItem( 'de', 'specialPageAliases' );
|
||||
$this->assertSame(
|
||||
[ 'LokalisierungsPufferTest' ],
|
||||
|
|
@ -144,6 +158,11 @@ class LocalisationCacheTest extends MediaWikiIntegrationTestCase {
|
|||
$specialPageAliases['Activeusers'],
|
||||
'specialPageAliases from extension/core files and fallback languages are merged'
|
||||
);
|
||||
$namespaceNames = $lc->getItem( 'de', 'namespaceNames' );
|
||||
$this->assertSame(
|
||||
'LokalisierungsPufferTest',
|
||||
$namespaceNames[98]
|
||||
);
|
||||
$this->assertFalse(
|
||||
$lc->getItem( 'de', 'rtl' ),
|
||||
'rtl cannot be set in ExtensionMessagesFiles'
|
||||
|
|
|
|||
Loading…
Reference in a new issue