]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/SugarMerge/Bug37295Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / SugarMerge / Bug37295Test.php
1 <?php
2 require_once 'include/dir_inc.php';
3
4 class Bug37295Test extends Sugar_PHPUnit_Framework_TestCase  {
5
6 var $merge;
7 var $has_dir;
8 var $modules;
9
10 function setUp() {
11    $this->modules = array('Contacts');
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('editviewdefs');
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('editviewdefs');
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_contacts_editview_merge() {       
69
70    require('custom/modules/Contacts/metadata/editviewdefs.php');
71    $pre_upgrade_fields = array();
72    $pre_upgrade_panels = array();
73    foreach($viewdefs['Contacts']['EditView']['panels'] as $panel_key=>$panel) {
74           $pre_upgrade_panels[$panel_key] = $panel_key;
75           foreach($panel as $row) {
76                  foreach($row as $col_key=>$col) {
77                         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
78                         if(!empty($id) && !is_array($id)) {
79                            $pre_upgrade_fields[$id] = $col;
80                         }
81                  }
82           }
83    }    
84
85
86    require_once 'modules/UpgradeWizard/SugarMerge/EditViewMerge.php';
87    $this->merge = new EditViewMerge();  
88    $this->merge->merge('Contacts', 'tests/modules/UpgradeWizard/SugarMerge/siupgrade_metadata_files/551/modules/Contacts/metadata/editviewdefs.php', 'modules/Contacts/metadata/editviewdefs.php', 'custom/modules/Contacts/metadata/editviewdefs.php');
89    $this->assertTrue(file_exists('custom/modules/Contacts/metadata/editviewdefs.php.suback.php'));
90    require('custom/modules/Contacts/metadata/editviewdefs.php');
91    $fields = array();
92    $panels = array();
93    
94    //echo var_export($viewdefs['Contacts']['EditView']['panels'], true);
95    $new_fields = array();
96    
97    foreach($viewdefs['Contacts']['EditView']['panels'] as $panel_key=>$panel) {
98           $panels[$panel_key] = $panel_key;
99           foreach($panel as $row) {
100                  foreach($row as $col_key=>$col) {
101                         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
102                         if(!empty($id) && !is_array($id)) {
103                            $fields[$id] = $col;
104                            if(!isset($pre_upgrade_fields[$id])) {
105                                  $new_fields[$id] = $id;
106                            }
107                         }
108                  }
109           }
110    }
111   
112    
113    
114    $this->assertTrue(isset($panels['lbl_panel1']), "Assert that 'panel1' panel id is present");
115    $this->assertTrue(isset($panels['lbl_address_information']), "Assert that 'lbl_address_information' panel id is present");
116    $this->assertTrue(isset($panels['lbl_email_addresses']), "Assert that 'lbl_email_addresses' panel id is present");
117    $this->assertTrue(isset($panels['lbl_description_information']), "Assert that 'lbl_description_information' panel id is present");
118
119
120    $custom_fields = array('primary_business_c', 'support_authorized_c', 'university_enabled_c', 'billing_contact_c',
121                           'oppq_active_c', 'technical_proficiency_');
122    
123    foreach($custom_fields as $c_field) {
124                 $this->assertTrue(isset($fields["{$c_field}"]), "Assert that custom field {$c_field} is present");
125    }
126    
127 }
128
129
130 }
131 ?>