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