2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 class Bug32382Test extends Sugar_PHPUnit_Framework_TestCase
40 public function setUp()
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');
47 //Simulate the .bak file that was created
48 if( $fh = @fopen('custom/include/language/en_us.lang.php.bak', 'w+') )
52 \$app_list_strings['this would have been missed!'] = array (
58 \$app_list_strings['a_test_1'] = array (
64 //a_test_1 is the same, nothing was wrong with it
65 \$app_list_strings['a_test_that_is_okay'] = array (
71 //b_test_2 has four entries, but "4"
72 \$app_list_strings['b_test_2'] = array (
79 //c_test_3 has four entries
80 \$app_list_strings['c_test_3'] = array (
87 \$GLOBALS['app_list_strings']['b_test_2'] = array (
94 \$GLOBALS['app_list_strings']['c_test_3'] = array (
102 \$GLOBALS['app_list_strings']['c_test_3'] = array (
110 fputs( $fh, $string);
115 //Simulate the .php file that was created
116 if( $fh = @fopen('custom/include/language/en_us.lang.php', 'w+') )
120 \$GLOBALS['app_list_strings']['a_test_that_is_okay'] = array (
126 \$GLOBALS['app_list_strings']['a_test__'] = array (
132 \$GLOBALS['app_list_strings']['b_test__'] = array (
139 \$GLOBALS['app_list_strings']['c_test__'] = array (
146 fputs( $fh, $string);
152 public function tearDown()
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');
158 unlink('custom/include/language/en_us.lang.php');
161 if(file_exists('custom/include/language/en_us.lang.php.bak')) {
162 unlink('custom/include/language/en_us.lang.php.bak');
165 if(file_exists('custom/include/language/en_us.lang.php.php_bak')) {
166 unlink('custom/include/language/en_us.lang.php.php_bak');
169 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
170 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
173 public function test_dropdown_fixed()
175 require_once('modules/UpgradeWizard/uw_utils.php');
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');
181 unset($GLOBALS['app_list_strings']);
182 require('custom/include/language/en_us.lang.php');
184 $this->assertTrue(isset($GLOBALS['app_list_strings']['this_would_have_been_missed_']), "Assert that 'this would have been missed! key was fixed");
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");
189 $this->assertEquals(count($GLOBALS['app_list_strings']['a_test_that_is_okay']), 3, "Assert that a_test_that_is_okay has 3 items");
191 preg_match_all('/b_test__/', $contents, $matches);
192 $this->assertEquals(count($matches[0]), 2, "Assert that b_test__ is declared twice");
194 $this->assertEquals(count($GLOBALS['app_list_strings']['b_test__']), 4, "Assert that b_test__ is additive and has 4 entries");
196 preg_match_all('/c_test__/', $contents, $matches);
197 $this->assertEquals(count($matches[0]), 2, "Assert that c_test__ is declared twice");
199 $this->assertEquals(count($GLOBALS['app_list_strings']['c_test__']), 5, "Assert that c_test__ is additive and contains 5 entries");