This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Intl/Tests/CountriesTest.php

360 lines
6.2 KiB
PHP
Raw Normal View History

2018-10-12 20:48:56 +01:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Intl\Tests;
2019-05-01 18:05:41 +01:00
use Symfony\Component\Intl\Countries;
2018-10-12 20:48:56 +01:00
/**
* @group intl-data
*/
2019-05-01 18:05:41 +01:00
class CountriesTest extends ResourceBundleTestCase
2018-10-12 20:48:56 +01:00
{
// The below arrays document the state of the ICU data bundled with this package.
2019-05-01 18:05:41 +01:00
private static $countries = [
2018-10-12 20:48:56 +01:00
'AC',
'AD',
'AE',
'AF',
'AG',
'AI',
'AL',
'AM',
'AO',
'AQ',
'AR',
'AS',
'AT',
'AU',
'AW',
'AX',
'AZ',
'BA',
'BB',
'BD',
'BE',
'BF',
'BG',
'BH',
'BI',
'BJ',
'BL',
'BM',
'BN',
'BO',
'BQ',
'BR',
'BS',
'BT',
'BW',
'BY',
'BZ',
'CA',
'CC',
'CD',
'CF',
'CG',
'CH',
'CI',
'CK',
'CL',
'CM',
'CN',
'CO',
'CR',
'CU',
'CV',
'CW',
'CX',
'CY',
'CZ',
'DE',
'DG',
'DJ',
'DK',
'DM',
'DO',
'DZ',
'EA',
'EC',
'EE',
'EG',
'EH',
'ER',
'ES',
'ET',
'FI',
'FJ',
'FK',
'FM',
'FO',
'FR',
'GA',
'GB',
'GD',
'GE',
'GF',
'GG',
'GH',
'GI',
'GL',
'GM',
'GN',
'GP',
'GQ',
'GR',
'GS',
'GT',
'GU',
'GW',
'GY',
'HK',
'HN',
'HR',
'HT',
'HU',
'IC',
'ID',
'IE',
'IL',
'IM',
'IN',
'IO',
'IQ',
'IR',
'IS',
'IT',
'JE',
'JM',
'JO',
'JP',
'KE',
'KG',
'KH',
'KI',
'KM',
'KN',
'KP',
'KR',
'KW',
'KY',
'KZ',
'LA',
'LB',
'LC',
'LI',
'LK',
'LR',
'LS',
'LT',
'LU',
'LV',
'LY',
'MA',
'MC',
'MD',
'ME',
'MF',
'MG',
'MH',
'MK',
'ML',
'MM',
'MN',
'MO',
'MP',
'MQ',
'MR',
'MS',
'MT',
'MU',
'MV',
'MW',
'MX',
'MY',
'MZ',
'NA',
'NC',
'NE',
'NF',
'NG',
'NI',
'NL',
'NO',
'NP',
'NR',
'NU',
'NZ',
'OM',
'PA',
'PE',
'PF',
'PG',
'PH',
'PK',
'PL',
'PM',
'PN',
'PR',
'PS',
'PT',
'PW',
'PY',
'QA',
'RE',
'RO',
'RS',
'RU',
'RW',
'SA',
'SB',
'SC',
'SD',
'SE',
'SG',
'SH',
'SI',
'SJ',
'SK',
'SL',
'SM',
'SN',
'SO',
'SR',
'SS',
'ST',
'SV',
'SX',
'SY',
'SZ',
'TA',
'TC',
'TD',
'TF',
'TG',
'TH',
'TJ',
'TK',
'TL',
'TM',
'TN',
'TO',
'TR',
'TT',
'TV',
'TW',
'TZ',
'UA',
'UG',
'UM',
'US',
'UY',
'UZ',
'VA',
'VC',
'VE',
'VG',
'VI',
'VN',
'VU',
'WF',
'WS',
'XA',
'XB',
'XK',
'YE',
'YT',
'ZA',
'ZM',
'ZW',
];
2019-05-01 18:05:41 +01:00
public function testGetCountryCodes()
2018-10-12 20:48:56 +01:00
{
2019-05-01 18:05:41 +01:00
$this->assertSame(self::$countries, Countries::getCountryCodes());
2018-10-12 20:48:56 +01:00
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
2019-05-01 18:05:41 +01:00
$countries = array_keys(Countries::getNames($displayLocale));
2018-10-12 20:48:56 +01:00
sort($countries);
2019-05-01 18:05:41 +01:00
$this->assertSame(self::$countries, $countries);
2018-10-12 20:48:56 +01:00
}
public function testGetNamesDefaultLocale()
{
2019-05-01 18:05:41 +01:00
\Locale::setDefault('de_AT');
2018-10-12 20:48:56 +01:00
2019-05-01 18:05:41 +01:00
$this->assertSame(Countries::getNames('de_AT'), Countries::getNames());
2018-10-12 20:48:56 +01:00
}
/**
* @dataProvider provideLocaleAliases
*/
public function testGetNamesSupportsAliases($alias, $ofLocale)
{
// Can't use assertSame(), because some aliases contain scripts with
// different collation (=order of output) than their aliased locale
// e.g. sr_Latn_ME => sr_ME
2019-05-01 18:05:41 +01:00
$this->assertEquals(Countries::getNames($ofLocale), Countries::getNames($alias));
2018-10-12 20:48:56 +01:00
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
2019-05-01 18:05:41 +01:00
$names = Countries::getNames($displayLocale);
2018-10-12 20:48:56 +01:00
foreach ($names as $country => $name) {
2019-05-01 18:05:41 +01:00
$this->assertSame($name, Countries::getName($country, $displayLocale));
2018-10-12 20:48:56 +01:00
}
}
/**
* @requires extension intl
*/
public function testLocaleAliasesAreLoaded()
{
\Locale::setDefault('zh_TW');
2019-05-01 18:05:41 +01:00
$countryNameZhTw = Countries::getName('AD');
2018-10-12 20:48:56 +01:00
\Locale::setDefault('zh_Hant_TW');
2019-05-01 18:05:41 +01:00
$countryNameHantZhTw = Countries::getName('AD');
2018-10-12 20:48:56 +01:00
\Locale::setDefault('zh');
2019-05-01 18:05:41 +01:00
$countryNameZh = Countries::getName('AD');
2018-10-12 20:48:56 +01:00
$this->assertSame($countryNameZhTw, $countryNameHantZhTw, 'zh_TW is an alias to zh_Hant_TW');
$this->assertNotSame($countryNameZh, $countryNameZhTw, 'zh_TW does not fall back to zh');
}
2019-04-27 09:07:48 +01:00
/**
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
2019-05-01 18:05:41 +01:00
public function testGetNameWithInvalidCountryCode()
2019-04-27 09:07:48 +01:00
{
2019-05-01 18:05:41 +01:00
Countries::getName('foo');
2019-04-27 09:07:48 +01:00
}
public function testExists()
{
2019-05-01 18:05:41 +01:00
$this->assertTrue(Countries::exists('NL'));
$this->assertFalse(Countries::exists('ZZ'));
2019-04-27 09:07:48 +01:00
}
2018-10-12 20:48:56 +01:00
}