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 testGetPrecedentPreferenceWithUserPreference()
164 $backup = $GLOBALS['sugar_config']['export_delimiter'];
165 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
166 $this->_user->setPreference('export_delimiter','John is Really Cool');
169 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
170 $this->_user->getPreference('export_delimiter')
173 $GLOBALS['sugar_config']['export_delimiter'] = $backup;
176 public function testGetPrecedentPreferenceWithNoUserPreference()
178 $backup = $GLOBALS['sugar_config']['export_delimiter'];
179 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
182 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
183 $GLOBALS['sugar_config']['export_delimiter']
186 $GLOBALS['sugar_config']['export_delimiter'] = $backup;
192 public function testGetPrecedentPreferenceWithUserPreferenceAndSpecifiedConfigKey()
194 $backup = $GLOBALS['sugar_config']['export_delimiter'];
195 $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
196 $this->_user->setPreference('export_delimiter','');
197 $GLOBALS['sugar_config']['default_random_setting_for_localization_test'] = 'John is not Cool at all';
200 $this->_locale->getPrecedentPreference('export_delimiter',$this->_user,'default_random_setting_for_localization_test'),
201 $GLOBALS['sugar_config']['default_random_setting_for_localization_test']
204 $backup = $GLOBALS['sugar_config']['export_delimiter'];
205 unset($GLOBALS['sugar_config']['default_random_setting_for_localization_test']);
211 public function testGetPrecedentPreferenceForDefaultEmailCharset()
213 $emailSettings = array('defaultOutboundCharset' => 'something fun');
214 $this->_user->setPreference('emailSettings',$emailSettings, 0, 'Emails');
217 $this->_locale->getPrecedentPreference('default_email_charset',$this->_user),
218 $emailSettings['defaultOutboundCharset']
225 public function testGetCurrencySymbol()
227 $this->_user->setPreference('default_currency_symbol','&&');
230 $this->_locale->getCurrencySymbol($this->_user),
238 public function testGetLocaleFormattedNumberWithNoCurrencySymbolSpecified()
240 $this->_user->setPreference('default_currency_symbol','**');
241 $this->_user->setPreference('default_decimal_separator','.');
244 $this->_locale->getLocaleFormattedNumber(20,'',true,$this->_user),