| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types = 1 ); |
| 4 |
|
| 5 |
namespace MediaWiki\Tests\Unit\Language; |
| 6 |
|
| 7 |
use LocalisationCache; |
| 8 |
use MediaWikiUnitTestCase; |
| 9 |
use Wikimedia\TestingAccessWrapper; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class LocalisationCacheTest extends MediaWikiUnitTestCase { |
| 16 |
|
| 17 |
public function testAllKeysSplitIntoCoreOnlyAndNonCoreOnly(): void { |
| 18 |
$coreOnlyKeys = TestingAccessWrapper::constant( LocalisationCache::class, 'CORE_ONLY_KEYS' ); |
| 19 |
$allExceptCoreOnlyKeys = TestingAccessWrapper::constant( LocalisationCache::class, 'ALL_EXCEPT_CORE_ONLY_KEYS' ); |
| 20 |
$this->assertSame( [], |
| 21 |
array_diff( $coreOnlyKeys, LocalisationCache::ALL_KEYS ), |
| 22 |
'core-only keys must be subset of all keys' ); |
| 23 |
$this->assertSame( [], |
| 24 |
array_diff( $allExceptCoreOnlyKeys, LocalisationCache::ALL_KEYS ), |
| 25 |
'keys that are not core-only must be subset of all keys' ); |
| 26 |
$this->assertSame( [], |
| 27 |
array_intersect( $coreOnlyKeys, $allExceptCoreOnlyKeys ), |
| 28 |
'core-only and other keys must not overlap' ); |
| 29 |
$this->assertSame( [], |
| 30 |
array_diff( LocalisationCache::ALL_KEYS, array_merge( |
| 31 |
$coreOnlyKeys, |
| 32 |
$allExceptCoreOnlyKeys |
| 33 |
) ), |
| 34 |
'core-only keys + all keys except them must contain all keys' ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testCoreOnlyKeysNotMergeable(): void { |
| 38 |
$coreOnlyKeys = TestingAccessWrapper::constant( LocalisationCache::class, 'CORE_ONLY_KEYS' ); |
| 39 |
$lc = TestingAccessWrapper::newFromClass( LocalisationCache::class ); |
| 40 |
foreach ( $coreOnlyKeys as $key ) { |
| 41 |
$this->assertFalse( $lc->isMergeableKey( $key ), |
| 42 |
'it does not make sense for core-only keys to be mergeable' ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
} |