]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/Bug30709Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / Bug30709Test.php
1 <?php
2
3 class Bug30709 extends Sugar_PHPUnit_Framework_TestCase {
4
5 function setUp() {
6     //Create the language files with bad name
7     if(file_exists('custom/include/language/en_us.lang.php')) {
8        copy('custom/include/language/en_us.lang.php', 'custom/include/language/en_us.lang.php.backup');
9     }
10         
11     //Simulate the .bak file that was created
12     if( $fh = @fopen('custom/include/language/en_us.lang.php.bak', 'w+') )
13     {
14 $string = <<<EOQ
15 <?php
16 \$app_list_strings['this would have been missed!'] = array (
17     'a' => 'A',
18     'b' => 'B',
19     'c' => 'C',
20 );
21
22 \$app_list_strings['a_test_1'] = array (
23     'a' => 'A',
24     'b' => 'B',
25     'c' => 'C',
26 );
27
28 //a_test_1 is the same, nothing was wrong with it
29 \$app_list_strings['a_test_that_is_okay'] = array (
30     'a' => 'A',
31     'b' => 'B',
32     'c' => 'C',
33 );
34   
35 //b_test_2 has four entries, but "4"
36 \$app_list_strings['b_test_2'] = array (
37     '0' => 'Zero',
38     '1' => 'One',
39     '2' => 'Two',
40     '4' => 'Four',
41 );
42
43 //c_test_3 has four entries
44 \$app_list_strings['c_test_3'] = array (
45     'a' => 'A',
46     'b' => 'B',
47     'c' => 'C',
48     'd' => 'D',
49 );
50
51 \$GLOBALS['app_list_strings']['b_test_2'] = array (
52     '0' => 'Zero',
53     '1' => 'One',
54     '2' => 'Two',
55     '3' => 'Three',
56 );
57
58 \$GLOBALS['app_list_strings']['c_test_3'] = array (
59     'a' => 'A',
60     'b' => 'B',
61     'c' => 'C',
62     'd' => 'D',
63     'e' => 'E',
64 );
65
66 \$GLOBALS['app_list_strings']['c_test_3'] = array (
67     'a' => 'A',
68     'b' => 'B',
69     'c' => 'C',
70     'd' => 'D',
71     'f' => 'F',
72 );
73
74
75 EOQ;
76        fputs( $fh, $string);
77        fclose( $fh );
78     } 
79     
80     //Simulate the .php file that was created
81     if( $fh = @fopen('custom/include/language/en_us.lang.php', 'w+') )
82     {
83 $string = <<<EOQ
84 <?php
85 \$GLOBALS['app_list_strings']['a_test_that_is_okay'] = array (
86     'a' => 'A',
87     'b' => 'B',
88     'c' => 'C',
89   );
90   
91 \$GLOBALS['app_list_strings']['a_test__'] = array (
92     'a' => 'A',
93     'b' => 'B',
94     'c' => 'C',
95 );  
96   
97 \$GLOBALS['app_list_strings']['b_test__'] = array (
98     '0' => 'Zero',
99     '1' => 'One',
100     '2' => 'Two',
101     '4' => 'Four',
102 );
103   
104 \$GLOBALS['app_list_strings']['c_test__'] = array (  
105     'a' => 'A',
106     'b' => 'B',
107     'c' => 'C',
108     'd' => 'D',
109 );
110
111
112 EOQ;
113        fputs( $fh, $string);
114        fclose( $fh );        
115     }
116     
117 }
118
119 function tearDown() {
120     if(file_exists('custom/include/language/en_us.lang.php.backup')) {
121        copy('custom/include/language/en_us.lang.php.backup', 'custom/include/language/en_us.lang.php');
122        unlink('custom/include/language/en_us.lang.php.backup');  
123     } else {
124        unlink('custom/include/language/en_us.lang.php');
125     }
126     
127     if(file_exists('custom/include/language/en_us.lang.php.bak')) {
128        unlink('custom/include/language/en_us.lang.php.bak');
129     }   
130
131     if(file_exists('custom/include/language/en_us.lang.php.php_bak')) {
132        unlink('custom/include/language/en_us.lang.php.php_bak');
133     }
134     
135     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
136     $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
137 }
138
139
140 function test_dropdown_fixed() {        
141     require_once('modules/UpgradeWizard/uw_utils.php');
142     fix_dropdown_list();
143         
144     //Check to make sure we don't have the buggy format where '$GLOBALS["app_list_strings"] = array (...' was declared
145     $contents = file_get_contents('custom/include/language/en_us.lang.php');
146     
147     unset($GLOBALS['app_list_strings']);
148     require('custom/include/language/en_us.lang.php');
149
150     $this->assertTrue(isset($GLOBALS['app_list_strings']['this_would_have_been_missed_']));
151     
152     preg_match_all('/a_test_that_is_okay/', $contents, $matches);
153     $this->assertEquals(count($matches[0]),1);       
154     
155     $this->assertEquals(count($GLOBALS['app_list_strings']['a_test_that_is_okay']),3);
156     
157     preg_match_all('/b_test__/', $contents, $matches);
158     $this->assertEquals(count($matches[0]),2);    
159     
160     $this->assertEquals(count($GLOBALS['app_list_strings']['b_test__']),4);
161     
162     preg_match_all('/c_test__/', $contents, $matches);
163     $this->assertEquals(count($matches[0]),2);
164     
165     $this->assertEquals(count($GLOBALS['app_list_strings']['c_test__']),5);  
166 }
167
168
169 }
170
171 ?>