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

102 lines
2.6 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\Locale;
use Symfony\Component\Intl\Locales;
/**
* @group intl-data
*/
class LocalesTest extends ResourceBundleTestCase
{
public function testGetLocales()
{
$this->assertSame($this->getLocales(), Locales::getLocales());
}
public function testGetLocaleAliases()
{
$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()
{
Locale::setDefault('de_AT');
$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()
{
Locale::setDefault('de_AT');
$names = Locales::getNames('de_AT');
foreach ($names as $locale => $name) {
$this->assertSame($name, Locales::getName($locale));
}
}
2019-04-27 09:07:48 +01:00
/**
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
*/
public function testGetNameWithInvalidLocale()
{
Locales::getName('foo');
}
public function testExists()
{
$this->assertTrue(Locales::exists('nl_NL'));
$this->assertFalse(Locales::exists('zxx_ZZ'));
}
2018-10-12 20:48:56 +01:00
}