]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/SugarMerge/Bug37231Test.php
Release 6.3.1
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / SugarMerge / Bug37231Test.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 require_once 'include/dir_inc.php';
38
39 class Bug37231Test extends Sugar_PHPUnit_Framework_TestCase  {
40
41 var $merge;
42 var $has_dir;
43 var $modules;
44
45 function setUp() {
46    $this->modules = array('Accounts', 'Opportunities');
47    $this->has_dir = array();
48    
49    foreach($this->modules as $module) {
50            if(!file_exists("custom/modules/{$module}/metadata")){
51                   mkdir_recursive("custom/modules/{$module}/metadata", true);
52            }
53            
54            if(file_exists("custom/modules/{$module}")) {
55                   $this->has_dir[$module] = true;
56            }
57            
58            $files = array('detailviewdefs', 'editviewdefs', 'searchdefs', 'listviewdefs');
59            foreach($files as $file) {
60                    if(file_exists("custom/modules/{$module}/metadata/{$file}")) {
61                           copy("custom/modules/{$module}/metadata/{$file}.php", "custom/modules/{$module}/metadata/{$file}.php.bak");
62                    }
63                    
64                    if(file_exists("custom/modules/{$module}/metadata/{$file}.php.suback.php")) {
65                       copy("custom/modules/{$module}/metadata/{$file}.php.suback.php", "custom/modules/{$module}/metadata/{$file}.php.suback.bak");
66                    }
67                    
68                    if(file_exists("tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/custom/modules/{$module}/metadata/{$file}.php")) {
69                           copy("tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/custom/modules/{$module}/metadata/{$file}.php", "custom/modules/{$module}/metadata/{$file}.php");
70                    }
71            } //foreach
72    } //foreach
73 }
74
75
76 function tearDown() {
77
78    foreach($this->modules as $module) {
79            if(!$this->has_dir[$module]) {
80                   rmdir_recursive("custom/modules/{$module}");
81            }  else {
82                    $files = array('detailviewdefs', 'editviewdefs', 'searchdefs', 'listviewdefs');
83                    foreach($files as $file) {
84                       if(file_exists("custom/modules/{$module}/metadata/{$file}.php.bak")) {
85                          copy("custom/modules/{$module}/metadata/{$file}.php.bak", "custom/modules/{$module}/metadata/{$file}.php");
86                      unlink("custom/modules/{$module}/metadata/{$file}.php.bak");
87                       } else if(file_exists("custom/modules/{$module}/metadata/{$file}.php")) {
88                          unlink("custom/modules/{$module}/metadata/{$file}.php");
89                       }
90                       
91                           if(file_exists("custom/modules/{$module}/metadata/{$module}.php.suback.bak")) {
92                          copy("custom/modules/{$module}/metadata/{$file}.php.suback.bak", "custom/modules/{$module}/metadata/{$file}.php.suback.php");
93                      unlink("custom/modules/{$module}/metadata/{$file}.php.suback.bak");
94                       } else if(file_exists("custom/modules/{$module}/metadata/{$file}.php.suback.php")) {
95                          unlink("custom/modules/{$module}/metadata/{$file}.php.suback.php");
96                       }  
97                    }
98            }
99    } //foreach
100 }
101
102
103 function test_accounts_editview_merge() {               
104    $original_panels = array();
105    require('custom/modules/Accounts/metadata/editviewdefs.php');        
106    foreach($viewdefs['Accounts']['EditView']['panels'] as $panel_key=>$panel) {
107           $original_panels[$panel_key] = $panel_key;
108    }    
109    
110    
111    require_once 'modules/UpgradeWizard/SugarMerge/EditViewMerge.php';
112    $this->merge = new EditViewMerge();  
113    $this->merge->merge('Accounts', 'tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/551/modules/Accounts/metadata/editviewdefs.php', 'modules/Accounts/metadata/editviewdefs.php', 'custom/modules/Accounts/metadata/editviewdefs.php');
114    $this->assertTrue(file_exists('custom/modules/Accounts/metadata/editviewdefs.php.suback.php'));
115    require('custom/modules/Accounts/metadata/editviewdefs.php');
116    $fields = array();
117    $panels = array();
118    
119    foreach($viewdefs['Accounts']['EditView']['panels'] as $panel_key=>$panel) {
120           $panels[$panel_key] = $panel_key;
121           foreach($panel as $row) {
122                  foreach($row as $col_key=>$col) {
123                         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
124                         if(!empty($id) && !is_array($id)) {
125                            $fields[$id] = $col;
126                         }
127                  }
128           }
129    }
130    
131    //echo var_export($original_panels, true);
132    //echo var_export($panels, true);
133    $this->assertTrue(count($panels) == count($original_panels), "Assert that orignal number of panels are preserved in custom Accounts EditView layout");
134    $this->assertTrue(isset($panels['lbl_address_information']), "Assert that 'lbl_address_information' panel id is present");
135    $this->assertTrue(isset($panels['lbl_email_addresses']), "Assert that 'lbl_email_addresses' panel id is present");
136    $this->assertTrue(isset($panels['lbl_description_information']), "Assert that 'lbl_description_information' panel id is present");
137
138
139    $custom_fields = array('reference_code_c', 'code_customized_by_c', 'customer_reference_c', 'type_of_reference_c',
140                           'reference_contact_c', 'last_used_as_reference_c', 'reference_status_c', 'reference_notes_c',
141                                                   'last_used_reference_notes_c', 'training_credits_purchased_c', 'remaining_training_credits_c',
142                                               'training_credits_pur_date_c', 'training_credits_exp_date_c', 'support_cases_purchased_c',
143    );
144    
145    foreach($custom_fields as $c_field) {
146                 $this->assertTrue(isset($fields["{$c_field}"]), "Assert that custom field {$c_field} is present");
147    }
148    
149   
150 }
151
152
153 function test_accounts_detailview_merge() {             
154    require_once 'modules/UpgradeWizard/SugarMerge/DetailViewMerge.php';
155    $this->merge = new DetailViewMerge();        
156    $this->merge->merge('Accounts', 'tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/551/modules/Accounts/metadata/detailviewdefs.php', 'modules/Accounts/metadata/detailviewdefs.php', 'custom/modules/Accounts/metadata/detailviewdefs.php');
157    $this->assertTrue(file_exists('custom/modules/Accounts/metadata/detailviewdefs.php.suback.php'));
158    require('custom/modules/Accounts/metadata/detailviewdefs.php');
159    $fields = array();
160    $panels = array();
161    
162    foreach($viewdefs['Accounts']['DetailView']['panels'] as $panel_key=>$panel) {
163           $panels[$panel_key] = $panel_key;
164           foreach($panel as $row) {
165                  foreach($row as $col_key=>$col) {
166                         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
167                         if(!empty($id) && !is_array($id)) {
168                            $fields[$id] = $col;
169                         }
170                  }
171           }
172    }
173    
174    //echo var_export($panels, true);
175    //echo var_export($viewdefs['Accounts']['DetailView']['panels'], true);
176    $this->assertTrue(count($panels) == 5, "Assert that there are 5 panels matching the custom Accounts DetailView layout");
177    $this->assertTrue(isset($panels['DEFAULT']), "Assert that 'DEFAULT' panel id is present");
178    $this->assertTrue(isset($panels['lbl_panel7']), "Assert that 'lbl_panel7' panel id is present");
179    $this->assertTrue(isset($panels['LBL_PANEL1']), "Assert that 'LBL_PANEL1' panel id is present");
180    $this->assertTrue(isset($panels['LBL_PANEL6']), "Assert that 'LBL_PANEL6' panel id is present");
181    $this->assertTrue(isset($panels['LBL_PANEL4']), "Assert that 'LBL_PANEL4' panel id is present");
182
183    //Test fields that were specified in other OOTB panels, but that are moved back to the default panel for
184    //this customization
185    $this->assertTrue(isset($fields['team_name']), "Assert that team_name field is present");
186    $this->assertTrue(isset($fields['date_modified']), "Assert that date_modified field is present"); 
187 }
188
189
190 function test_accounts_searchdefs_merge() {     
191    require_once 'modules/UpgradeWizard/SugarMerge/SearchMerge.php';             
192    $this->merge = new SearchMerge();    
193    $this->merge->merge('Accounts', 'tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/551/modules/Accounts/metadata/searchdefs.php', 'modules/Accounts/metadata/searchdefs.php', 'custom/modules/Accounts/metadata/searchdefs.php');
194    $this->assertTrue(file_exists('custom/modules/Accounts/metadata/searchdefs.php.suback.php'));
195    require('custom/modules/Accounts/metadata/searchdefs.php');
196    $fields = array();
197    
198    foreach($searchdefs['Accounts']['layout']['basic_search'] as $col_key=>$col) {
199         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
200         if(!empty($id) && !is_array($id)) {
201                    $fields[$id] = $col;
202                 }
203    }
204   
205    
206    $this->assertTrue(count($fields) == 6, "Assert that there are 6 fields in the basic_search layout for Accounts metadata");
207    
208    $fields = array();
209    foreach($searchdefs['Accounts']['layout']['advanced_search'] as $col_key=>$col) {
210         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
211         if(!empty($id)) {
212                 $fields[$id] = $col;
213         }
214    }
215    $this->assertTrue(count($fields) == 18, "Assert that there are 18 fields in the advanced_search layout for Accounts metadata");
216 }
217
218
219 function test_accounts_listviewdefs_merge() {   
220    require_once 'modules/UpgradeWizard/SugarMerge/ListViewMerge.php';           
221    $this->merge = new ListViewMerge();  
222    $this->merge->merge('Accounts', 'tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/551/modules/Accounts/metadata/listviewdefs.php', 'modules/Accounts/metadata/listviewdefs.php', 'custom/modules/Accounts/metadata/listviewdefs.php');
223    $this->assertTrue(file_exists('custom/modules/Accounts/metadata/listviewdefs.php.suback.php'));
224    require('custom/modules/Accounts/metadata/listviewdefs.php');
225    $fields = array();
226    $displayed_fields = array();
227    foreach($listViewDefs['Accounts'] as $col_key=>$col) {
228                 $fields[$col_key] = $col;
229                 if(isset($col['default']) && $col['default']) {
230                    $displayed_fields[$col_key] = $col;
231                 }
232    }
233   
234    
235    $this->assertTrue(count($displayed_fields) == 6, "Assert that there are 6 fields displayed in the listview layout for Accounts metadata");
236    $this->assertTrue(isset($displayed_fields['NAME']), "Assert that NAME field is present");
237    $this->assertTrue(isset($displayed_fields['BILLING_ADDRESS_CITY']), "Assert that BILLING_ADDRESS_CITY field is present");
238    $this->assertTrue(isset($displayed_fields['BILLING_ADDRESS_STATE']), "Assert that BILLING_ADDRESS_STATE field is present");
239    $this->assertTrue(isset($displayed_fields['PHONE_OFFICE']), "Assert that PHONE_OFFICE field is present");
240    $this->assertTrue(isset($displayed_fields['TEAM_NAME']), "Assert that TEAM_NAME field is present");
241    $this->assertTrue(isset($displayed_fields['ASSIGNED_USER_NAME']), "Assert that ASSIGNED_USER_NAME field is present");
242 }
243
244
245 function test_opportunities_searchdefs_merge() {        
246    require_once 'modules/UpgradeWizard/SugarMerge/SearchMerge.php';             
247    $this->merge = new SearchMerge();
248    $this->merge->merge('Opportunities', 'tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/551/modules/Opportunities/metadata/searchdefs.php', 'modules/Opportunities/metadata/searchdefs.php', 'custom/modules/Opportunities/metadata/searchdefs.php');
249    $this->assertTrue(file_exists('custom/modules/Opportunities/metadata/searchdefs.php.suback.php'));
250    require('custom/modules/Opportunities/metadata/searchdefs.php');
251    $fields = array();
252    
253    foreach($searchdefs['Opportunities']['layout']['basic_search'] as $col_key=>$col) {
254         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
255         if(!empty($id) && !is_array($id)) {
256                    $fields[$id] = $col;
257                 }
258    }
259   
260    $this->assertTrue(count($fields) == 4, "Assert that there are 4 fields in the basic_search layout for Opportunities metadata");
261    $this->assertTrue(isset($fields['name']), "Assert that name field is present");
262    $this->assertTrue(isset($fields['opportunity_type']), "Assert that opportunity_type field is present");
263    $this->assertTrue(isset($fields['account_name']), "Assert that account_name field is present");
264    $this->assertTrue(isset($fields['current_user_only']), "Assert that current_user_only field is present");
265       
266    $fields = array();
267    foreach($searchdefs['Opportunities']['layout']['advanced_search'] as $col_key=>$col) {
268         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
269         if(!empty($id) && !is_array($id)) {
270                    $fields[$id] = $col;
271                 }
272    }
273    
274    $this->assertTrue(count($fields) == 12, "Assert that there are 12 fields in the advanced_search layout for Opportunities metadata");
275    $this->assertTrue(isset($fields['partner_assigned_to_c']), "Assert that partner_assigned_to_c field is present");
276    
277 }
278
279 }
280 ?>