3 defined('AK_TEST_DATABASE_ON') ?
null : define('AK_TEST_DATABASE_ON', true);
4 require_once(dirname(__FILE__
).'/../../fixtures/config/config.php');
6 require_once(AK_LIB_DIR
.DS
.'AkLocaleManager.php');
8 class Test_of_AkLocaleManager_Class
extends AkUnitTest
15 $this->LocaleManager
=& new AkLocaleManager();
20 unset ($this->LocaleManager
);
23 function Test_of__getAvailableLocales()
25 $available_locales = $this->LocaleManager
->_getAvailableLocales();
26 $this->assertTrue(is_array($available_locales['en']) && count($available_locales) > 0 ,'Locale en was not found on config/locales folder.');
29 function Test_of__parseLocaleConfigString()
32 $config_string = 'en';
33 $expected = array('en'=>array('en'));
34 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
35 $this->assertEqual($expected, $result);
37 $config_string = 'en,es ';
38 $expected = array('en'=>array('en'),'es'=>array('es'));
39 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
40 $this->assertEqual($expected, $result);
42 $config_string = 'en; es';
43 $expected = array('en'=>array('en'),'es'=>array('es'));
44 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
45 $this->assertEqual($expected, $result);
47 $config_string = 'en; es (spain)';
48 $expected = array('en'=>array('en'),'es'=>array('es','spain'));
49 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
50 $this->assertEqual($expected, $result);
52 $config_string = 'en; es (spain|espana)';
53 $expected = array('en'=>array('en'),'es'=>array('es','spain', 'espana'));
54 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
55 $this->assertEqual($expected, $result);
57 $config_string = 'es (spain)';
58 $expected = array('es'=>array('es','spain'));
59 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
60 $this->assertEqual($expected, $result);
62 $config_string = 'es (spain|espana)';
63 $expected = array('es'=>array('es','spain', 'espana'));
64 $result = $this->LocaleManager
->_parseLocaleConfigString($config_string);
65 $this->assertEqual($expected, $result);
72 function Test_of_getBrowserLanguages()
74 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->LocaleManager
->_browser_language
= 'en-us,en,es-es;q=0.5;';
76 $this->LocaleManager
->available_locales
= array('en_us'=>'en_us','en'=>'en','es_es'=>'es_es');
77 $expected = array_keys($this->LocaleManager
->available_locales
);
78 $result = $this->LocaleManager
->getBrowserLanguages();
79 $this->assertEqual($expected, $result);
81 unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
82 $this->LocaleManager
->available_locales
= array('en'=>'en');
83 $expected = array_keys($this->LocaleManager
->available_locales
);
84 $result = $this->LocaleManager
->getBrowserLanguages();
85 $this->assertEqual($expected, $result);
87 $this->LocaleManager
->available_locales
= array('en_us'=>'en_us');
88 $expected = array_keys($this->LocaleManager
->available_locales
);
89 $result = $this->LocaleManager
->getBrowserLanguages();
90 $this->assertEqual($expected, $result);
95 function Test_of_getDefaultLanguageForUser()
97 unset($_SERVER['HTTP_ACCEPT_LANGUAGE']);
98 $this->LocaleManager
->available_locales
= array('en_us'=>array('en_us'),'en'=>array('en'),'es_es'=>array('es_es'));
99 $this->LocaleManager
->browser_lang
= $this->LocaleManager
->getBrowserLanguages();
100 $result = $this->LocaleManager
->getDefaultLanguageForUser();
102 $this->assertEqual($expected, $result);
104 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es-es,en-us,en;q=0.5;';
105 $this->LocaleManager
->available_locales
= array('en'=>array('en'),'en_us'=>array('en_us'),'es_es'=>array('es_es'));
106 $this->LocaleManager
->browser_lang
= $this->LocaleManager
->getBrowserLanguages();
107 $result = $this->LocaleManager
->getDefaultLanguageForUser();
109 $this->assertEqual($expected, $result);
111 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us,en;q=0.5;';
112 $this->LocaleManager
->available_locales
= array('es_es'=>array('es_es'));
113 $this->LocaleManager
->browser_lang
= $this->LocaleManager
->getBrowserLanguages();
114 $result = $this->LocaleManager
->getDefaultLanguageForUser();
116 $this->assertEqual($expected, $result);
120 function Test_of__getDefaultLocale()
122 $this->LocaleManager
->available_locales
= array('es_es'=>array('es_es'));
123 $result = $this->LocaleManager
->_getDefaultLocale();
125 $this->assertEqual($expected, $result);
127 $this->LocaleManager
->available_locales
= array('es_es'=>'es_es');
128 $result = $this->LocaleManager
->_getDefaultLocale();
130 $this->assertEqual($expected, $result);
132 $this->LocaleManager
->available_locales
= array('es_es');
133 $result = $this->LocaleManager
->_getDefaultLocale();
135 $this->assertEqual($expected, $result);
137 $this->LocaleManager
->available_locales
= array('en'=>array('en'),'es_es'=>array('es_es'));
138 $result = $this->LocaleManager
->_getDefaultLocale();
140 $this->assertEqual($expected, $result);
141 $result = $this->LocaleManager
->_getDefaultLocale();
143 $this->assertEqual($expected, $result);
148 function Test_of_getLangFromUrl()
150 $Request = new AkObject();
153 $Request->_request
['ak'] = 'en';
154 $this->LocaleManager
->available_locales
= array('en'=>array('en'),'es_es'=>array('es_es','spain'));
158 $result = $this->LocaleManager
->getLangFromUrl($Request);
159 $this->assertEqual($expected, $result);
160 $this->assertEqual($Request->_request
['ak'],'');
161 $this->assertEqual($Request->ak
,'');
163 $Request->ak
= '/en/';
164 $Request->_request
['ak'] = '/en/';
166 $result = $this->LocaleManager
->getLangFromUrl($Request);
167 $this->assertEqual($expected, $result);
168 $this->assertEqual($Request->_request
['ak'],'');
169 $this->assertEqual($Request->ak
,'');
171 $Request->ak
= 'en/post';
172 $Request->_request
['ak'] = 'en/post';
174 $result = $this->LocaleManager
->getLangFromUrl($Request);
175 $this->assertEqual($expected, $result);
177 $this->assertEqual($Request->_request
['ak'],'post');
178 $this->assertEqual($Request->ak
,'post');
180 $Request->ak
= 'fr/post';
181 $Request->_request
['ak'] = 'fr/post';
182 unset($Request->lang
);
184 $result = $this->LocaleManager
->getLangFromUrl($Request);
185 $this->assertFalse($result);
187 $this->assertEqual($Request->_request
['ak'],'fr/post');
188 $this->assertEqual($Request->ak
,'fr/post');
190 $Request->ak
= 'post/es_es';
191 $Request->_request
['ak'] = 'post/es_es';
192 unset($Request->lang
);
194 $result = $this->LocaleManager
->getLangFromUrl($Request);
195 $this->assertFalse($result);
197 $this->assertEqual($Request->_request
['ak'],'post/es_es');
198 $this->assertEqual($Request->ak
,'post/es_es');
200 $Request->ak
= 'es/post';
201 $Request->_request
['ak'] = 'es/post';
202 unset($Request->lang
);
204 $result = $this->LocaleManager
->getLangFromUrl($Request);
205 $this->assertFalse($result);
207 $this->assertEqual($Request->_request
['ak'],'es/post');
208 $this->assertEqual($Request->ak
,'es/post');
210 $Request->ak
= 'spain/people';
211 $Request->_request
['ak'] = 'spain/people';
212 unset($Request->lang
);
214 $result = $this->LocaleManager
->getLangFromUrl($Request);
216 $this->assertEqual($result, $expected);
218 $this->assertEqual($Request->_request
['ak'],'people');
219 $this->assertEqual($Request->ak
,'people');
221 //Falta devolver IDIOMA y no alias y cargar $request->lang
226 function Test_of_getLocaleFromAlias()
228 $this->LocaleManager
->available_locales
= $this->LocaleManager
->_parseLocaleConfigString('es, en, fr (france)');
229 $result = $this->LocaleManager
->getLocaleFromAlias('france');
231 $this->assertEqual($result,$expected);
233 $result = $this->LocaleManager
->getLocaleFromAlias('spain');
234 $this->assertFalse($result);
240 ak_test('Test_of_AkLocaleManager_Class');