Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPLocaleTest.php
1 <?php
2 
22 require_mock_env('env1');
23 
24 import('lib.pkp.tests.PKPTestCase');
25 import('lib.pkp.classes.i18n.PKPLocale');
26 
27 class PKPLocaleTest extends PKPTestCase {
31  public function testGetLocaleStylesheet() {
32  self::assertNull(AppLocale::getLocaleStyleSheet('en_US'));
33  self::assertEquals('pt.css', AppLocale::getLocaleStyleSheet('pt_BR'));
34  self::assertNull(AppLocale::getLocaleStyleSheet('xx_XX'));
35  }
36 
40  public function testIsLocaleComplete() {
41  self::assertTrue(AppLocale::isLocaleComplete('en_US'));
42  self::assertFalse(AppLocale::isLocaleComplete('pt_BR'));
43  self::assertFalse(AppLocale::isLocaleComplete('xx_XX'));
44  }
45 
49  public function testGetAllLocales() {
50  $expectedLocales = array(
51  'en_US' => 'English',
52  'pt_BR' => 'Portuguese (Brazil)',
53  'pt_PT' => 'Portuguese (Portugal)',
54  'de_DE' => 'German'
55  );
56  self::assertEquals($expectedLocales, AppLocale::getAllLocales());
57  }
58 
63  self::assertEquals('eng', AppLocale::get3LetterFrom2LetterIsoLanguage('en'));
64  self::assertEquals('por', AppLocale::get3LetterFrom2LetterIsoLanguage('pt'));
65  self::assertNull(AppLocale::get3LetterFrom2LetterIsoLanguage('xx'));
66  }
67 
72  self::assertEquals('en', AppLocale::get2LetterFrom3LetterIsoLanguage('eng'));
73  self::assertEquals('pt', AppLocale::get2LetterFrom3LetterIsoLanguage('por'));
74  self::assertNull(AppLocale::get2LetterFrom3LetterIsoLanguage('xxx'));
75  }
76 
80  public function testGet3LetterIsoFromLocale() {
81  self::assertEquals('eng', AppLocale::get3LetterIsoFromLocale('en_US'));
82  self::assertEquals('por', AppLocale::get3LetterIsoFromLocale('pt_BR'));
83  self::assertEquals('por', AppLocale::get3LetterIsoFromLocale('pt_PT'));
84  self::assertNull(AppLocale::get3LetterIsoFromLocale('xx_XX'));
85  }
86 
90  public function testGetLocaleFrom3LetterIso() {
91  // A locale that does not have to be disambiguated.
92  self::assertEquals('en_US', AppLocale::getLocaleFrom3LetterIso('eng'));
93 
94  // The primary locale will be used if that helps
95  // to disambiguate.
96  AppLocale::setSupportedLocales(array('en_US' => 'English', 'pt_BR' => 'Portuguese (Brazil)', 'pt_PT' => 'Portuguese (Portugal)'));
98  self::assertEquals('pt_BR', AppLocale::getLocaleFrom3LetterIso('por'));
100  self::assertEquals('pt_PT', AppLocale::getLocaleFrom3LetterIso('por'));
101 
102  // If the primary locale doesn't help then use the first supported locale found.
104  self::assertEquals('pt_BR', AppLocale::getLocaleFrom3LetterIso('por'));
105  AppLocale::setSupportedLocales(array('en_US' => 'English', 'pt_PT' => 'Portuguese (Portugal)', 'pt_BR' => 'Portuguese (Brazil)'));
106  self::assertEquals('pt_PT', AppLocale::getLocaleFrom3LetterIso('por'));
107 
108  // If the locale isn't even in the supported localse then use the first locale found.
109  AppLocale::setSupportedLocales(array('en_US' => 'English'));
110  self::assertEquals('pt_PT', AppLocale::getLocaleFrom3LetterIso('por'));
111 
112  // Unknown language.
113  self::assertNull(AppLocale::getLocaleFrom3LetterIso('xxx'));
114  }
115 }
116 ?>
static get3LetterFrom2LetterIsoLanguage($iso2Letter)
static get3LetterIsoFromLocale($locale)
static getLocaleFrom3LetterIso($iso3Letter)
static & getAllLocales()
static setSupportedLocales($supportedLocales)
testGetLocaleFrom3LetterIso()
static get2LetterFrom3LetterIsoLanguage($iso3Letter)
Tests for the PKPLocale class.
static isLocaleComplete($locale)
static getLocaleStyleSheet($locale)
testGet3LetterFrom2LetterIsoLanguage()
static setPrimaryLocale($primaryLocale)
testGet2LetterFrom3LetterIsoLanguage()
testGet3LetterIsoFromLocale()
Class that implements functionality common to all PKP unit test cases.