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