]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/Bug30709Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / Bug30709Test.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 class Bug30709 extends Sugar_PHPUnit_Framework_TestCase {
39
40 function setUp() {
41     //Create the language files with bad name
42     if(file_exists('custom/include/language/en_us.lang.php')) {
43        copy('custom/include/language/en_us.lang.php', 'custom/include/language/en_us.lang.php.backup');
44     }
45         
46     //Simulate the .bak file that was created
47     if( $fh = @fopen('custom/include/language/en_us.lang.php.bak', 'w+') )
48     {
49 $string = <<<EOQ
50 <?php
51 \$app_list_strings['this would have been missed!'] = array (
52     'a' => 'A',
53     'b' => 'B',
54     'c' => 'C',
55 );
56
57 \$app_list_strings['a_test_1'] = array (
58     'a' => 'A',
59     'b' => 'B',
60     'c' => 'C',
61 );
62
63 //a_test_1 is the same, nothing was wrong with it
64 \$app_list_strings['a_test_that_is_okay'] = array (
65     'a' => 'A',
66     'b' => 'B',
67     'c' => 'C',
68 );
69   
70 //b_test_2 has four entries, but "4"
71 \$app_list_strings['b_test_2'] = array (
72     '0' => 'Zero',
73     '1' => 'One',
74     '2' => 'Two',
75     '4' => 'Four',
76 );
77
78 //c_test_3 has four entries
79 \$app_list_strings['c_test_3'] = array (
80     'a' => 'A',
81     'b' => 'B',
82     'c' => 'C',
83     'd' => 'D',
84 );
85
86 \$GLOBALS['app_list_strings']['b_test_2'] = array (
87     '0' => 'Zero',
88     '1' => 'One',
89     '2' => 'Two',
90     '3' => 'Three',
91 );
92
93 \$GLOBALS['app_list_strings']['c_test_3'] = array (
94     'a' => 'A',
95     'b' => 'B',
96     'c' => 'C',
97     'd' => 'D',
98     'e' => 'E',
99 );
100
101 \$GLOBALS['app_list_strings']['c_test_3'] = array (
102     'a' => 'A',
103     'b' => 'B',
104     'c' => 'C',
105     'd' => 'D',
106     'f' => 'F',
107 );
108
109
110 EOQ;
111        fputs( $fh, $string);
112        fclose( $fh );
113     } 
114     
115     //Simulate the .php file that was created
116     if( $fh = @fopen('custom/include/language/en_us.lang.php', 'w+') )
117     {
118 $string = <<<EOQ
119 <?php
120 \$GLOBALS['app_list_strings']['a_test_that_is_okay'] = array (
121     'a' => 'A',
122     'b' => 'B',
123     'c' => 'C',
124   );
125   
126 \$GLOBALS['app_list_strings']['a_test__'] = array (
127     'a' => 'A',
128     'b' => 'B',
129     'c' => 'C',
130 );  
131   
132 \$GLOBALS['app_list_strings']['b_test__'] = array (
133     '0' => 'Zero',
134     '1' => 'One',
135     '2' => 'Two',
136     '4' => 'Four',
137 );
138   
139 \$GLOBALS['app_list_strings']['c_test__'] = array (  
140     'a' => 'A',
141     'b' => 'B',
142     'c' => 'C',
143     'd' => 'D',
144 );
145
146
147 EOQ;
148        fputs( $fh, $string);
149        fclose( $fh );        
150     }
151     
152 }
153
154 function tearDown() {
155     if(file_exists('custom/include/language/en_us.lang.php.backup')) {
156        copy('custom/include/language/en_us.lang.php.backup', 'custom/include/language/en_us.lang.php');
157        unlink('custom/include/language/en_us.lang.php.backup');  
158     } else {
159        unlink('custom/include/language/en_us.lang.php');
160     }
161     
162     if(file_exists('custom/include/language/en_us.lang.php.bak')) {
163        unlink('custom/include/language/en_us.lang.php.bak');
164     }   
165
166     if(file_exists('custom/include/language/en_us.lang.php.php_bak')) {
167        unlink('custom/include/language/en_us.lang.php.php_bak');
168     }
169     
170     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
171     $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
172 }
173
174
175 function test_dropdown_fixed() {        
176     require_once('modules/UpgradeWizard/uw_utils.php');
177     fix_dropdown_list();
178         
179     //Check to make sure we don't have the buggy format where '$GLOBALS["app_list_strings"] = array (...' was declared
180     $contents = file_get_contents('custom/include/language/en_us.lang.php');
181     
182     unset($GLOBALS['app_list_strings']);
183     require('custom/include/language/en_us.lang.php');
184
185     $this->assertTrue(isset($GLOBALS['app_list_strings']['this_would_have_been_missed_']));
186     
187     preg_match_all('/a_test_that_is_okay/', $contents, $matches);
188     $this->assertEquals(count($matches[0]),1);       
189     
190     $this->assertEquals(count($GLOBALS['app_list_strings']['a_test_that_is_okay']),3);
191     
192     preg_match_all('/b_test__/', $contents, $matches);
193     $this->assertEquals(count($matches[0]),2);    
194     
195     $this->assertEquals(count($GLOBALS['app_list_strings']['b_test__']),4);
196     
197     preg_match_all('/c_test__/', $contents, $matches);
198     $this->assertEquals(count($matches[0]),2);
199     
200     $this->assertEquals(count($GLOBALS['app_list_strings']['c_test__']),5);  
201 }
202
203
204 }
205
206 ?>