]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Localization/LocalizationTest.php
Release 6.4.0
[Github/sugarcrm.git] / tests / include / Localization / LocalizationTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 require_once 'include/Localization/Localization.php';
39
40 class LocalizationTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     public function setUp() 
43     {
44         $this->_locale = new Localization();
45         $this->_user = SugarTestUserUtilities::createAnonymousUser();
46     }
47     
48     public function tearDown()
49     {
50         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
51     }
52     
53     public function providerGetLocaleFormattedName()
54     {
55         return array(
56             array(
57                 't s f l',
58                 'Mason',
59                 'Hu',
60                 'Mr.',
61                 'Saler',
62                 'Saler Mr. Mason Hu',
63                 ),
64             array(
65                 'l f',
66                 'Mason',
67                 'Hu',
68                 '',
69                 '',
70                 'Hu Mason',
71                 ),
72                     
73             );
74     }
75     
76     /**
77      * @dataProvider providerGetLocaleFormattedName
78      */
79     public function testGetLocaleFormattedNameUsingFormatInUserPreference($nameFormat,$firstName,$lastName,$salutation,$title,$expectedOutput)
80     {
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);
84     }
85     
86     /**
87      * @dataProvider providerGetLocaleFormattedName
88      */
89     public function testGetLocaleFormattedNameUsingFormatSpecified($nameFormat,$firstName,$lastName,$salutation,$title,$expectedOutput)
90     {
91         $outputName = $this->_locale->getLocaleFormattedName($firstName, $lastName, $salutation, $title, $nameFormat,$this->_user);
92         $this->assertEquals($expectedOutput, $outputName);
93     }
94     
95     /**
96      * @ticket 26803
97      */
98     public function testGetLocaleFormattedNameWhenNameIsEmpty()
99     {
100         $this->_user->setPreference('default_locale_name_format', 'l f');
101         $expectedOutput = ' ';
102         $outputName = $this->_locale->getLocaleFormattedName('', '', '', '', '',$this->_user);
103         
104         $this->assertEquals($expectedOutput, $outputName);
105     }
106     
107     /**
108      * @ticket 26803
109      */
110     public function testGetLocaleFormattedNameWhenNameIsEmptyAndReturningEmptyString()
111     {
112         $this->_user->setPreference('default_locale_name_format', 'l f');
113         $expectedOutput = '';
114         $outputName = $this->_locale->getLocaleFormattedName('', '', '', '', '',$this->_user,true);
115         
116         $this->assertEquals($expectedOutput, $outputName);
117     }
118     
119     public function testCurrenciesLoadingCorrectly()
120     {
121         global $sugar_config;
122         
123         $currencies = $this->_locale->getCurrencies();
124         
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);
128     }
129     
130     public function testConvertingUnicodeStringBetweenCharsets()
131     {
132         $string = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド";
133         
134         $convertedString = $this->_locale->translateCharset($string,'UTF-8','EUC-CN');
135         $this->assertNotEquals($string,$convertedString);
136         
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);
140     }
141     
142     public function testCanDetectAsciiEncoding()
143     {
144         $string = 'string';
145         
146         $this->assertEquals(
147             $this->_locale->detectCharset($string),
148             'ASCII'
149             );
150     }
151     
152     public function testCanDetectUtf8Encoding()
153     {
154         $string = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド';
155         
156         $this->assertEquals(
157             $this->_locale->detectCharset($string),
158             'UTF-8'
159             );
160     }
161     
162     public function testGetPrecedentPreferenceWithUserPreference()
163     {
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');
167         
168         $this->assertEquals(
169             $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
170             $this->_user->getPreference('export_delimiter')
171             );
172         
173         $GLOBALS['sugar_config']['export_delimiter'] = $backup;
174     }
175     
176     public function testGetPrecedentPreferenceWithNoUserPreference()
177     {
178         $backup = $GLOBALS['sugar_config']['export_delimiter'];
179         $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
180         
181         $this->assertEquals(
182             $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
183             $GLOBALS['sugar_config']['export_delimiter']
184             );
185         
186         $GLOBALS['sugar_config']['export_delimiter'] = $backup;
187     }
188     
189     /**
190      * @ticket 33086
191      */
192     public function testGetPrecedentPreferenceWithUserPreferenceAndSpecifiedConfigKey()
193     {
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';
198         
199         $this->assertEquals(
200             $this->_locale->getPrecedentPreference('export_delimiter',$this->_user,'default_random_setting_for_localization_test'),
201             $GLOBALS['sugar_config']['default_random_setting_for_localization_test']
202             );
203         
204         $backup = $GLOBALS['sugar_config']['export_delimiter'];
205         unset($GLOBALS['sugar_config']['default_random_setting_for_localization_test']);
206     }
207     
208     /**
209      * @ticket 39171
210      */
211     public function testGetPrecedentPreferenceForDefaultEmailCharset()
212     {
213         $emailSettings = array('defaultOutboundCharset' => 'something fun');
214         $this->_user->setPreference('emailSettings',$emailSettings, 0, 'Emails');
215         
216         $this->assertEquals(
217             $this->_locale->getPrecedentPreference('default_email_charset',$this->_user),
218             $emailSettings['defaultOutboundCharset']
219             );
220     }
221     
222     /**
223      * @ticket 23992
224      */
225     public function testGetCurrencySymbol()
226     {
227         $this->_user->setPreference('default_currency_symbol','&&');
228         
229         $this->assertEquals(
230             $this->_locale->getCurrencySymbol($this->_user),
231             '&&'
232             );
233     }
234     
235     /**
236      * @ticket 23992
237      */
238     public function testGetLocaleFormattedNumberWithNoCurrencySymbolSpecified()
239     {
240         $this->_user->setPreference('default_currency_symbol','**');
241         $this->_user->setPreference('default_decimal_separator','.');
242         
243         $this->assertEquals(
244             $this->_locale->getLocaleFormattedNumber(20,'',true,$this->_user),
245             '**20'
246             );
247     }
248 }