PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modules/UpgradeWizard/Bug30709Test.php

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