2 require_once 'include/Localization/Localization.php';
4 class LocalizationTest extends Sugar_PHPUnit_Framework_TestCase
6 public function setUp()
8 $this->_locale = new Localization();
9 $this->_user = SugarTestUserUtilities::createAnonymousUser();
12 public function tearDown()
14 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
17 public function providerGetLocaleFormattedName()
41 * @dataProvider providerGetLocaleFormattedName
43 public function testGetLocaleFormattedNameUsingFormatInUserPreference($nameFormat,$firstName,$lastName,$salutation,$title,$expectedOutput)
45 $this->_user->setPreference('default_locale_name_format', $nameFormat);
46 $outputName = $this->_locale->getLocaleFormattedName($firstName, $lastName, $salutation, $title, '',$this->_user);
47 $this->assertEquals($expectedOutput, $outputName);
51 * @dataProvider providerGetLocaleFormattedName
53 public function testGetLocaleFormattedNameUsingFormatSpecified($nameFormat,$firstName,$lastName,$salutation,$title,$expectedOutput)
55 $outputName = $this->_locale->getLocaleFormattedName($firstName, $lastName, $salutation, $title, $nameFormat,$this->_user);
56 $this->assertEquals($expectedOutput, $outputName);
62 public function testGetLocaleFormattedNameWhenNameIsEmpty()
64 $this->_user->setPreference('default_locale_name_format', 'l f');
65 $expectedOutput = ' ';
66 $outputName = $this->_locale->getLocaleFormattedName('', '', '', '', '',$this->_user);
68 $this->assertEquals($expectedOutput, $outputName);
74 public function testGetLocaleFormattedNameWhenNameIsEmptyAndReturningEmptyString()
76 $this->_user->setPreference('default_locale_name_format', 'l f');
78 $outputName = $this->_locale->getLocaleFormattedName('', '', '', '', '',$this->_user,true);
80 $this->assertEquals($expectedOutput, $outputName);
83 public function testCurrenciesLoadingCorrectly()
87 $currencies = $this->_locale->getCurrencies();
89 $this->assertEquals($currencies['-99']['name'],$sugar_config['default_currency_name']);
90 $this->assertEquals($currencies['-99']['symbol'],$sugar_config['default_currency_symbol']);
91 $this->assertEquals($currencies['-99']['conversion_rate'],1);
94 public function testConvertingUnicodeStringBetweenCharsets()
96 $string = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド";
98 $convertedString = $this->_locale->translateCharset($string,'UTF-8','EUC-CN');
99 $this->assertNotEquals($string,$convertedString);
101 // test for this working by being able to convert back and the string match
102 $convertedString = $this->_locale->translateCharset($convertedString,'EUC-CN','UTF-8');
103 $this->assertEquals($string,$convertedString);
106 public function testCanDetectAsciiEncoding()
111 $this->_locale->detectCharset($string),
116 public function testCanDetectUtf8Encoding()
118 $string = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド';
121 $this->_locale->detectCharset($string),
126 public function testGetNameJsCorrectlySpecifiesMissingOrEmptyParameters()
130 $app_strings = return_application_language($GLOBALS['current_language']);
137 $ret = $this->_locale->getNameJs($first,$last,$salutation);
139 $this->assertRegExp("/stuff\['s'\] = '$salutation';/",$ret);
140 $this->assertRegExp("/stuff\['f'\] = '$first';/",$ret);
141 $this->assertRegExp("/stuff\['l'\] = '$last';/",$ret);
142 $this->assertRegExp("/stuff\['t'\] = '{$app_strings['LBL_LOCALE_NAME_EXAMPLE_TITLE']}';/",$ret);
144 $ret = $this->_locale->getNameJs('',$last,$salutation);
146 $this->assertRegExp("/stuff\['s'\] = '$salutation';/",$ret);
147 $this->assertRegExp("/stuff\['f'\] = '{$app_strings['LBL_LOCALE_NAME_EXAMPLE_FIRST']}';/",$ret);
148 $this->assertRegExp("/stuff\['l'\] = '$last';/",$ret);
149 $this->assertRegExp("/stuff\['t'\] = '{$app_strings['LBL_LOCALE_NAME_EXAMPLE_TITLE']}';/",$ret);
152 public function testGetPrecedentPreferenceWithUserPreference()
154 $backup = $GLOBALS['sugar_config']['export_delimiter'];
155 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
156 $this->_user->setPreference('export_delimiter','John is Really Cool');
159 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
160 $this->_user->getPreference('export_delimiter')
163 $GLOBALS['sugar_config']['export_delimiter'] = $backup;
166 public function testGetPrecedentPreferenceWithNoUserPreference()
168 $backup = $GLOBALS['sugar_config']['export_delimiter'];
169 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
172 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
173 $GLOBALS['sugar_config']['export_delimiter']
176 $GLOBALS['sugar_config']['export_delimiter'] = $backup;
182 public function testGetPrecedentPreferenceWithUserPreferenceAndSpecifiedConfigKey()
184 $backup = $GLOBALS['sugar_config']['export_delimiter'];
185 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
186 $this->_user->setPreference('export_delimiter','');
187 $GLOBALS['sugar_config']['default_random_setting_for_localization_test'] = 'John is not Cool at all';
190 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user,'default_random_setting_for_localization_test'),
191 $GLOBALS['sugar_config']['default_random_setting_for_localization_test']
194 $backup = $GLOBALS['sugar_config']['export_delimiter'];
195 unset($GLOBALS['sugar_config']['default_random_setting_for_localization_test']);
201 public function testGetPrecedentPreferenceForDefaultEmailCharset()
203 $emailSettings = array('defaultOutboundCharset' => 'something fun');
204 $this->_user->setPreference('emailSettings',$emailSettings, 0, 'Emails');
207 $this->_locale->getPrecedentPreference('default_email_charset',$this->_user),
208 $emailSettings['defaultOutboundCharset']