PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modules/UpgradeWizard/Bug30709Test.php

https://github.com/item/sugarcrm_dev
PHP | 171 lines | 127 code | 37 blank | 7 comment | 7 complexity | dd3b664695ccf8677e8a57880b25de04 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1
  1. <?php
  2. class Bug30709 extends Sugar_PHPUnit_Framework_TestCase {
  3. function setUp() {
  4. //Create the language files with bad name
  5. if(file_exists('custom/include/language/en_us.lang.php')) {
  6. copy('custom/include/language/en_us.lang.php', 'custom/include/language/en_us.lang.php.backup');
  7. }
  8. //Simulate the .bak file that was created
  9. if( $fh = @fopen('custom/include/language/en_us.lang.php.bak', 'w+') )
  10. {
  11. $string = <<<EOQ
  12. <?php
  13. \$app_list_strings['this would have been missed!'] = array (
  14. 'a' => 'A',
  15. 'b' => 'B',
  16. 'c' => 'C',
  17. );
  18. \$app_list_strings['a_test_1'] = array (
  19. 'a' => 'A',
  20. 'b' => 'B',
  21. 'c' => 'C',
  22. );
  23. //a_test_1 is the same, nothing was wrong with it
  24. \$app_list_strings['a_test_that_is_okay'] = array (
  25. 'a' => 'A',
  26. 'b' => 'B',
  27. 'c' => 'C',
  28. );
  29. //b_test_2 has four entries, but "4"
  30. \$app_list_strings['b_test_2'] = array (
  31. '0' => 'Zero',
  32. '1' => 'One',
  33. '2' => 'Two',
  34. '4' => 'Four',
  35. );
  36. //c_test_3 has four entries
  37. \$app_list_strings['c_test_3'] = array (
  38. 'a' => 'A',
  39. 'b' => 'B',
  40. 'c' => 'C',
  41. 'd' => 'D',
  42. );
  43. \$GLOBALS['app_list_strings']['b_test_2'] = array (
  44. '0' => 'Zero',
  45. '1' => 'One',
  46. '2' => 'Two',
  47. '3' => 'Three',
  48. );
  49. \$GLOBALS['app_list_strings']['c_test_3'] = array (
  50. 'a' => 'A',
  51. 'b' => 'B',
  52. 'c' => 'C',
  53. 'd' => 'D',
  54. 'e' => 'E',
  55. );
  56. \$GLOBALS['app_list_strings']['c_test_3'] = array (
  57. 'a' => 'A',
  58. 'b' => 'B',
  59. 'c' => 'C',
  60. 'd' => 'D',
  61. 'f' => 'F',
  62. );
  63. EOQ;
  64. fputs( $fh, $string);
  65. fclose( $fh );
  66. }
  67. //Simulate the .php file that was created
  68. if( $fh = @fopen('custom/include/language/en_us.lang.php', 'w+') )
  69. {
  70. $string = <<<EOQ
  71. <?php
  72. \$GLOBALS['app_list_strings']['a_test_that_is_okay'] = array (
  73. 'a' => 'A',
  74. 'b' => 'B',
  75. 'c' => 'C',
  76. );
  77. \$GLOBALS['app_list_strings']['a_test__'] = array (
  78. 'a' => 'A',
  79. 'b' => 'B',
  80. 'c' => 'C',
  81. );
  82. \$GLOBALS['app_list_strings']['b_test__'] = array (
  83. '0' => 'Zero',
  84. '1' => 'One',
  85. '2' => 'Two',
  86. '4' => 'Four',
  87. );
  88. \$GLOBALS['app_list_strings']['c_test__'] = array (
  89. 'a' => 'A',
  90. 'b' => 'B',
  91. 'c' => 'C',
  92. 'd' => 'D',
  93. );
  94. EOQ;
  95. fputs( $fh, $string);
  96. fclose( $fh );
  97. }
  98. }
  99. function tearDown() {
  100. if(file_exists('custom/include/language/en_us.lang.php.backup')) {
  101. copy('custom/include/language/en_us.lang.php.backup', 'custom/include/language/en_us.lang.php');
  102. unlink('custom/include/language/en_us.lang.php.backup');
  103. } else {
  104. unlink('custom/include/language/en_us.lang.php');
  105. }
  106. if(file_exists('custom/include/language/en_us.lang.php.bak')) {
  107. unlink('custom/include/language/en_us.lang.php.bak');
  108. }
  109. if(file_exists('custom/include/language/en_us.lang.php.php_bak')) {
  110. unlink('custom/include/language/en_us.lang.php.php_bak');
  111. }
  112. $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
  113. $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
  114. }
  115. function test_dropdown_fixed() {
  116. require_once('modules/UpgradeWizard/uw_utils.php');
  117. fix_dropdown_list();
  118. //Check to make sure we don't have the buggy format where '$GLOBALS["app_list_strings"] = array (...' was declared
  119. $contents = file_get_contents('custom/include/language/en_us.lang.php');
  120. unset($GLOBALS['app_list_strings']);
  121. require('custom/include/language/en_us.lang.php');
  122. $this->assertTrue(isset($GLOBALS['app_list_strings']['this_would_have_been_missed_']));
  123. preg_match_all('/a_test_that_is_okay/', $contents, $matches);
  124. $this->assertEquals(count($matches[0]),1);
  125. $this->assertEquals(count($GLOBALS['app_list_strings']['a_test_that_is_okay']),3);
  126. preg_match_all('/b_test__/', $contents, $matches);
  127. $this->assertEquals(count($matches[0]),2);
  128. $this->assertEquals(count($GLOBALS['app_list_strings']['b_test__']),4);
  129. preg_match_all('/c_test__/', $contents, $matches);
  130. $this->assertEquals(count($matches[0]),2);
  131. $this->assertEquals(count($GLOBALS['app_list_strings']['c_test__']),5);
  132. }
  133. }
  134. ?>