]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/utils/Bug22882Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / utils / Bug22882Test.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 'modules/Calls/metadata/additionalDetails.php';
39
40 /**
41  * @ticket 22882
42  */
43 class Bug22882Test extends Sugar_PHPUnit_Framework_TestCase
44 {
45     private $file = '';
46     private $file_fr_tmp = '';
47     private $file_en_tmp = '';
48     
49     public function setUp()
50     {
51         if ( !is_dir('custom/include/language') )
52             @mkdir('custom/include/language', 0777, true);
53         sugar_cache_clear('app_list_strings.en_us');
54         sugar_cache_clear('app_list_strings.fr_test');
55     }
56     
57     public function testMultiLanguagesDeletedValue()
58     {
59         $this->loadFilesDeletedValue();
60         $resultfr = return_app_list_strings_language('fr_test');
61         $resulten = return_app_list_strings_language('en_us');
62         $resultfr = array_keys($resultfr['account_type_dom']);
63         $resulten = array_keys($resulten['account_type_dom']);
64         if($this->isSameSize($resultfr, $resulten)){
65             $this->isEqual($resultfr, $resulten);
66         }
67         $this->cleanupFiles();
68     }
69     
70     public function testMultiLanguagesDeletedValueFrOnly()
71     {
72         $this->loadFilesDeletedValueFrOnly();
73         $resultfr = return_app_list_strings_language('fr_test');
74         $resulten = return_app_list_strings_language('en_us');
75         $resultfr = array_keys($resultfr['account_type_dom']);
76         $resulten = array_keys($resulten['account_type_dom']);
77         $this->assertNotEquals(count($resultfr), count($resulten), 'The 2 drop down list have the same size.');
78         $this->cleanupFiles();
79     }
80     
81     public function testMultiLanguagesDeletedValueEnOnly()
82     {
83         $this->loadFilesDeletedValueEnOnly();
84         $resultfr = return_app_list_strings_language('fr_test');
85         $resulten = return_app_list_strings_language('en_us');
86         $resultfr = array_keys($resultfr['account_type_dom']);
87         $resulten = array_keys($resulten['account_type_dom']);
88         $this->assertNotEquals(count($resultfr),count($resulten));
89         $this->assertFalse(in_array('Customer',$resulten));
90         $this->assertTrue(in_array('Customer',$resultfr));
91         $this->cleanupFiles();
92     }
93     
94     public function testMultiLanguagesAddedValue()
95     {
96         $this->loadFilesAddedValueEn();
97         $resultfr = return_app_list_strings_language('fr_test');
98         $resulten = return_app_list_strings_language('en_us');
99         $resultfr = array_keys($resultfr['account_type_dom']);
100         $resulten = array_keys($resulten['account_type_dom']);
101         $this->assertNotEquals(count($resultfr), count($resulten), 'The 2 drop down list have the same size.');
102         $this->cleanupFiles();
103     }
104     
105     public function loadFilesDeletedValue(){
106             $file_fr = <<<FRFR
107 <?php
108 \$app_list_strings['account_type_dom']=array ( 
109   //'Analyst' => 'Analyste', Line deleted
110   'Competitor' => 'Concurrent',
111   'Customer' => 'Client',
112   'Integrator' => 'Intégrateur',
113   'Investor' => 'Investisseur',
114   'Partner' => 'Partenaire',
115   'Press' => 'Presse',
116   'Prospect' => 'Prospect',
117   'Other' => 'Autre',
118   '' => '',
119 );
120 FRFR;
121         $file_en = <<<ENEN
122 <?php
123 \$app_list_strings['account_type_dom']=array ( 
124   //'Analyst' => 'Analyst', Line deleted
125   'Competitor' => 'Competitor',
126   'Customer' => 'Customer',
127   'Integrator' => 'Integrator',
128   'Investor' => 'Investor',
129   'Partner' => 'Partner',
130   'Press' => 'Press',
131   'Prospect' => 'Prospect',
132   'Other' => 'Other',
133   '' => '',
134 );
135 ENEN;
136         if(!file_exists('include/language/fr_test.lang.php')){
137             $this->file = file_get_contents('include/language/en_us.lang.php');
138             file_put_contents('include/language/fr_test.lang.php', $this->file);
139         }
140         if(!file_exists('custom/include/language/fr_test.lang.php')){
141             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
142         }else{
143             $this->file_fr_tmp = file_get_contents('custom/include/language/fr_test.lang.php');
144             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
145         }
146         if(!file_exists('custom/include/language/en_us.lang.php')){
147             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
148         }else{
149             $this->file_en_tmp = file_get_contents('custom/include/language/en_us.lang.php');
150             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
151         }
152     }
153     
154     public function loadFilesDeletedValueFrOnly(){
155             $file_fr = <<<FRFR
156 <?php
157 \$app_list_strings['account_type_dom']=array ( 
158   //'Analyst' => 'Analyste', Line deleted
159   'Competitor' => 'Concurrent',
160   'Customer' => 'Client',
161   'Integrator' => 'Intégrateur',
162   'Investor' => 'Investisseur',
163   'Partner' => 'Partenaire',
164   'Press' => 'Presse',
165   'Prospect' => 'Prospect',
166   'Other' => 'Autre',
167   '' => '',
168 );
169 FRFR;
170         $file_en = <<<ENEN
171 <?php
172 \$app_list_strings['account_type_dom']=array ( 
173   'Analyst' => 'Analyst',
174   'Competitor' => 'Competitor',
175   'Customer' => 'Customer',
176   'Integrator' => 'Integrator',
177   'Investor' => 'Investor',
178   'Partner' => 'Partner',
179   'Press' => 'Press',
180   'Prospect' => 'Prospect',
181   'Other' => 'Other',
182   '' => '',
183 );
184 ENEN;
185         if(!file_exists('include/language/fr_test.lang.php')){
186             $this->file = file_get_contents('include/language/en_us.lang.php');
187             file_put_contents('include/language/fr_test.lang.php', $this->file);
188         }
189         if(!file_exists('custom/include/language/fr_test.lang.php')){
190             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
191         }else{
192             $this->file_fr_tmp = file_get_contents('custom/include/language/fr_test.lang.php');
193             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
194         }
195         if(!file_exists('custom/include/language/en_us.lang.php')){
196             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
197         }else{
198             $this->file_en_tmp = file_get_contents('custom/include/language/en_us.lang.php');
199             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
200         }
201     }
202     
203     public function loadFilesDeletedValueEnOnly(){
204             $file_fr = <<<FRFR
205 <?php
206 \$app_list_strings['account_type_dom']=array ( 
207   'Analyst' => 'Analyste',
208   'Competitor' => 'Concurrent',
209   'Customer' => 'Client',
210   'Integrator' => 'Intégrateur',
211   'Investor' => 'Investisseur',
212   'Partner' => 'Partenaire',
213   'Press' => 'Presse',
214   'Prospect' => 'Prospect',
215   'Other' => 'Autre',
216   '' => '',
217 );
218 FRFR;
219         $file_en = <<<ENEN
220 <?php
221 \$app_list_strings['account_type_dom']=array ( 
222   'Analyst' => 'Analyst',
223   'Competitor' => 'Competitor',
224   //'Customer' => 'Customer',
225   'Integrator' => 'Integrator',
226   'Investor' => 'Investor',
227   'Partner' => 'Partner',
228   'Press' => 'Press',
229   'Prospect' => 'Prospect',
230   'Other' => 'Other',
231   '' => '',
232 );
233 ENEN;
234         if(!file_exists('include/language/fr_test.lang.php')){
235             $this->file = file_get_contents('include/language/en_us.lang.php');
236             file_put_contents('include/language/fr_test.lang.php', $this->file);
237         }
238         if(!file_exists('custom/include/language/fr_test.lang.php')){
239             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
240         }else{
241             $this->file_fr_tmp = file_get_contents('custom/include/language/fr_test.lang.php');
242             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
243         }
244         if(!file_exists('custom/include/language/en_us.lang.php')){
245             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
246         }else{
247             $this->file_en_tmp = file_get_contents('custom/include/language/en_us.lang.php');
248             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
249         }
250     }
251     
252     public function loadFilesAddedValueEn(){
253             $file_fr = <<<FRFR
254 <?php
255 \$app_list_strings['account_type_dom']=array ( 
256   'Analyst' => 'Analyste',
257   'Competitor' => 'Concurrent',
258   'Customer' => 'Client',
259   'Integrator' => 'Intégrateur',
260   'Investor' => 'Investisseur',
261   'Partner' => 'Partenaire',
262   'Press' => 'Presse',
263   'Prospect' => 'Prospect',
264   'Other' => 'Autre',
265   '' => '',
266 );
267 FRFR;
268         $file_en = <<<ENEN
269 <?php
270 \$app_list_strings['account_type_dom']=array ( 
271   'Extra' => 'Extra',
272   'Analyst' => 'Analyst',
273   'Competitor' => 'Competitor',
274   'Customer' => 'Customer',
275   'Integrator' => 'Integrator',
276   'Investor' => 'Investor',
277   'Partner' => 'Partner',
278   'Press' => 'Press',
279   'Prospect' => 'Prospect',
280   'Other' => 'Other',
281   '' => '',
282 );
283 ENEN;
284         if(!file_exists('include/language/fr_test.lang.php')){
285             $this->file = file_get_contents('include/language/en_us.lang.php');
286             file_put_contents('include/language/fr_test.lang.php', $this->file);
287         }
288         if(!file_exists('custom/include/language/fr_test.lang.php')){
289             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
290         }else{
291             $this->file_fr_tmp = file_get_contents('custom/include/language/fr_test.lang.php');
292             file_put_contents('custom/include/language/fr_test.lang.php', $file_fr);
293         }
294         if(!file_exists('custom/include/language/en_us.lang.php')){
295             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
296         }else{
297             $this->file_en_tmp = file_get_contents('custom/include/language/en_us.lang.php');
298             file_put_contents('custom/include/language/en_us.lang.php', $file_en);
299         }
300     }
301     
302     public function cleanupFiles(){
303         if(!empty($this->file)){
304             $this->file = '';
305             unlink('include/language/fr_test.lang.php');
306         }
307         if(!empty($this->file_fr_tmp)){
308             file_put_contents('custom/include/language/fr_test.lang.php', $this->file_fr_tmp);
309             $this->file_fr_tmp = '';
310         }else{
311             unlink('custom/include/language/fr_test.lang.php');
312         }
313         if(!empty($this->file_en_tmp)){
314             file_put_contents('custom/include/language/en_us.lang.php', $this->file_en_tmp);
315             $this->file_en_tmp = '';
316         }else{
317             unlink('custom/include/language/en_us.lang.php');
318         }
319     }
320     
321     public function isSameSize($result1, $result2)
322     {
323         if(count($result1) != count($result2)){
324             $this->assertTrue(false, 'The 2 drop down list didn\'t have the same size.');
325             return false;
326         }
327         return true;
328     }
329     
330     public function isEqual($result1, $result2)
331     {
332         foreach($result1 as $k=>$v){
333             $this->assertTrue(in_array($v,$result2));
334         }
335         foreach($result2 as $k=>$v){
336             $this->assertTrue(in_array($v,$result1));
337         }
338     }
339 }