Add a test for the localize function. re #96
This commit is contained in:
		
							父節點
							
								
									3be4fce3a5
								
							
						
					
					
						當前提交
						9c09b8797c
					
				
					共有  2 個文件被更改,包括 27 次插入 和 1 次删除
				
			
		
							
								
								
									
										5
									
								
								base.php
									
										
									
									
									
								
							
							
						
						
									
										5
									
								
								base.php
									
										
									
									
									
								
							|  | @ -139,7 +139,7 @@ function str_format($format) { | |||
|  * This method is based on this page | ||||
|  * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/ | ||||
|  */ | ||||
| function localize($phrase, $count=-1) { | ||||
| function localize($phrase, $count=-1, $reset=false) { | ||||
|     if ($count == 0) | ||||
|         $phrase .= ".none"; | ||||
|     if ($count == 1) | ||||
|  | @ -149,6 +149,9 @@ function localize($phrase, $count=-1) { | |||
| 
 | ||||
|     /* Static keyword is used to ensure the file is loaded only once */ | ||||
|     static $translations = NULL; | ||||
|     if ($reset) { | ||||
|         $translations = NULL; | ||||
|     } | ||||
|     /* If no instance of $translations has occured load the language file */ | ||||
|     if (is_null($translations)) { | ||||
|         $lang = "en"; | ||||
|  |  | |||
|  | @ -11,4 +11,27 @@ class BaseTest extends PHPUnit_Framework_TestCase | |||
|         $this->assertEquals ("?key=value&db=0", addURLParameter ("?key=value", "db", "0")); | ||||
|         $this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0")); | ||||
|     } | ||||
|      | ||||
|     public function testLocalize () | ||||
|     { | ||||
|         $this->assertEquals ("Authors", localize ("authors.title")); | ||||
|     } | ||||
|      | ||||
|     public function testLocalizeFr () | ||||
|     { | ||||
|         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3"; | ||||
|         $this->assertEquals ("Auteurs", localize ("authors.title", -1, true)); | ||||
|          | ||||
|         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; | ||||
|         localize ("authors.title", -1, true); | ||||
|     } | ||||
|      | ||||
|     public function testLocalizeUnknown () | ||||
|     { | ||||
|         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "aa"; | ||||
|         $this->assertEquals ("Authors", localize ("authors.title", -1, true)); | ||||
|          | ||||
|         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; | ||||
|         localize ("authors.title", -1, true); | ||||
|     } | ||||
| } | ||||
		載入中…
	
	Add table
		Add a link
		
	
		Reference in a new issue