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