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

/tests/modules/UpgradeWizard/Bug32382Test.php

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