2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 Bug30709 extends Sugar_PHPUnit_Framework_TestCase {
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');
46 //Simulate the .bak file that was created
47 if( $fh = @fopen('custom/include/language/en_us.lang.php.bak', 'w+') )
51 \$app_list_strings['this would have been missed!'] = array (
57 \$app_list_strings['a_test_1'] = array (
63 //a_test_1 is the same, nothing was wrong with it
64 \$app_list_strings['a_test_that_is_okay'] = array (
70 //b_test_2 has four entries, but "4"
71 \$app_list_strings['b_test_2'] = array (
78 //c_test_3 has four entries
79 \$app_list_strings['c_test_3'] = array (
86 \$GLOBALS['app_list_strings']['b_test_2'] = array (
93 \$GLOBALS['app_list_strings']['c_test_3'] = array (
101 \$GLOBALS['app_list_strings']['c_test_3'] = array (
111 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 (
148 fputs( $fh, $string);
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');
159 unlink('custom/include/language/en_us.lang.php');
162 if(file_exists('custom/include/language/en_us.lang.php.bak')) {
163 unlink('custom/include/language/en_us.lang.php.bak');
166 if(file_exists('custom/include/language/en_us.lang.php.php_bak')) {
167 unlink('custom/include/language/en_us.lang.php.php_bak');
170 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
171 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
175 function test_dropdown_fixed() {
176 require_once('modules/UpgradeWizard/uw_utils.php');
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');
182 unset($GLOBALS['app_list_strings']);
183 require('custom/include/language/en_us.lang.php');
185 $this->assertTrue(isset($GLOBALS['app_list_strings']['this_would_have_been_missed_']));
187 preg_match_all('/a_test_that_is_okay/', $contents, $matches);
188 $this->assertEquals(count($matches[0]),1);
190 $this->assertEquals(count($GLOBALS['app_list_strings']['a_test_that_is_okay']),3);
192 preg_match_all('/b_test__/', $contents, $matches);
193 $this->assertEquals(count($matches[0]),2);
195 $this->assertEquals(count($GLOBALS['app_list_strings']['b_test__']),4);
197 preg_match_all('/c_test__/', $contents, $matches);
198 $this->assertEquals(count($matches[0]),2);
200 $this->assertEquals(count($GLOBALS['app_list_strings']['c_test__']),5);