]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/UpgradeWizard/SugarMerge/Bug37862Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / UpgradeWizard / SugarMerge / Bug37862Test.php
1 <?php
2 require_once 'include/dir_inc.php';
3
4 class Bug37862Test 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('searchdefs');
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/od_metadata_files/custom/modules/{$module}/metadata/{$file}.php")) {
34                           copy("tests/modules/UpgradeWizard/SugarMerge/od_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('searchdefs');
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_searchdefs_merge() {     
69    require('custom/modules/Contacts/metadata/searchdefs.php');
70    $original_basic_fields = array();
71
72    //echo var_export($searchdefs, true);
73    foreach($searchdefs['Contacts']['layout']['basic_search'] as $col_key=>$col) {
74         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
75         if(!empty($id) && !is_array($id)) {
76                    $original_basic_fields[$id] = $col;
77                 }
78    }
79    
80    $original_advanced_fields = array();
81    foreach($searchdefs['Contacts']['layout']['advanced_search'] as $col_key=>$col) {
82         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
83         if(!empty($id)) {
84                 $original_advanced_fields[$id] = $col;
85         }
86    }   
87    
88         
89    require_once 'modules/UpgradeWizard/SugarMerge/SearchMerge.php';             
90    $this->merge = new SearchMerge();    
91    $this->merge->merge('Contacts', 'tests/modules/UpgradeWizard/SugarMerge/metadata_files/551/modules/Contacts/metadata/searchdefs.php', 'modules/Contacts/metadata/searchdefs.php', 'custom/modules/Contacts/metadata/searchdefs.php');
92    $this->assertTrue(file_exists('custom/modules/Contacts/metadata/searchdefs.php.suback.php'));
93    require('custom/modules/Contacts/metadata/searchdefs.php');
94    $fields = array();
95
96    //echo var_export($searchdefs, true);
97    foreach($searchdefs['Contacts']['layout']['basic_search'] as $col_key=>$col) {
98         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
99         if(!empty($id) && !is_array($id)) {
100                    $fields[$id] = $col;
101                 }
102    }
103    
104    //echo var_export($original_basic_fields, true);
105    //echo var_export($fields, true);
106    //echo var_export(array_diff(array_keys($fields), array_keys($original_basic_fields)), true);
107    
108    
109    $this->assertTrue(count($fields) == 5, "Assert that there are 5 fields in the basic_search layout for Contacts metadata");
110    $this->assertTrue(count(array_diff(array_keys($fields), array_keys($original_basic_fields))) == 0, 'Assert that there is no difference between original basic search and merged basic search Array');
111    
112   
113    $fields = array();
114    foreach($searchdefs['Contacts']['layout']['advanced_search'] as $col_key=>$col) {
115         $id = is_array($col) && isset($col['name']) ? $col['name'] : $col;
116         if(!empty($id)) {
117                 $fields[$id] = $col;
118         }
119    }
120    
121    $this->assertTrue(count($fields) == 16, "Assert that there are 18 fields in the advanced_search layout for Contacts metadata");
122    $this->assertTrue(count(array_diff(array_keys($fields), array_keys($original_advanced_fields))) == 0, 'Assert that there is no difference between original advanced search and merged advanced search Array');
123 }
124
125
126 }
127 ?>