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