]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Localization/LocalizationTest.php
Release 6.5.10
[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-2013 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 testConvertKS_C_56011987AsCP949()
143     {
144         if ( !function_exists('iconv') ) {
145             $this->markTestSkipped('Requires iconv');
146         }
147         
148         $string = file_get_contents(dirname(__FILE__)."/Bug49619.txt");
149         
150         $convertedString = $this->_locale->translateCharset($string,'KS_C_5601-1987','UTF-8', true);
151         $this->assertNotEquals($string,$convertedString);
152         
153         // test for this working by being able to convert back and the string match
154         $convertedString = $this->_locale->translateCharset($convertedString,'UTF-8','KS_C_5601-1987',true);
155         $this->assertEquals($string,$convertedString);
156     }
157     
158     public function testCanDetectAsciiEncoding()
159     {
160         $string = 'string';
161         
162         $this->assertEquals(
163             $this->_locale->detectCharset($string),
164             'ASCII'
165             );
166     }
167     
168     public function testCanDetectUtf8Encoding()
169     {
170         $string = 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモガギグゲゴザジズゼゾダヂヅデド';
171         
172         $this->assertEquals(
173             $this->_locale->detectCharset($string),
174             'UTF-8'
175             );
176     }
177     
178     public function testGetPrecedentPreferenceWithUserPreference()
179     {
180         $backup = $GLOBALS['sugar_config']['export_delimiter'];
181         $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
182         $this->_user->setPreference('export_delimiter','John is Really Cool');
183         
184         $this->assertEquals(
185             $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
186             $this->_user->getPreference('export_delimiter')
187             );
188         
189         $GLOBALS['sugar_config']['export_delimiter'] = $backup;
190     }
191     
192     public function testGetPrecedentPreferenceWithNoUserPreference()
193     {
194         $backup = $GLOBALS['sugar_config']['export_delimiter'];
195         $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
196         
197         $this->assertEquals(
198             $this->_locale->getPrecedentPreference('export_delimiter',$this->_user),
199             $GLOBALS['sugar_config']['export_delimiter']
200             );
201         
202         $GLOBALS['sugar_config']['export_delimiter'] = $backup;
203     }
204     
205     /**
206      * @ticket 33086
207      */
208     public function testGetPrecedentPreferenceWithUserPreferenceAndSpecifiedConfigKey()
209     {
210         $backup = $GLOBALS['sugar_config']['export_delimiter'];
211         $GLOBALS['sugar_config']['export_delimiter'] = 'John is Cool';
212         $this->_user->setPreference('export_delimiter','');
213         $GLOBALS['sugar_config']['default_random_setting_for_localization_test'] = 'John is not Cool at all';
214         
215         $this->assertEquals(
216             $this->_locale->getPrecedentPreference('export_delimiter',$this->_user,'default_random_setting_for_localization_test'),
217             $GLOBALS['sugar_config']['default_random_setting_for_localization_test']
218             );
219         
220         $backup = $GLOBALS['sugar_config']['export_delimiter'];
221         unset($GLOBALS['sugar_config']['default_random_setting_for_localization_test']);
222     }
223     
224     /**
225      * @ticket 39171
226      */
227     public function testGetPrecedentPreferenceForDefaultEmailCharset()
228     {
229         $emailSettings = array('defaultOutboundCharset' => 'something fun');
230         $this->_user->setPreference('emailSettings',$emailSettings, 0, 'Emails');
231         
232         $this->assertEquals(
233             $this->_locale->getPrecedentPreference('default_email_charset',$this->_user),
234             $emailSettings['defaultOutboundCharset']
235             );
236     }
237     
238     /**
239      * @ticket 23992
240      */
241     public function testGetCurrencySymbol()
242     {
243         $this->_user->setPreference('default_currency_symbol','&&');
244         
245         $this->assertEquals(
246             $this->_locale->getCurrencySymbol($this->_user),
247             '&&'
248             );
249     }
250     
251     /**
252      * @ticket 23992
253      */
254     public function testGetLocaleFormattedNumberWithNoCurrencySymbolSpecified()
255     {
256         $this->_user->setPreference('default_currency_symbol','**');
257         $this->_user->setPreference('default_decimal_separator','.');
258         
259         $this->assertEquals(
260             $this->_locale->getLocaleFormattedNumber(20,'',true,$this->_user),
261             '**20'
262             );
263     }
264 }