@@ -44,24 +44,36 @@ class TranslatedListsTest extends TestCase
4444 * @var array
4545 */
4646 private $ expectedLocales = [
47- 'en_US ' => ' English (United States) ' ,
48- 'en_GB ' => ' English (United Kingdom) ' ,
49- 'uk_UA ' => ' Ukrainian (Ukraine) ' ,
50- 'de_DE ' => ' German (Germany) ' ,
51- 'sr_Cyrl_RS ' => ' Serbian (Cyrillic, Serbia) ' ,
52- 'sr_Latn_RS ' => ' Serbian (Latin, Serbia) '
47+ 'en_US ' ,
48+ 'en_GB ' ,
49+ 'uk_UA ' ,
50+ 'de_DE ' ,
51+ 'sr_Cyrl_RS ' ,
52+ 'sr_Latn_RS '
5353 ];
5454
5555 /**
56- * @var array
56+ * @var string[]
57+ */
58+ private $ languages = [
59+ 'en_US ' => 'English ' ,
60+ 'en_GB ' => 'English ' ,
61+ 'uk_UA ' => 'Ukrainian ' ,
62+ 'de_DE ' => 'German ' ,
63+ 'sr_Cyrl_RS ' => 'Serbian ' ,
64+ 'sr_Latn_RS ' => 'Serbian '
65+ ];
66+
67+ /**
68+ * @var string[]
5769 */
58- private $ expectedTranslatedLocales = [
59- 'en_US ' => 'English ( United States) / English (United States) ' ,
60- 'en_GB ' => 'English ( United Kingdom) / English (United Kingdom) ' ,
61- 'uk_UA ' => 'українська (Україна) / Ukrainian ( Ukraine) ' ,
62- 'de_DE ' => 'Deutsch (Deutschland) / German ( Germany) ' ,
63- 'sr_Cyrl_RS ' => 'српски (ћирилица, Србија) / Serbian (Cyrillic, Serbia) ' ,
64- 'sr_Latn_RS ' => 'Srpski (latinica, Srbija) / Serbian (Latin, Serbia) '
70+ private $ countries = [
71+ 'en_US ' => 'United States ' ,
72+ 'en_GB ' => 'United Kingdom ' ,
73+ 'uk_UA ' => 'Ukraine ' ,
74+ 'de_DE ' => 'Germany ' ,
75+ 'sr_Cyrl_RS ' => 'Serbia ' ,
76+ 'sr_Latn_RS ' => 'Serbia '
6577 ];
6678
6779 protected function setUp ()
@@ -168,20 +180,22 @@ public function testGetOptionTimezones()
168180
169181 public function testGetOptionLocales ()
170182 {
183+ $ expected = $ this ->getExpectedLocales ();
171184 $ locales = array_intersect (
172- $ this -> expectedLocales ,
185+ $ expected ,
173186 $ this ->convertOptionLocales ($ this ->listsModel ->getOptionLocales ())
174187 );
175- $ this ->assertEquals ($ this -> expectedLocales , $ locales );
188+ $ this ->assertEquals ($ expected , $ locales );
176189 }
177190
178191 public function testGetTranslatedOptionLocales ()
179192 {
193+ $ expected = $ this ->getExpectedTranslatedLocales ();
180194 $ locales = array_intersect (
181- $ this -> expectedTranslatedLocales ,
195+ $ expected ,
182196 $ this ->convertOptionLocales ($ this ->listsModel ->getTranslatedOptionLocales ())
183197 );
184- $ this ->assertEquals ($ this -> expectedTranslatedLocales , $ locales );
198+ $ this ->assertEquals ($ expected , $ locales );
185199 }
186200
187201 /**
@@ -198,4 +212,42 @@ private function convertOptionLocales($optionLocales): array
198212
199213 return $ result ;
200214 }
215+
216+ /**
217+ * Expected translated locales list.
218+ *
219+ * @return string[]
220+ */
221+ private function getExpectedTranslatedLocales (): array
222+ {
223+ $ expected = [];
224+ foreach ($ this ->expectedLocales as $ locale ) {
225+ $ script = \Locale::getDisplayScript ($ locale );
226+ $ scriptTranslated = $ script ? \Locale::getDisplayScript ($ locale , $ locale ) .', ' : '' ;
227+ $ expected [$ locale ] = ucwords (\Locale::getDisplayLanguage ($ locale , $ locale ))
228+ . ' ( ' . $ scriptTranslated
229+ . \Locale::getDisplayRegion ($ locale , $ locale ) . ') / '
230+ . $ this ->languages [$ locale ]
231+ . ' ( ' . ($ script ? $ script .', ' : '' ) . $ this ->countries [$ locale ] . ') ' ;
232+ }
233+
234+ return $ expected ;
235+ }
236+
237+ /**
238+ * Expected locales list.
239+ *
240+ * @return string[]
241+ */
242+ private function getExpectedLocales (): array
243+ {
244+ $ expected = [];
245+ foreach ($ this ->expectedLocales as $ locale ) {
246+ $ script = \Locale::getScript ($ locale );
247+ $ scriptDisplayed = $ script ? \Locale::getDisplayScript ($ locale ) . ', ' : '' ;
248+ $ expected [$ locale ] = $ this ->languages [$ locale ] .' ( ' .$ scriptDisplayed .$ this ->countries [$ locale ] .') ' ;
249+ }
250+
251+ return $ expected ;
252+ }
201253}
0 commit comments