PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modules/Administration/Bug36978Test.php

https://github.com/item/sugarcrm_dev
PHP | 264 lines | 220 code | 37 blank | 7 comment | 14 complexity | 01fbf343678afa4c6e6fde50eca08238 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1
  1. <?php
  2. class Bug36978Test extends Sugar_PHPUnit_Framework_TestCase {
  3. var $rel_guid;
  4. var $has_custom_table_dictionary;
  5. var $moduleList;
  6. function setUp() {
  7. if(true) {
  8. $this->markTestSkipped("Skipping unless otherwise specified");
  9. return;
  10. }
  11. $admin = new User();
  12. $GLOBALS['current_user'] = $admin->retrieve('1');
  13. $GLOBALS['app_list_strings'] = return_app_list_strings_language('en_us');
  14. //Create the custom relationships
  15. if(!file_exists('custom/Extension/modules/abc_Test/Ext/Vardefs')) {
  16. mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Vardefs');
  17. }
  18. if(!file_exists('custom/Extension/modules/abc_Test/Ext/Layoutdefs')) {
  19. mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
  20. }
  21. if(!file_exists('modules/abc_Test/metadata')) {
  22. mkdir_recursive('modules/abc_Test/metadata');
  23. }
  24. if( $fh = @fopen('modules/abc_Test/metadata/studio.php', 'w+') )
  25. {
  26. $string = <<<EOQ
  27. \$GLOBALS['studioDefs']['abc_Test'] = array(
  28. );
  29. EOQ;
  30. fputs( $fh, $string);
  31. fclose( $fh );
  32. }
  33. if( $fh = @fopen('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php', 'w+') )
  34. {
  35. $string = <<<EOQ
  36. <?php
  37. \$dictionary["abc_Test"]["fields"]["abc_test_abc_test"] = array (
  38. 'name' => 'abc_test_abc_test',
  39. 'type' => 'link',
  40. 'relationship' => 'abc_test_abc_test',
  41. 'source' => 'non-db',
  42. 'side' => 'right',
  43. 'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
  44. );
  45. ?>
  46. <?php
  47. \$dictionary["abc_Test"]["fields"]["abc_test_abc_test_name"] = array (
  48. 'name' => 'abc_test_abc_test_name',
  49. 'type' => 'relate',
  50. 'source' => 'non-db',
  51. 'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
  52. 'save' => true,
  53. 'id_name' => 'abc_test_ab6dabc_test_ida',
  54. 'link' => 'abc_test_abc_test',
  55. 'table' => 'abc_test',
  56. 'module' => 'abc_Test',
  57. 'rname' => 'name',
  58. );
  59. ?>
  60. <?php
  61. \$dictionary["abc_Test"]["fields"]["abc_test_ab6dabc_test_ida"] = array (
  62. 'name' => 'abc_test_ab6dabc_test_ida',
  63. 'type' => 'link',
  64. 'relationship' => 'abc_test_abc_test',
  65. 'source' => 'non-db',
  66. 'reportable' => false,
  67. 'side' => 'right',
  68. 'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_R_TITLE',
  69. );
  70. ?>
  71. EOQ;
  72. fputs( $fh, $string);
  73. fclose( $fh );
  74. }
  75. //Create the custom relationships
  76. if(!file_exists('custom/metadata')) {
  77. mkdir_recursive('custom/metadata');
  78. }
  79. if( $fh = @fopen('custom/metadata/abc_test_abc_testMetaData.php', 'w+') )
  80. {
  81. $string = <<<EOQ
  82. <?php
  83. \$dictionary["abc_test_abc_test"] = array (
  84. 'true_relationship_type' => 'one-to-many',
  85. 'relationships' =>
  86. array (
  87. 'abc_test_abc_test' =>
  88. array (
  89. 'lhs_module' => 'abc_Test',
  90. 'lhs_table' => 'abc_test',
  91. 'lhs_key' => 'id',
  92. 'rhs_module' => 'abc_Test',
  93. 'rhs_table' => 'abc_test',
  94. 'rhs_key' => 'id',
  95. 'relationship_type' => 'one-to-many',
  96. 'join_table' => 'abc_test_abc_test_c',
  97. 'join_key_lhs' => 'abc_test_ab6dabc_test_ida',
  98. 'join_key_rhs' => 'abc_test_aed49bc_test_idb',
  99. ),
  100. ),
  101. 'table' => 'abc_test_abc_test_c',
  102. 'fields' =>
  103. array (
  104. 0 =>
  105. array (
  106. 'name' => 'id',
  107. 'type' => 'varchar',
  108. 'len' => 36,
  109. ),
  110. 1 =>
  111. array (
  112. 'name' => 'date_modified',
  113. 'type' => 'datetime',
  114. ),
  115. 2 =>
  116. array (
  117. 'name' => 'deleted',
  118. 'type' => 'bool',
  119. 'len' => '1',
  120. 'default' => '0',
  121. 'required' => true,
  122. ),
  123. 3 =>
  124. array (
  125. 'name' => 'abc_test_ab6dabc_test_ida',
  126. 'type' => 'varchar',
  127. 'len' => 36,
  128. ),
  129. 4 =>
  130. array (
  131. 'name' => 'abc_test_aed49bc_test_idb',
  132. 'type' => 'varchar',
  133. 'len' => 36,
  134. ),
  135. ),
  136. 'indices' =>
  137. array (
  138. 0 =>
  139. array (
  140. 'name' => 'abc_test_abc_testspk',
  141. 'type' => 'primary',
  142. 'fields' =>
  143. array (
  144. 0 => 'id',
  145. ),
  146. ),
  147. 1 =>
  148. array (
  149. 'name' => 'abc_test_abc_test_ida1',
  150. 'type' => 'index',
  151. 'fields' =>
  152. array (
  153. 0 => 'abc_test_ab6dabc_test_ida',
  154. ),
  155. ),
  156. 2 =>
  157. array (
  158. 'name' => 'abc_test_abc_test_alt',
  159. 'type' => 'alternate_key',
  160. 'fields' =>
  161. array (
  162. 0 => 'abc_test_aed49bc_test_idb',
  163. ),
  164. ),
  165. ),
  166. );
  167. ?>
  168. EOQ;
  169. fputs( $fh, $string);
  170. fclose( $fh );
  171. }
  172. if(!file_exists('custom/Extension/application/Ext/TableDictionary')) {
  173. mkdir_recursive('custom/Extension/application/Ext/TableDictionary');
  174. }
  175. if( $fh = @fopen('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php', 'w+') )
  176. {
  177. $string = <<<EOQ
  178. <?php
  179. include('custom/metadata/abc_test_abc_testMetaData.php');
  180. ?>
  181. EOQ;
  182. fputs( $fh, $string);
  183. fclose( $fh );
  184. }
  185. $this->rel_guid = create_guid();
  186. $sql = "INSERT INTO relationships (id, relationship_name, lhs_module, lhs_table, lhs_key, rhs_module, rhs_table, rhs_key, join_table, join_key_lhs, join_key_rhs, relationship_type, reverse, deleted) VALUES ('{$this->rel_guid}', 'abc_test_abc_test', 'abc_Test', 'abc_test', 'id', 'abc_Test', 'abc_test', 'id', 'abc_test_abc_test_c', 'abc_test_ab6abc_test_id', 'abc_test_aed49bc_test_id', 'one-to-many', 0, 0)";
  187. $GLOBALS['db']->query($sql);
  188. $rel = new Relationship();
  189. $rel->delete_cache();
  190. $rel->build_relationship_cache();
  191. $this->moduleList = $GLOBALS['moduleList'];
  192. }
  193. function tearDown() {
  194. if(file_exists('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php')) {
  195. unlink('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php');
  196. }
  197. if(file_exists('custom/metadata/abc_test_abc_testMetaData.php')) {
  198. unlink('custom/metadata/abc_test_abc_testMetaData.php');
  199. }
  200. if(file_exists('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php')) {
  201. unlink('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php');
  202. }
  203. if(file_exists('modules/abc_Test/metadata/studio.php')) {
  204. unlink('modules/abc_Test/metadata/studio.php');
  205. }
  206. rmdir_recursive('custom/Extension/modules/abc_Test/Ext/Vardefs');
  207. rmdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
  208. rmdir_recursive('custom/Extension/modules/abc_Test/Ext');
  209. rmdir_recursive('custom/Extension/modules/abc_Test');
  210. rmdir_recursive('modules/abc_Test/metadata');
  211. rmdir_recursive('modules/abc_Test');
  212. $sql = "DELETE FROM relationships WHERE id = '{$this->rel_guid}'";
  213. $GLOBALS['db']->query($sql);
  214. $GLOBALS['moduleList'] = $this->moduleList;
  215. }
  216. function test_upgrade_custom_relationships() {
  217. $GLOBALS['moduleList'] = array();
  218. $GLOBALS['moduleList'][] = 'abc_Test';
  219. $GLOBALS['beanList']['abc_Test'] = 'abc_Test';
  220. /*
  221. include('modules/Administration/upgrade_custom_relationships.php');
  222. upgrade_custom_relationships();
  223. include('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php');
  224. */
  225. }
  226. }
  227. ?>