StubLocaleTest.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. namespace Symfony\Tests\Component\Locale\Stub;
  3. use Symfony\Component\Locale\Stub\StubLocale;
  4. /*
  5. * This file is part of the Symfony framework.
  6. *
  7. * (c) Fabien Potencier <fabien@symfony.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. class StubLocaleTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @expectedException InvalidArgumentException
  16. */
  17. public function testGetDisplayCountriesWithUnsupportedLocale()
  18. {
  19. $countries = StubLocale::getDisplayCountries('pt_BR');
  20. }
  21. public function testGetDisplayCountries()
  22. {
  23. $countries = StubLocale::getDisplayCountries('en');
  24. $this->assertEquals('Brazil', $countries['BR']);
  25. }
  26. public function testGetCountries()
  27. {
  28. $countries = StubLocale::getCountries();
  29. $this->assertTrue(in_array('BR', $countries));
  30. }
  31. /**
  32. * @expectedException InvalidArgumentException
  33. */
  34. public function testGetDisplayLanguagesWithUnsupportedLocale()
  35. {
  36. $countries = StubLocale::getDisplayLanguages('pt_BR');
  37. }
  38. public function testGetDisplayLanguages()
  39. {
  40. $languages = StubLocale::getDisplayLanguages('en');
  41. $this->assertEquals('Brazilian Portuguese', $languages['pt_BR']);
  42. }
  43. public function testGetLanguages()
  44. {
  45. $languages = StubLocale::getLanguages();
  46. $this->assertTrue(in_array('pt_BR', $languages));
  47. }
  48. /**
  49. * @expectedException InvalidArgumentException
  50. */
  51. public function testGetCurrenciesDataWithUnsupportedLocale()
  52. {
  53. $currencies = StubLocale::getCurrenciesData('pt_BR');
  54. }
  55. public function testGetCurrenciesData()
  56. {
  57. $currencies = StubLocale::getCurrenciesData('en');
  58. $this->assertEquals('R$', $currencies['BRL']['symbol']);
  59. $this->assertEquals('Brazilian Real', $currencies['BRL']['name']);
  60. $this->assertEquals(2, $currencies['BRL']['fractionDigits']);
  61. $this->assertEquals(0, $currencies['BRL']['roundingIncrement']);
  62. }
  63. public function testGetDisplayCurrencies()
  64. {
  65. $currencies = StubLocale::getDisplayCurrencies('en');
  66. $this->assertEquals('Brazilian Real', $currencies['BRL']);
  67. // Checking that the cache is being used
  68. $currencies = StubLocale::getDisplayCurrencies('en');
  69. $this->assertEquals('Argentine Peso', $currencies['ARS']);
  70. }
  71. public function testGetCurrencies()
  72. {
  73. $currencies = StubLocale::getCurrencies();
  74. $this->assertTrue(in_array('BRL', $currencies));
  75. }
  76. /**
  77. * @expectedException InvalidArgumentException
  78. */
  79. public function testGetDisplayLocalesWithUnsupportedLocale()
  80. {
  81. $locales = StubLocale::getDisplayLocales('pt');
  82. }
  83. public function testGetDisplayLocales()
  84. {
  85. $locales = StubLocale::getDisplayLocales('en');
  86. $this->assertEquals('Portuguese', $locales['pt']);
  87. }
  88. public function testGetLocales()
  89. {
  90. $locales = StubLocale::getLocales();
  91. $this->assertTrue(in_array('pt', $locales));
  92. }
  93. /**
  94. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  95. */
  96. public function testAcceptFromHttp()
  97. {
  98. StubLocale::acceptFromHttp('pt-br,en-us;q=0.7,en;q=0.5');
  99. }
  100. /**
  101. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  102. */
  103. public function testComposeLocale()
  104. {
  105. $subtags = array(
  106. 'language' => 'pt',
  107. 'script' => 'Latn',
  108. 'region' => 'BR'
  109. );
  110. StubLocale::composeLocale($subtags);
  111. }
  112. /**
  113. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  114. */
  115. public function testFilterMatches()
  116. {
  117. StubLocale::filterMatches('pt-BR', 'pt-BR');
  118. }
  119. /**
  120. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  121. */
  122. public function testGetAllVariants()
  123. {
  124. StubLocale::getAllVariants('pt_BR_Latn');
  125. }
  126. public function testGetDefault()
  127. {
  128. $this->assertEquals('en', StubLocale::getDefault());
  129. }
  130. /**
  131. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  132. */
  133. public function testGetDisplayLanguage()
  134. {
  135. StubLocale::getDisplayLanguage('pt-Latn-BR', 'en');
  136. }
  137. /**
  138. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  139. */
  140. public function testGetDisplayName()
  141. {
  142. StubLocale::getDisplayName('pt-Latn-BR', 'en');
  143. }
  144. /**
  145. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  146. */
  147. public function testGetDisplayRegion()
  148. {
  149. StubLocale::getDisplayRegion('pt-Latn-BR', 'en');
  150. }
  151. /**
  152. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  153. */
  154. public function testGetDisplayScript()
  155. {
  156. StubLocale::getDisplayScript('pt-Latn-BR', 'en');
  157. }
  158. /**
  159. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  160. */
  161. public function testGetDisplayVariant()
  162. {
  163. StubLocale::getDisplayVariant('pt-Latn-BR', 'en');
  164. }
  165. /**
  166. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  167. */
  168. public function testGetKeywords()
  169. {
  170. StubLocale::getKeywords('pt-BR@currency=BRL');
  171. }
  172. /**
  173. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  174. */
  175. public function testGetPrimaryLanguage()
  176. {
  177. StubLocale::getPrimaryLanguage('pt-Latn-BR');
  178. }
  179. /**
  180. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  181. */
  182. public function testGetRegion()
  183. {
  184. StubLocale::getRegion('pt-Latn-BR');
  185. }
  186. /**
  187. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  188. */
  189. public function testGetScript()
  190. {
  191. StubLocale::getScript('pt-Latn-BR');
  192. }
  193. /**
  194. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  195. */
  196. public function testLookup()
  197. {
  198. $langtag = array(
  199. 'pt-Latn-BR',
  200. 'pt-BR'
  201. );
  202. StubLocale::lookup($langtag, 'pt-BR-x-priv1');
  203. }
  204. /**
  205. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  206. */
  207. public function testParseLocale()
  208. {
  209. StubLocale::parseLocale('pt-Latn-BR');
  210. }
  211. /**
  212. * @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
  213. */
  214. public function testSetDefault()
  215. {
  216. StubLocale::setDefault('pt_BR');
  217. }
  218. }