4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\Tests\ResourceBundle
;
14 use Symfony\Component\Intl\ResourceBundle\LanguageBundle
;
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 class LanguageBundleTest
extends \PHPUnit_Framework_TestCase
21 const RES_DIR
= '/base/lang';
29 * @var \PHPUnit_Framework_MockObject_MockObject
33 protected function setUp()
35 $this->reader
= $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface');
36 $this->bundle
= new LanguageBundle(self
::RES_DIR
, $this->reader
);
39 public function testGetLanguageName()
46 $this->reader
->expects($this->once())
48 ->with(self
::RES_DIR
, 'en', array('Languages'))
49 ->will($this->returnValue($languages));
51 $this->assertSame('German', $this->bundle
->getLanguageName('de', null, 'en'));
54 public function testGetLanguageNameWithRegion()
59 'en_GB' => 'British English',
62 $this->reader
->expects($this->once())
64 ->with(self
::RES_DIR
, 'en', array('Languages'))
65 ->will($this->returnValue($languages));
67 $this->assertSame('British English', $this->bundle
->getLanguageName('en', 'GB', 'en'));
70 public function testGetLanguageNameWithUntranslatedRegion()
77 $this->reader
->expects($this->once())
79 ->with(self
::RES_DIR
, 'en', array('Languages'))
80 ->will($this->returnValue($languages));
82 $this->assertSame('English', $this->bundle
->getLanguageName('en', 'US', 'en'));
85 public function testGetLanguageNames()
87 $sortedLanguages = array(
92 $this->reader
->expects($this->once())
94 ->with(self
::RES_DIR
, 'en', array('Languages'))
95 ->will($this->returnValue($sortedLanguages));
97 $this->assertSame($sortedLanguages, $this->bundle
->getLanguageNames('en'));
100 public function testGetScriptName()
103 'Languages' => array(
109 'Cyrl' => 'cyrillique',
113 $this->reader
->expects($this->once())
115 ->with(self
::RES_DIR
, 'en')
116 ->will($this->returnValue($data));
118 $this->assertSame('latin', $this->bundle
->getScriptName('Latn', null, 'en'));
121 public function testGetScriptNameIncludedInLanguage()
124 'Languages' => array(
127 'zh_Hans' => 'Simplified Chinese',
131 'Cyrl' => 'cyrillique',
135 $this->reader
->expects($this->once())
137 ->with(self
::RES_DIR
, 'en')
138 ->will($this->returnValue($data));
140 // Null because the script is included in the language anyway
141 $this->assertNull($this->bundle
->getScriptName('Hans', 'zh', 'en'));
144 public function testGetScriptNameIncludedInLanguageInBraces()
147 'Languages' => array(
150 'zh_Hans' => 'Chinese (simplified)',
154 'Cyrl' => 'cyrillique',
158 $this->reader
->expects($this->once())
160 ->with(self
::RES_DIR
, 'en')
161 ->will($this->returnValue($data));
163 $this->assertSame('simplified', $this->bundle
->getScriptName('Hans', 'zh', 'en'));
166 public function testGetScriptNameNoScriptsBlock()
169 'Languages' => array(
175 $this->reader
->expects($this->once())
177 ->with(self
::RES_DIR
, 'en')
178 ->will($this->returnValue($data));
180 $this->assertNull($this->bundle
->getScriptName('Latn', null, 'en'));
183 public function testGetScriptNames()
185 $sortedScripts = array(
186 'Cyrl' => 'cyrillique',
190 $this->reader
->expects($this->once())
191 ->method('readEntry')
192 ->with(self
::RES_DIR
, 'en', array('Scripts'))
193 ->will($this->returnValue($sortedScripts));
195 $this->assertSame($sortedScripts, $this->bundle
->getScriptNames('en'));