IcuLanguageBundleTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Icu\Tests;
  11. use Symfony\Component\Icu\IcuData;
  12. use Symfony\Component\Icu\IcuLanguageBundle;
  13. /**
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class IcuLanguageBundleTest extends IcuTestCase
  17. {
  18. /**
  19. * @var string
  20. */
  21. private $resDir;
  22. /**
  23. * @var IcuLanguageBundle
  24. */
  25. private $bundle;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $reader;
  30. protected function setUp()
  31. {
  32. parent::setUp();
  33. $this->resDir = IcuData::getResourceDirectory() . '/lang';
  34. $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface');
  35. $this->bundle = new IcuLanguageBundle($this->reader);
  36. }
  37. public function testGetLanguageName()
  38. {
  39. $languages = array(
  40. 'de' => 'German',
  41. 'en' => 'English',
  42. );
  43. $this->reader->expects($this->once())
  44. ->method('readEntry')
  45. ->with($this->resDir, 'en', array('Languages'))
  46. ->will($this->returnValue($languages));
  47. $this->assertSame('German', $this->bundle->getLanguageName('de', null, 'en'));
  48. }
  49. public function testGetLanguageNameWithRegion()
  50. {
  51. $languages = array(
  52. 'de' => 'German',
  53. 'en' => 'English',
  54. 'en_GB' => 'British English',
  55. );
  56. $this->reader->expects($this->once())
  57. ->method('readEntry')
  58. ->with($this->resDir, 'en', array('Languages'))
  59. ->will($this->returnValue($languages));
  60. $this->assertSame('British English', $this->bundle->getLanguageName('en', 'GB', 'en'));
  61. }
  62. public function testGetLanguageNameWithUntranslatedRegion()
  63. {
  64. $languages = array(
  65. 'de' => 'German',
  66. 'en' => 'English',
  67. );
  68. $this->reader->expects($this->once())
  69. ->method('readEntry')
  70. ->with($this->resDir, 'en', array('Languages'))
  71. ->will($this->returnValue($languages));
  72. $this->assertSame('English', $this->bundle->getLanguageName('en', 'US', 'en'));
  73. }
  74. public function testGetLanguageNameForMultipleLanguages()
  75. {
  76. $this->reader->expects($this->never())
  77. ->method('readEntry');
  78. $this->assertNull($this->bundle->getLanguageName('mul', 'en'));
  79. }
  80. public function testGetLanguageNames()
  81. {
  82. $languages = array(
  83. 'mul' => 'Multiple Languages',
  84. 'de' => 'German',
  85. 'en' => 'English',
  86. );
  87. $this->reader->expects($this->once())
  88. ->method('readEntry')
  89. ->with($this->resDir, 'en', array('Languages'))
  90. ->will($this->returnValue($languages));
  91. $sortedLanguages = array(
  92. 'en' => 'English',
  93. 'de' => 'German',
  94. );
  95. $this->assertSame($sortedLanguages, $this->bundle->getLanguageNames('en'));
  96. }
  97. public function testGetScriptNames()
  98. {
  99. $scripts = array(
  100. 'Latn' => 'latin',
  101. 'Cyrl' => 'cyrillique',
  102. );
  103. $this->reader->expects($this->once())
  104. ->method('readEntry')
  105. ->with($this->resDir, 'en', array('Scripts'))
  106. ->will($this->returnValue($scripts));
  107. $sortedScripts = array(
  108. 'Cyrl' => 'cyrillique',
  109. 'Latn' => 'latin',
  110. );
  111. $this->assertSame($sortedScripts, $this->bundle->getScriptNames('en'));
  112. }
  113. }