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