2 require_once('PHPUnit/Framework.php');
3 require_once('gettext.inc');
5 class LocaleTest extends PHPUnit_Framework_TestCase
7 public function test_setlocale()
9 // _setlocale defaults to a locale name from environment variable LANG.
11 $this->assertEquals('sr_RS', _setlocale(LC_MESSAGES, 0));
13 // For an existing locale, it never needs emulation.
15 _setlocale(LC_MESSAGES, "");
16 $this->assertEquals(0, locale_emulation());
18 // If we set it to a non-existent locale, it still works, but uses
20 _setlocale(LC_MESSAGES, "xxx_XXX");
21 $this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
22 $this->assertEquals(1, locale_emulation());
25 public function test_get_list_of_locales()
27 // For a locale containing country code, we prefer
28 // full locale name, but if that's not found, fall back
29 // to the language only locale name.
30 $this->assertEquals(array("sr_RS", "sr"),
31 get_list_of_locales("sr_RS"));
33 // If language code is used, it's the only thing returned.
34 $this->assertEquals(array("sr"),
35 get_list_of_locales("sr"));
37 // There is support for language and charset only.
38 $this->assertEquals(array("sr.UTF-8", "sr"),
39 get_list_of_locales("sr.UTF-8"));
41 // It can also split out character set from the full locale name.
42 $this->assertEquals(array("sr_RS.UTF-8", "sr_RS", "sr"),
43 get_list_of_locales("sr_RS.UTF-8"));
45 // There is support for @modifier in locale names as well.
46 $this->assertEquals(array("sr_RS.UTF-8@latin", "sr_RS@latin", "sr@latin",
47 "sr_RS.UTF-8", "sr_RS", "sr"),
48 get_list_of_locales("sr_RS.UTF-8@latin"));
50 // We can pass in only language and modifier.
51 $this->assertEquals(array("sr@latin", "sr"),
52 get_list_of_locales("sr@latin"));
55 // If locale name is not following the regular POSIX pattern,
56 // it's used verbatim.
57 $this->assertEquals(array("something"),
58 get_list_of_locales("something"));
60 // Passing in an empty string returns an empty array.
61 $this->assertEquals(array(),
62 get_list_of_locales(""));