diff options
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php')
-rw-r--r-- | vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php new file mode 100644 index 00000000..96031fc7 --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php | |||
@@ -0,0 +1,197 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Component\Intl\Tests\ResourceBundle; | ||
13 | |||
14 | use Symfony\Component\Intl\ResourceBundle\LanguageBundle; | ||
15 | |||
16 | /** | ||
17 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
18 | */ | ||
19 | class LanguageBundleTest extends \PHPUnit_Framework_TestCase | ||
20 | { | ||
21 | const RES_DIR = '/base/lang'; | ||
22 | |||
23 | /** | ||
24 | * @var LanguageBundle | ||
25 | */ | ||
26 | private $bundle; | ||
27 | |||
28 | /** | ||
29 | * @var \PHPUnit_Framework_MockObject_MockObject | ||
30 | */ | ||
31 | private $reader; | ||
32 | |||
33 | protected function setUp() | ||
34 | { | ||
35 | $this->reader = $this->getMock('Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReaderInterface'); | ||
36 | $this->bundle = new LanguageBundle(self::RES_DIR, $this->reader); | ||
37 | } | ||
38 | |||
39 | public function testGetLanguageName() | ||
40 | { | ||
41 | $languages = array( | ||
42 | 'de' => 'German', | ||
43 | 'en' => 'English', | ||
44 | ); | ||
45 | |||
46 | $this->reader->expects($this->once()) | ||
47 | ->method('readEntry') | ||
48 | ->with(self::RES_DIR, 'en', array('Languages')) | ||
49 | ->will($this->returnValue($languages)); | ||
50 | |||
51 | $this->assertSame('German', $this->bundle->getLanguageName('de', null, 'en')); | ||
52 | } | ||
53 | |||
54 | public function testGetLanguageNameWithRegion() | ||
55 | { | ||
56 | $languages = array( | ||
57 | 'de' => 'German', | ||
58 | 'en' => 'English', | ||
59 | 'en_GB' => 'British English', | ||
60 | ); | ||
61 | |||
62 | $this->reader->expects($this->once()) | ||
63 | ->method('readEntry') | ||
64 | ->with(self::RES_DIR, 'en', array('Languages')) | ||
65 | ->will($this->returnValue($languages)); | ||
66 | |||
67 | $this->assertSame('British English', $this->bundle->getLanguageName('en', 'GB', 'en')); | ||
68 | } | ||
69 | |||
70 | public function testGetLanguageNameWithUntranslatedRegion() | ||
71 | { | ||
72 | $languages = array( | ||
73 | 'de' => 'German', | ||
74 | 'en' => 'English', | ||
75 | ); | ||
76 | |||
77 | $this->reader->expects($this->once()) | ||
78 | ->method('readEntry') | ||
79 | ->with(self::RES_DIR, 'en', array('Languages')) | ||
80 | ->will($this->returnValue($languages)); | ||
81 | |||
82 | $this->assertSame('English', $this->bundle->getLanguageName('en', 'US', 'en')); | ||
83 | } | ||
84 | |||
85 | public function testGetLanguageNames() | ||
86 | { | ||
87 | $sortedLanguages = array( | ||
88 | 'en' => 'English', | ||
89 | 'de' => 'German', | ||
90 | ); | ||
91 | |||
92 | $this->reader->expects($this->once()) | ||
93 | ->method('readEntry') | ||
94 | ->with(self::RES_DIR, 'en', array('Languages')) | ||
95 | ->will($this->returnValue($sortedLanguages)); | ||
96 | |||
97 | $this->assertSame($sortedLanguages, $this->bundle->getLanguageNames('en')); | ||
98 | } | ||
99 | |||
100 | public function testGetScriptName() | ||
101 | { | ||
102 | $data = array( | ||
103 | 'Languages' => array( | ||
104 | 'de' => 'German', | ||
105 | 'en' => 'English', | ||
106 | ), | ||
107 | 'Scripts' => array( | ||
108 | 'Latn' => 'latin', | ||
109 | 'Cyrl' => 'cyrillique', | ||
110 | ), | ||
111 | ); | ||
112 | |||
113 | $this->reader->expects($this->once()) | ||
114 | ->method('read') | ||
115 | ->with(self::RES_DIR, 'en') | ||
116 | ->will($this->returnValue($data)); | ||
117 | |||
118 | $this->assertSame('latin', $this->bundle->getScriptName('Latn', null, 'en')); | ||
119 | } | ||
120 | |||
121 | public function testGetScriptNameIncludedInLanguage() | ||
122 | { | ||
123 | $data = array( | ||
124 | 'Languages' => array( | ||
125 | 'de' => 'German', | ||
126 | 'en' => 'English', | ||
127 | 'zh_Hans' => 'Simplified Chinese', | ||
128 | ), | ||
129 | 'Scripts' => array( | ||
130 | 'Latn' => 'latin', | ||
131 | 'Cyrl' => 'cyrillique', | ||
132 | ), | ||
133 | ); | ||
134 | |||
135 | $this->reader->expects($this->once()) | ||
136 | ->method('read') | ||
137 | ->with(self::RES_DIR, 'en') | ||
138 | ->will($this->returnValue($data)); | ||
139 | |||
140 | // Null because the script is included in the language anyway | ||
141 | $this->assertNull($this->bundle->getScriptName('Hans', 'zh', 'en')); | ||
142 | } | ||
143 | |||
144 | public function testGetScriptNameIncludedInLanguageInBraces() | ||
145 | { | ||
146 | $data = array( | ||
147 | 'Languages' => array( | ||
148 | 'de' => 'German', | ||
149 | 'en' => 'English', | ||
150 | 'zh_Hans' => 'Chinese (simplified)', | ||
151 | ), | ||
152 | 'Scripts' => array( | ||
153 | 'Latn' => 'latin', | ||
154 | 'Cyrl' => 'cyrillique', | ||
155 | ), | ||
156 | ); | ||
157 | |||
158 | $this->reader->expects($this->once()) | ||
159 | ->method('read') | ||
160 | ->with(self::RES_DIR, 'en') | ||
161 | ->will($this->returnValue($data)); | ||
162 | |||
163 | $this->assertSame('simplified', $this->bundle->getScriptName('Hans', 'zh', 'en')); | ||
164 | } | ||
165 | |||
166 | public function testGetScriptNameNoScriptsBlock() | ||
167 | { | ||
168 | $data = array( | ||
169 | 'Languages' => array( | ||
170 | 'de' => 'German', | ||
171 | 'en' => 'English', | ||
172 | ), | ||
173 | ); | ||
174 | |||
175 | $this->reader->expects($this->once()) | ||
176 | ->method('read') | ||
177 | ->with(self::RES_DIR, 'en') | ||
178 | ->will($this->returnValue($data)); | ||
179 | |||
180 | $this->assertNull($this->bundle->getScriptName('Latn', null, 'en')); | ||
181 | } | ||
182 | |||
183 | public function testGetScriptNames() | ||
184 | { | ||
185 | $sortedScripts = array( | ||
186 | 'Cyrl' => 'cyrillique', | ||
187 | 'Latn' => 'latin', | ||
188 | ); | ||
189 | |||
190 | $this->reader->expects($this->once()) | ||
191 | ->method('readEntry') | ||
192 | ->with(self::RES_DIR, 'en', array('Scripts')) | ||
193 | ->will($this->returnValue($sortedScripts)); | ||
194 | |||
195 | $this->assertSame($sortedScripts, $this->bundle->getScriptNames('en')); | ||
196 | } | ||
197 | } | ||