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/LocalesTest.php

106 lines
2.9 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;
use Symfony\Component\Intl\Locales;
/**
* @group intl-data
*/
class LocalesTest extends ResourceBundleTestCase
{
public function testGetLocales()
{
$this->assertSame($this->getLocales(), Locales::getLocales());
}
2019-05-01 18:05:41 +01:00
public function testGetAliases()
2018-10-12 20:48:56 +01:00
{
$this->assertSame($this->getLocaleAliases(), Locales::getAliases());
}
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$locales = array_keys(Locales::getNames($displayLocale));
sort($locales);
// We can't assert on exact list of locale, as there's too many variations.
// The best we can do is to make sure getNames() returns a subset of what getLocales() returns.
$this->assertNotEmpty($locales);
$this->assertEmpty(array_diff($locales, $this->getLocales()));
}
public function testGetNamesDefaultLocale()
{
2019-05-01 18:05:41 +01:00
\Locale::setDefault('de_AT');
2018-10-12 20:48:56 +01:00
$this->assertSame(Locales::getNames('de_AT'), Locales::getNames());
}
/**
* @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
$this->assertEquals(Locales::getNames($ofLocale), Locales::getNames($alias));
}
/**
* @dataProvider provideLocales
*/
public function testGetName($displayLocale)
{
$names = Locales::getNames($displayLocale);
foreach ($names as $locale => $name) {
$this->assertSame($name, Locales::getName($locale, $displayLocale));
}
}
public function testGetNameDefaultLocale()
{
2019-05-01 18:05:41 +01:00
\Locale::setDefault('de_AT');
2018-10-12 20:48:56 +01:00
$names = Locales::getNames('de_AT');
foreach ($names as $locale => $name) {
$this->assertSame($name, Locales::getName($locale));
}
}
2019-04-27 09:07:48 +01:00
public function testGetNameWithInvalidLocale()
{
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
2019-04-27 09:07:48 +01:00
Locales::getName('foo');
}
public function testGetNameWithAliasLocale()
{
$this->assertSame(Locales::getName('tl_PH'), Locales::getName('fil_PH'));
}
2019-04-27 09:07:48 +01:00
public function testExists()
{
$this->assertTrue(Locales::exists('nl_NL'));
$this->assertTrue(Locales::exists('tl_PH'));
$this->assertTrue(Locales::exists('fil_PH')); // alias for "tl_PH"
2019-04-27 09:07:48 +01:00
$this->assertFalse(Locales::exists('zxx_ZZ'));
}
2018-10-12 20:48:56 +01:00
}