2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 require_once 'include/Localization/Localization.php';
40 class LocalizationTest extends Sugar_PHPUnit_Framework_TestCase
42 public function setUp()
44 $this->_locale = new Localization();
45 $this->_user = SugarTestUserUtilities::createAnonymousUser();
48 public function tearDown()
50 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
53 public function providerGetLocaleFormattedName()
77 * @dataProvider providerGetLocaleFormattedName
79 public function testGetLocaleFormattedNameUsingFormatInUserPreference($nameFormat,$firstName,$lastName,$salutation,$title,$expectedOutput)
81 $this->_user->setPreference('default_locale_name_format', $nameFormat);
82 $outputName = $this->_locale->getLocaleFormattedName($firstName, $lastName, $salutation, $title, '',$this->_user);
83 $this->assertEquals($expectedOutput, $outputName);
87 * @dataProvider providerGetLocaleFormattedName
89 public function testGetLocaleFormattedNameUsingFormatSpecified($nameFormat,$firstName,$lastName,$salutation,$title,$expectedOutput)
91 $outputName = $this->_locale->getLocaleFormattedName($firstName, $lastName, $salutation, $title, $nameFormat,$this->_user);
92 $this->assertEquals($expectedOutput, $outputName);
98 public function testGetLocaleFormattedNameWhenNameIsEmpty()
100 $this->_user->setPreference('default_locale_name_format', 'l f');
101 $expectedOutput = ' ';
102 $outputName = $this->_locale->getLocaleFormattedName('', '', '', '', '',$this->_user);
104 $this->assertEquals($expectedOutput, $outputName);
110 public function testGetLocaleFormattedNameWhenNameIsEmptyAndReturningEmptyString()
112 $this->_user->setPreference('default_locale_name_format', 'l f');
113 $expectedOutput = '';
114 $outputName = $this->_locale->getLocaleFormattedName('', '', '', '', '',$this->_user,true);
116 $this->assertEquals($expectedOutput, $outputName);
119 public function testCurrenciesLoadingCorrectly()
121 global $sugar_config;
123 $currencies = $this->_locale->getCurrencies();
125 $this->assertEquals($currencies['-99']['name'],$sugar_config['default_currency_name']);
126 $this->assertEquals($currencies['-99']['symbol'],$sugar_config['default_currency_symbol']);
127 $this->assertEquals($currencies['-99']['conversion_rate'],1);
130 public function testConvertingUnicodeStringBetweenCharsets()
132 $string = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド";
134 $convertedString = $this->_locale->translateCharset($string,'UTF-8','EUC-CN');
135 $this->assertNotEquals($string,$convertedString);
137 // test for this working by being able to convert back and the string match
138 $convertedString = $this->_locale->translateCharset($convertedString,'EUC-CN','UTF-8');
139 $this->assertEquals($string,$convertedString);
142 public function testCanDetectAsciiEncoding()
147 $this->_locale->detectCharset($string),
152 public function testCanDetectUtf8Encoding()
154 $string = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド';
157 $this->_locale->detectCharset($string),
162 public function testGetNameJsCorrectlySpecifiesMissingOrEmptyParameters()
166 $app_strings = return_application_language($GLOBALS['current_language']);
173 $ret = $this->_locale->getNameJs($first,$last,$salutation);
175 $this->assertRegExp("/stuff\['s'\] = '$salutation';/",$ret);
176 $this->assertRegExp("/stuff\['f'\] = '$first';/",$ret);
177 $this->assertRegExp("/stuff\['l'\] = '$last';/",$ret);
178 $this->assertRegExp("/stuff\['t'\] = '{$app_strings['LBL_LOCALE_NAME_EXAMPLE_TITLE']}';/",$ret);
180 $ret = $this->_locale->getNameJs('',$last,$salutation);
182 $this->assertRegExp("/stuff\['s'\] = '$salutation';/",$ret);
183 $this->assertRegExp("/stuff\['f'\] = '{$app_strings['LBL_LOCALE_NAME_EXAMPLE_FIRST']}';/",$ret);
184 $this->assertRegExp("/stuff\['l'\] = '$last';/",$ret);
185 $this->assertRegExp("/stuff\['t'\] = '{$app_strings['LBL_LOCALE_NAME_EXAMPLE_TITLE']}';/",$ret);
188 public function testGetPrecedentPreferenceWithUserPreference()
190 $backup = $GLOBALS['sugar_config']['export_delimiter'];
191 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
192 $this->_user->setPreference('export_delimiter','John is Really Cool');
195 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
196 $this->_user->getPreference('export_delimiter')
199 $GLOBALS['sugar_config']['export_delimiter'] = $backup;
202 public function testGetPrecedentPreferenceWithNoUserPreference()
204 $backup = $GLOBALS['sugar_config']['export_delimiter'];
205 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
208 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
209 $GLOBALS['sugar_config']['export_delimiter']
212 $GLOBALS['sugar_config']['export_delimiter'] = $backup;
218 public function testGetPrecedentPreferenceWithUserPreferenceAndSpecifiedConfigKey()
220 $backup = $GLOBALS['sugar_config']['export_delimiter'];
221 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
222 $this->_user->setPreference('export_delimiter','');
223 $GLOBALS['sugar_config']['default_random_setting_for_localization_test'] = 'John is not Cool at all';
226 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user,'default_random_setting_for_localization_test'),
227 $GLOBALS['sugar_config']['default_random_setting_for_localization_test']
230 $backup = $GLOBALS['sugar_config']['export_delimiter'];
231 unset($GLOBALS['sugar_config']['default_random_setting_for_localization_test']);
237 public function testGetPrecedentPreferenceForDefaultEmailCharset()
239 $emailSettings = array('defaultOutboundCharset' => 'something fun');
240 $this->_user->setPreference('emailSettings',$emailSettings, 0, 'Emails');
243 $this->_locale->getPrecedentPreference('default_email_charset',$this->_user),
244 $emailSettings['defaultOutboundCharset']
251 public function testGetCurrencySymbol()
253 $this->_user->setPreference('default_currency_symbol','&&');
256 $this->_locale->getCurrencySymbol($this->_user),
264 public function testGetLocaleFormattedNumberWithNoCurrencySymbolSpecified()
266 $this->_user->setPreference('default_currency_symbol','**');
267 $this->_user->setPreference('default_decimal_separator','.');
270 $this->_locale->getLocaleFormattedNumber(20,'',true,$this->_user),