PageRenderTime 32ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modules/UpgradeWizard/Bug36845Test.php

https://github.com/jacknicole/sugarcrm_dev
PHP | 222 lines | 162 code | 26 blank | 34 comment | 10 complexity | 263d8a202859fc8069b7319f06e035cd 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 Bug36845Test extends Sugar_PHPUnit_Framework_TestCase
  37. {
  38. var $has_custom_unified_search_modules_display = false;
  39. var $has_custom_unified_search_modules = false;
  40. var $module_dir = 'modules/clabc_Bug36845Test';
  41. var $module = 'clabc_Bug36845Test';
  42. public function setUp()
  43. {
  44. if(file_exists('cache/modules/unified_search_modules.php'))
  45. {
  46. $this->has_custom_unified_search_modules = true;
  47. copy('cache/modules/unified_search_modules.php', 'cache/modules/unified_search_modules.php.bak');
  48. }
  49. if(file_exists('custom/modules/unified_search_modules_display.php'))
  50. {
  51. $this->has_custom_unified_search_modules_display = true;
  52. copy('custom/modules/unified_search_modules_display.php', 'custom/modules/unified_search_modules_display.php.bak');
  53. }
  54. if(file_exists($this->module_dir))
  55. {
  56. rmdir_recursive($this->module_dir);
  57. }
  58. mkdir_recursive($this->module_dir . '/metadata');
  59. $the_string = <<<EOQ
  60. <?php
  61. \$module_name = "{$this->module}";
  62. \$searchFields[\$module_name] =
  63. array (
  64. 'name' => array( 'query_type'=>'default'),
  65. 'account_type'=> array('query_type'=>'default', 'options' => 'account_type_dom', 'template_var' => 'ACCOUNT_TYPE_OPTIONS'),
  66. 'industry'=> array('query_type'=>'default', 'options' => 'industry_dom', 'template_var' => 'INDUSTRY_OPTIONS'),
  67. 'annual_revenue'=> array('query_type'=>'default'),
  68. 'address_street'=> array('query_type'=>'default','db_field'=>array('billing_address_street','shipping_address_street')),
  69. 'address_city'=> array('query_type'=>'default','db_field'=>array('billing_address_city','shipping_address_city')),
  70. 'address_state'=> array('query_type'=>'default','db_field'=>array('billing_address_state','shipping_address_state')),
  71. 'address_postalcode'=> array('query_type'=>'default','db_field'=>array('billing_address_postalcode','shipping_address_postalcode')),
  72. 'address_country'=> array('query_type'=>'default','db_field'=>array('billing_address_country','shipping_address_country')),
  73. 'rating'=> array('query_type'=>'default'),
  74. 'phone'=> array('query_type'=>'default','db_field'=>array('phone_office')),
  75. 'email'=> array('query_type'=>'default','db_field'=>array('email1','email2')),
  76. 'website'=> array('query_type'=>'default'),
  77. 'ownership'=> array('query_type'=>'default'),
  78. 'employees'=> array('query_type'=>'default'),
  79. 'ticker_symbol'=> array('query_type'=>'default'),
  80. 'current_user_only'=> array('query_type'=>'default','db_field'=>array('assigned_user_id'),'my_items'=>true, 'vname' => 'LBL_CURRENT_USER_FILTER', 'type' => 'bool'),
  81. 'assigned_user_id'=> array('query_type'=>'default'),
  82. 'favorites_only' => array(
  83. 'query_type'=>'format',
  84. 'operator' => 'subquery',
  85. 'subquery' => 'SELECT sugarfavorites.record_id FROM sugarfavorites
  86. WHERE sugarfavorites.deleted=0
  87. and sugarfavorites.module = \''.\$module_name.'\'
  88. and sugarfavorites.assigned_user_id = \'{0}\'',
  89. 'db_field'=>array('id')),
  90. );
  91. ?>
  92. EOQ;
  93. $fp = sugar_fopen($this->module_dir . '/metadata/SearchFields.php', "w");
  94. fwrite( $fp, $the_string );
  95. fclose( $fp );
  96. $table_name = strtolower($this->module);
  97. $the_string = <<<EOQ
  98. <?php
  99. \$dictionary["{$this->module}"] = array(
  100. 'table'=>"{$table_name}",
  101. 'audited'=>true,
  102. 'fields'=>array (
  103. ),
  104. 'relationships'=>array (
  105. ),
  106. 'optimistic_locking'=>true,
  107. );
  108. if (!class_exists('VardefManager')){
  109. require_once('include/SugarObjects/VardefManager.php');
  110. }
  111. VardefManager::createVardef("{$this->module}","{$this->module}", array('basic','team_security','assignable','company'));
  112. ?>
  113. EOQ;
  114. $fp = sugar_fopen($this->module_dir . '/vardefs.php', "w");
  115. fwrite( $fp, $the_string );
  116. fclose( $fp );
  117. $the_string = <<<EOQ
  118. <?php
  119. class clabc_Bug36845Test extends Basic
  120. {
  121. }
  122. ?>
  123. EOQ;
  124. $fp = sugar_fopen($this->module_dir . '/clabc_Bug36845Test.php', "w");
  125. fwrite( $fp, $the_string );
  126. fclose( $fp );
  127. global $beanFiles, $beanList;
  128. $beanFiles['clabc_Bug36845Test'] = 'modules/clabc_Bug36845Test/clabc_Bug36845Test.php';
  129. $beanList['clabc_Bug36845Test'] = 'clabc_Bug36845Test';
  130. }
  131. public function tearDown()
  132. {
  133. if(file_exists('cache/modules/unified_search_modules.php'))
  134. {
  135. unlink('cache/modules/unified_search_modules.php');
  136. }
  137. if(file_exists('custom/modules/unified_search_modules_display.php'))
  138. {
  139. unlink('custom/modules/unified_search_modules_display.php');
  140. }
  141. if($this->has_custom_unified_search_modules)
  142. {
  143. copy('cache/modules/unified_search_modules.php.bak', 'cache/modules/unified_search_modules.php');
  144. unlink('cache/modules/unified_search_modules.php.bak');
  145. }
  146. if($this->has_custom_unified_search_modules_display)
  147. {
  148. copy('custom/modules/unified_search_modules_display.php.bak', 'custom/modules/unified_search_modules_display.php');
  149. unlink('custom/modules/unified_search_modules_display.php.bak');
  150. }
  151. if(file_exists($this->module_dir))
  152. {
  153. rmdir_recursive($this->module_dir);
  154. }
  155. }
  156. public function test_update_custom_vardefs()
  157. {
  158. $this->assertTrue(file_exists("{$this->module_dir}/metadata/SearchFields.php"), 'Assert that we have a SearchFields.php file');
  159. $this->assertTrue(file_exists("{$this->module_dir}/vardefs.php"), 'Assert that we have a vardefs.php file');
  160. require_once('modules/UpgradeWizard/uw_utils.php');
  161. add_unified_search_to_custom_modules_vardefs();
  162. require_once('modules/Home/UnifiedSearchAdvanced.php');
  163. $usa = new UnifiedSearchAdvanced();
  164. $usa->buildCache();
  165. $this->assertTrue(file_exists('cache/modules/unified_search_modules.php'), 'Assert that we have a unified_search_modules.php file');
  166. include('cache/modules/unified_search_modules.php');
  167. $this->assertTrue(isset($unified_search_modules['clabc_Bug36845Test']), 'Assert that the custom module was added to unified_search_modules.php');
  168. $this->assertEquals(false, $unified_search_modules['clabc_Bug36845Test']['default'], 'Assert that the custom module was set to not be searched on by default');
  169. }
  170. public function test_update_custom_vardefs_without_searchfields()
  171. {
  172. unlink("{$this->module_dir}/metadata/SearchFields.php");
  173. $this->assertTrue(!file_exists("{$this->module_dir}/metadata/SearchFields.php"), 'Assert that we have a SearchFields.php file');
  174. $this->assertTrue(file_exists("{$this->module_dir}/vardefs.php"), 'Assert that we have a vardefs.php file');
  175. require_once('modules/UpgradeWizard/uw_utils.php');
  176. add_unified_search_to_custom_modules_vardefs();
  177. require_once('modules/Home/UnifiedSearchAdvanced.php');
  178. $usa = new UnifiedSearchAdvanced();
  179. $usa->buildCache();
  180. $this->assertTrue(file_exists("cache/modules/unified_search_modules.php"), 'Assert that we have a unified_search_modules.php file');
  181. include('cache/modules/unified_search_modules.php');
  182. $this->assertTrue(!isset($unified_search_modules['clabc_Bug36845Test']), 'Assert that the custom module was not added to unified_search_modules.php');
  183. }
  184. public function test_create_unified_search_modules_display()
  185. {
  186. if(file_exists('custom/modules/unified_search_modules_display.php'))
  187. {
  188. unlink('custom/modules/unified_search_modules_display.php');
  189. }
  190. require_once('modules/UpgradeWizard/uw_utils.php');
  191. $usa = new UnifiedSearchAdvanced();
  192. $_REQUEST['enabled_modules'] = 'Accounts,Bug36845Test';
  193. $usa->saveGlobalSearchSettings();
  194. $this->assertTrue(file_exists('custom/modules/unified_search_modules_display.php'), 'Assert that unified_search_modules_display.php file was created');
  195. }
  196. }