commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / PHPgettext / tests / LocalesTest.php
1 <?php
2 require_once('PHPUnit/Framework.php');
3 require_once('gettext.inc');
4
5 class LocaleTest extends PHPUnit_Framework_TestCase
6 {
7 public function test_setlocale()
8 {
9 // _setlocale defaults to a locale name from environment variable LANG.
10 putenv("LANG=sr_RS");
11 $this->assertEquals('sr_RS', _setlocale(LC_MESSAGES, 0));
12
13 // For an existing locale, it never needs emulation.
14 putenv("LANG=C");
15 _setlocale(LC_MESSAGES, "");
16 $this->assertEquals(0, locale_emulation());
17
18 // If we set it to a non-existent locale, it still works, but uses
19 // emulation.
20 _setlocale(LC_MESSAGES, "xxx_XXX");
21 $this->assertEquals('xxx_XXX', _setlocale(LC_MESSAGES, 0));
22 $this->assertEquals(1, locale_emulation());
23 }
24
25 public function test_get_list_of_locales()
26 {
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"));
32
33 // If language code is used, it's the only thing returned.
34 $this->assertEquals(array("sr"),
35 get_list_of_locales("sr"));
36
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"));
40
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"));
44
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"));
49
50 // We can pass in only language and modifier.
51 $this->assertEquals(array("sr@latin", "sr"),
52 get_list_of_locales("sr@latin"));
53
54
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"));
59
60 // Passing in an empty string returns an empty array.
61 $this->assertEquals(array(),
62 get_list_of_locales(""));
63 }
64 }
65
66 ?>