wiki.techinc.nl/tests/phpunit/unit/includes/language/LocalisationCacheTest.php

47 lines
1.6 KiB
PHP
Raw Normal View History

LocalisationCache: Add CORE_ONLY_KEYS, ALL_EXCEPT_CORE_ONLY_KEYS Previously, it was technically possible to set some keys in extension messages files that didn’t make much sense (e.g. $rtl['en'] = true;). This prevents optimizing language creation, so going forward, we will no longer support that; ALL_KEYS is now split into CORE_ONLY_KEYS and ALL_EXCEPT_CORE_ONLY_KEYS (with a test verifying that no key is missing or overlapping or anything), and ALL_EXCEPT_CORE_ONLY_KEYS are silently skipped when loading extension messages files. To demonstrate that it’s okay to silently skip these keys, patch set 1 of this change on Gerrit instead raised a deprecation warning; CI indicated that this warning was never hit. Codesearch [1] also suggests that no known extension was actually using any of these keys. (The DonationInterface [2] and LandingCheck [3] codesearch results can be ignored: both of these define es-419 as a new language, using the Language::getMessagesFileName hook to register their MessagesEs_419.php as a “core” message file, not an extension message file.) [1]: https://codesearch.wmcloud.org/search/?q=^\%24(fallback|rtl|(digit|separator)TransformTable|fallback8bitEncoding|link(PrefixExtension|Trail|PrefixCharset)|date(Formats|Preferences|PreferenceMigrationMap)|defaultDateFormat|digitGroupingPattern).*%3D&files=\.php%24 [2]: https://gerrit.wikimedia.org/g/mediawiki/extensions/DonationInterface/+/f8b5fe95f77c8a9bc516bc52084d001477c70e2d/gateway_common/messages/MessagesEs_419.php#11 [3]: https://gerrit.wikimedia.org/g/mediawiki/extensions/LandingCheck/+/2537439aeebaf6ccc71b897fa683cdc4d06ae9d3/messages/MessagesEs_419.php#11 Bug: T342418 Change-Id: Ia3dffea390d4efdfa3a3cea549d079507718ef48
2023-07-21 09:31:43 +00:00
<?php
declare( strict_types = 1 );
namespace MediaWiki\Tests\Unit\Language;
use LocalisationCache;
use MediaWikiUnitTestCase;
use Wikimedia\TestingAccessWrapper;
/**
* @covers LocalisationCache
* @group Language
*/
class LocalisationCacheTest extends MediaWikiUnitTestCase {
public function testAllKeysSplitIntoCoreOnlyAndNonCoreOnly(): void {
$coreOnlyKeys = TestingAccessWrapper::constant( LocalisationCache::class, 'CORE_ONLY_KEYS' );
$allExceptCoreOnlyKeys = TestingAccessWrapper::constant( LocalisationCache::class, 'ALL_EXCEPT_CORE_ONLY_KEYS' );
$this->assertSame( [],
array_diff( $coreOnlyKeys, LocalisationCache::ALL_KEYS ),
'core-only keys must be subset of all keys' );
$this->assertSame( [],
array_diff( $allExceptCoreOnlyKeys, LocalisationCache::ALL_KEYS ),
'keys that are not core-only must be subset of all keys' );
$this->assertSame( [],
array_intersect( $coreOnlyKeys, $allExceptCoreOnlyKeys ),
'core-only and other keys must not overlap' );
$this->assertSame( [],
array_diff( LocalisationCache::ALL_KEYS, array_merge(
$coreOnlyKeys,
$allExceptCoreOnlyKeys
) ),
'core-only keys + all keys except them must contain all keys' );
}
public function testCoreOnlyKeysNotMergeable(): void {
$coreOnlyKeys = TestingAccessWrapper::constant( LocalisationCache::class, 'CORE_ONLY_KEYS' );
$lc = TestingAccessWrapper::newFromClass( LocalisationCache::class );
foreach ( $coreOnlyKeys as $key ) {
$this->assertFalse( $lc->isMergeableKey( $key ),
'it does not make sense for core-only keys to be mergeable' );
}
}
}