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