AbstractLocaleDataProviderTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Intl\Tests\Data\Provider;
  11. use Symfony\Component\Intl\Data\Provider\LocaleDataProvider;
  12. use Symfony\Component\Intl\Intl;
  13. use Symfony\Component\Intl\Locale;
  14. /**
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. */
  17. abstract class AbstractLocaleDataProviderTest extends AbstractDataProviderTest
  18. {
  19. /**
  20. * @var LocaleDataProvider
  21. */
  22. protected $dataProvider;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. $this->dataProvider = new LocaleDataProvider(
  27. $this->getDataDirectory().'/'.Intl::LOCALE_DIR,
  28. $this->createEntryReader()
  29. );
  30. }
  31. abstract protected function getDataDirectory();
  32. public function testGetLocales()
  33. {
  34. $this->assertSame($this->getLocales(), $this->dataProvider->getLocales());
  35. }
  36. public function testGetLocaleAliases()
  37. {
  38. $this->assertSame($this->getLocaleAliases(), $this->dataProvider->getAliases());
  39. }
  40. /**
  41. * @dataProvider provideLocales
  42. */
  43. public function testGetNames($displayLocale)
  44. {
  45. $locales = array_keys($this->dataProvider->getNames($displayLocale));
  46. sort($locales);
  47. $this->assertSame($this->getLocales(), $locales);
  48. }
  49. public function testGetNamesDefaultLocale()
  50. {
  51. Locale::setDefault('de_AT');
  52. $this->assertSame(
  53. $this->dataProvider->getNames('de_AT'),
  54. $this->dataProvider->getNames()
  55. );
  56. }
  57. /**
  58. * @dataProvider provideLocaleAliases
  59. */
  60. public function testGetNamesSupportsAliases($alias, $ofLocale)
  61. {
  62. // Can't use assertSame(), because some aliases contain scripts with
  63. // different collation (=order of output) than their aliased locale
  64. // e.g. sr_Latn_ME => sr_ME
  65. $this->assertEquals(
  66. $this->dataProvider->getNames($ofLocale),
  67. $this->dataProvider->getNames($alias)
  68. );
  69. }
  70. /**
  71. * @dataProvider provideLocales
  72. */
  73. public function testGetName($displayLocale)
  74. {
  75. $names = $this->dataProvider->getNames($displayLocale);
  76. foreach ($names as $locale => $name) {
  77. $this->assertSame($name, $this->dataProvider->getName($locale, $displayLocale));
  78. }
  79. }
  80. public function testGetNameDefaultLocale()
  81. {
  82. Locale::setDefault('de_AT');
  83. $names = $this->dataProvider->getNames('de_AT');
  84. foreach ($names as $locale => $name) {
  85. $this->assertSame($name, $this->dataProvider->getName($locale));
  86. }
  87. }
  88. }