1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<?php
declare(strict_types=1);
namespace Giggsey\Locale\Tests;
use Giggsey\Locale\Locale;
use PHPUnit\Framework\TestCase;
class DisplayRegionTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('dataDisplayRegions')]
public function testGetDisplayRegion(string $locale, string $inLocale, string $expectedRegion): void
{
$this->assertSame(
$expectedRegion,
Locale::getDisplayRegion($locale, $inLocale),
"getDisplayRegion with $locale and $inLocale"
);
}
/**
* @see testGetDisplayRegion
*/
public static function dataDisplayRegions(): array
{
return array_merge(
self::dataForUnitedKingdom(),
self::dataForGermany(),
self::dataForMissingEntries(),
self::dataForInvalidRegions()
);
}
protected static function dataForUnitedKingdom(): array
{
return [
['en-GB', 'en-GB', 'United Kingdom'],
['en_GB', 'en-GB', 'United Kingdom'],
['en-GB', 'en_GB', 'United Kingdom'],
['en_GB', 'en_GB', 'United Kingdom'],
['fake-GB', 'en-GB', 'United Kingdom'],
['en-GB', 'en-US', 'United Kingdom'],
['en-GB', 'fr-FR', 'Royaume-Uni'],
['en-GB', 'fr-CH', 'Royaume-Uni'],
['en-GB', 'de-DE', 'Vereinigtes Königreich'],
['en-GB', 'de-CH', 'Vereinigtes Königreich'],
['en-GB', 'dz', 'ཡུ་ནཱའི་ཊེཌ་ ཀིང་ཌམ'],
['en-GB', 'ro', 'Regatul Unit'],
['en-GB', 'ru', 'Великобритания'],
['en-GB', 'ru-UA', 'Великобритания'],
['en-GB', 'zh', '英国'],
['en-GB', 'zh-Hans-HK', '英国'],
['en-GB', 'zh-Hant-HK', '英國'],
['EN-gb', 'EN-gb', 'United Kingdom'],
];
}
protected static function dataForGermany(): array
{
return [
['-de', 'en-GB', 'Germany'],
['de-DE', 'en', 'Germany'],
['de-DE', 'en-GB', 'Germany'],
['de-DE', 'en-US', 'Germany'],
['de-DE', 'de', 'Deutschland'],
['de-DE', 'de-DE', 'Deutschland'],
['de-DE', 'ru', 'Германия'],
['de-DE', 'fr', 'Allemagne'],
];
}
protected static function dataForMissingEntries(): array
{
return [
['-rs', 'en', 'Serbia'],
['-rs', 'ee', ''], // PHP returns 'RS' here, which I think is wrong...
];
}
protected static function dataForInvalidRegions(): array
{
return [
['fake-too', 'en', ''],
['en', 'en-GB', ''],
['en-GB', 'fake-GB', ''],
];
}
}
|