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