AbstractScriptDataProviderTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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\ScriptDataProvider;
  12. use Symfony\Component\Intl\Intl;
  13. use Symfony\Component\Intl\Locale;
  14. /**
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. * @group intl-data
  17. */
  18. abstract class AbstractScriptDataProviderTest extends AbstractDataProviderTest
  19. {
  20. // The below arrays document the state of the ICU data bundled with this package.
  21. protected static $scripts = array(
  22. 'Afak',
  23. 'Arab',
  24. 'Armi',
  25. 'Armn',
  26. 'Avst',
  27. 'Bali',
  28. 'Bamu',
  29. 'Bass',
  30. 'Batk',
  31. 'Beng',
  32. 'Blis',
  33. 'Bopo',
  34. 'Brah',
  35. 'Brai',
  36. 'Bugi',
  37. 'Buhd',
  38. 'Cakm',
  39. 'Cans',
  40. 'Cari',
  41. 'Cham',
  42. 'Cher',
  43. 'Cirt',
  44. 'Copt',
  45. 'Cprt',
  46. 'Cyrl',
  47. 'Cyrs',
  48. 'Deva',
  49. 'Dsrt',
  50. 'Dupl',
  51. 'Egyd',
  52. 'Egyh',
  53. 'Egyp',
  54. 'Ethi',
  55. 'Geok',
  56. 'Geor',
  57. 'Glag',
  58. 'Goth',
  59. 'Gran',
  60. 'Grek',
  61. 'Gujr',
  62. 'Guru',
  63. 'Hang',
  64. 'Hani',
  65. 'Hano',
  66. 'Hans',
  67. 'Hant',
  68. 'Hebr',
  69. 'Hira',
  70. 'Hluw',
  71. 'Hmng',
  72. 'Hrkt',
  73. 'Hung',
  74. 'Inds',
  75. 'Ital',
  76. 'Java',
  77. 'Jpan',
  78. 'Jurc',
  79. 'Kali',
  80. 'Kana',
  81. 'Khar',
  82. 'Khmr',
  83. 'Khoj',
  84. 'Knda',
  85. 'Kore',
  86. 'Kpel',
  87. 'Kthi',
  88. 'Lana',
  89. 'Laoo',
  90. 'Latf',
  91. 'Latg',
  92. 'Latn',
  93. 'Lepc',
  94. 'Limb',
  95. 'Lina',
  96. 'Linb',
  97. 'Lisu',
  98. 'Loma',
  99. 'Lyci',
  100. 'Lydi',
  101. 'Mand',
  102. 'Mani',
  103. 'Maya',
  104. 'Mend',
  105. 'Merc',
  106. 'Mero',
  107. 'Mlym',
  108. 'Mong',
  109. 'Moon',
  110. 'Mroo',
  111. 'Mtei',
  112. 'Mymr',
  113. 'Narb',
  114. 'Nbat',
  115. 'Nkgb',
  116. 'Nkoo',
  117. 'Nshu',
  118. 'Ogam',
  119. 'Olck',
  120. 'Orkh',
  121. 'Orya',
  122. 'Osma',
  123. 'Palm',
  124. 'Perm',
  125. 'Phag',
  126. 'Phli',
  127. 'Phlp',
  128. 'Phlv',
  129. 'Phnx',
  130. 'Plrd',
  131. 'Prti',
  132. 'Rjng',
  133. 'Roro',
  134. 'Runr',
  135. 'Samr',
  136. 'Sara',
  137. 'Sarb',
  138. 'Saur',
  139. 'Sgnw',
  140. 'Shaw',
  141. 'Shrd',
  142. 'Sind',
  143. 'Sinh',
  144. 'Sora',
  145. 'Sund',
  146. 'Sylo',
  147. 'Syrc',
  148. 'Syre',
  149. 'Syrj',
  150. 'Syrn',
  151. 'Tagb',
  152. 'Takr',
  153. 'Tale',
  154. 'Talu',
  155. 'Taml',
  156. 'Tang',
  157. 'Tavt',
  158. 'Telu',
  159. 'Teng',
  160. 'Tfng',
  161. 'Tglg',
  162. 'Thaa',
  163. 'Thai',
  164. 'Tibt',
  165. 'Tirh',
  166. 'Ugar',
  167. 'Vaii',
  168. 'Visp',
  169. 'Wara',
  170. 'Wole',
  171. 'Xpeo',
  172. 'Xsux',
  173. 'Yiii',
  174. 'Zinh',
  175. 'Zmth',
  176. 'Zsym',
  177. 'Zxxx',
  178. 'Zyyy',
  179. 'Zzzz',
  180. );
  181. /**
  182. * @var ScriptDataProvider
  183. */
  184. protected $dataProvider;
  185. protected function setUp()
  186. {
  187. parent::setUp();
  188. $this->dataProvider = new ScriptDataProvider(
  189. $this->getDataDirectory().'/'.Intl::SCRIPT_DIR,
  190. $this->createEntryReader()
  191. );
  192. }
  193. abstract protected function getDataDirectory();
  194. public function testGetScripts()
  195. {
  196. $this->assertSame(static::$scripts, $this->dataProvider->getScripts());
  197. }
  198. /**
  199. * @dataProvider provideLocales
  200. */
  201. public function testGetNames($displayLocale)
  202. {
  203. $scripts = array_keys($this->dataProvider->getNames($displayLocale));
  204. sort($scripts);
  205. $this->assertSame(static::$scripts, $scripts);
  206. }
  207. public function testGetNamesDefaultLocale()
  208. {
  209. Locale::setDefault('de_AT');
  210. $this->assertSame(
  211. $this->dataProvider->getNames('de_AT'),
  212. $this->dataProvider->getNames()
  213. );
  214. }
  215. /**
  216. * @dataProvider provideLocaleAliases
  217. */
  218. public function testGetNamesSupportsAliases($alias, $ofLocale)
  219. {
  220. // Can't use assertSame(), because some aliases contain scripts with
  221. // different collation (=order of output) than their aliased locale
  222. // e.g. sr_Latn_ME => sr_ME
  223. $this->assertEquals(
  224. $this->dataProvider->getNames($ofLocale),
  225. $this->dataProvider->getNames($alias)
  226. );
  227. }
  228. /**
  229. * @dataProvider provideLocales
  230. */
  231. public function testGetName($displayLocale)
  232. {
  233. $names = $this->dataProvider->getNames($displayLocale);
  234. foreach ($names as $script => $name) {
  235. $this->assertSame($name, $this->dataProvider->getName($script, $displayLocale));
  236. }
  237. }
  238. public function testGetNameDefaultLocale()
  239. {
  240. Locale::setDefault('de_AT');
  241. $names = $this->dataProvider->getNames('de_AT');
  242. foreach ($names as $script => $name) {
  243. $this->assertSame($name, $this->dataProvider->getName($script));
  244. }
  245. }
  246. }