]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Administration/Bug36978Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Administration / Bug36978Test.php
1 <?php
2
3 class Bug36978Test extends Sugar_PHPUnit_Framework_TestCase {
4
5 var $rel_guid;  
6 var $has_custom_table_dictionary;       
7 var $moduleList;
8
9 function setUp() {
10         
11     if(true) {
12        $this->markTestSkipped("Skipping unless otherwise specified");
13        return;
14     }   
15         
16     $admin = new User();
17     $GLOBALS['current_user'] = $admin->retrieve('1');   
18         
19     $GLOBALS['app_list_strings'] = return_app_list_strings_language('en_us');
20     
21     //Create the custom relationships
22     if(!file_exists('custom/Extension/modules/abc_Test/Ext/Vardefs')) {
23        mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Vardefs');
24     }
25
26     if(!file_exists('custom/Extension/modules/abc_Test/Ext/Layoutdefs')) {
27        mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
28     }    
29     
30     if(!file_exists('modules/abc_Test/metadata')) {
31        mkdir_recursive('modules/abc_Test/metadata');
32     }
33     
34     if( $fh = @fopen('modules/abc_Test/metadata/studio.php', 'w+') )
35     {
36 $string = <<<EOQ
37 \$GLOBALS['studioDefs']['abc_Test'] = array(
38
39 );
40 EOQ;
41        fputs( $fh, $string);
42        fclose( $fh );
43     }
44     
45     if( $fh = @fopen('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php', 'w+') )
46     {
47 $string = <<<EOQ
48
49 <?php
50 \$dictionary["abc_Test"]["fields"]["abc_test_abc_test"] = array (
51   'name' => 'abc_test_abc_test',
52   'type' => 'link',
53   'relationship' => 'abc_test_abc_test',
54   'source' => 'non-db',
55   'side' => 'right',
56   'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
57 );
58 ?>
59 <?php
60 \$dictionary["abc_Test"]["fields"]["abc_test_abc_test_name"] = array (
61   'name' => 'abc_test_abc_test_name',
62   'type' => 'relate',
63   'source' => 'non-db',
64   'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
65   'save' => true,
66   'id_name' => 'abc_test_ab6dabc_test_ida',
67   'link' => 'abc_test_abc_test',
68   'table' => 'abc_test',
69   'module' => 'abc_Test',
70   'rname' => 'name',
71 );
72 ?>
73 <?php
74 \$dictionary["abc_Test"]["fields"]["abc_test_ab6dabc_test_ida"] = array (
75   'name' => 'abc_test_ab6dabc_test_ida',
76   'type' => 'link',
77   'relationship' => 'abc_test_abc_test',
78   'source' => 'non-db',
79   'reportable' => false,
80   'side' => 'right',
81   'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_R_TITLE',
82 );
83 ?>
84
85 EOQ;
86        fputs( $fh, $string);
87        fclose( $fh );
88     } 
89     
90     //Create the custom relationships
91     if(!file_exists('custom/metadata')) {
92        mkdir_recursive('custom/metadata');
93     }    
94     
95     if( $fh = @fopen('custom/metadata/abc_test_abc_testMetaData.php', 'w+') )
96     {
97 $string = <<<EOQ
98
99 <?php
100 \$dictionary["abc_test_abc_test"] = array (
101   'true_relationship_type' => 'one-to-many',
102   'relationships' => 
103   array (
104     'abc_test_abc_test' => 
105     array (
106       'lhs_module' => 'abc_Test',
107       'lhs_table' => 'abc_test',
108       'lhs_key' => 'id',
109       'rhs_module' => 'abc_Test',
110       'rhs_table' => 'abc_test',
111       'rhs_key' => 'id',
112       'relationship_type' => 'one-to-many',
113       'join_table' => 'abc_test_abc_test_c',
114       'join_key_lhs' => 'abc_test_ab6dabc_test_ida',
115       'join_key_rhs' => 'abc_test_aed49bc_test_idb',
116     ),
117   ),
118   'table' => 'abc_test_abc_test_c',
119   'fields' => 
120   array (
121     0 => 
122     array (
123       'name' => 'id',
124       'type' => 'varchar',
125       'len' => 36,
126     ),
127     1 => 
128     array (
129       'name' => 'date_modified',
130       'type' => 'datetime',
131     ),
132     2 => 
133     array (
134       'name' => 'deleted',
135       'type' => 'bool',
136       'len' => '1',
137       'default' => '0',
138       'required' => true,
139     ),
140     3 => 
141     array (
142       'name' => 'abc_test_ab6dabc_test_ida',
143       'type' => 'varchar',
144       'len' => 36,
145     ),
146     4 => 
147     array (
148       'name' => 'abc_test_aed49bc_test_idb',
149       'type' => 'varchar',
150       'len' => 36,
151     ),
152   ),
153   'indices' => 
154   array (
155     0 => 
156     array (
157       'name' => 'abc_test_abc_testspk',
158       'type' => 'primary',
159       'fields' => 
160       array (
161         0 => 'id',
162       ),
163     ),
164     1 => 
165     array (
166       'name' => 'abc_test_abc_test_ida1',
167       'type' => 'index',
168       'fields' => 
169       array (
170         0 => 'abc_test_ab6dabc_test_ida',
171       ),
172     ),
173     2 => 
174     array (
175       'name' => 'abc_test_abc_test_alt',
176       'type' => 'alternate_key',
177       'fields' => 
178       array (
179         0 => 'abc_test_aed49bc_test_idb',
180       ),
181     ),
182   ),
183 );
184 ?>
185
186
187 EOQ;
188        fputs( $fh, $string);
189        fclose( $fh );
190     }
191
192     
193 if(!file_exists('custom/Extension/application/Ext/TableDictionary'))  {
194    mkdir_recursive('custom/Extension/application/Ext/TableDictionary');
195 }
196     
197
198 if( $fh = @fopen('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php', 'w+') )
199 {
200 $string = <<<EOQ
201 <?php
202 include('custom/metadata/abc_test_abc_testMetaData.php');
203 ?>
204 EOQ;
205        fputs( $fh, $string);
206        fclose( $fh );
207 }
208
209     $this->rel_guid = create_guid();
210     $sql = "INSERT INTO relationships (id, relationship_name, lhs_module, lhs_table, lhs_key, rhs_module, rhs_table, rhs_key, join_table, join_key_lhs, join_key_rhs, relationship_type, reverse, deleted) VALUES ('{$this->rel_guid}', 'abc_test_abc_test', 'abc_Test', 'abc_test', 'id', 'abc_Test', 'abc_test', 'id', 'abc_test_abc_test_c', 'abc_test_ab6abc_test_id', 'abc_test_aed49bc_test_id', 'one-to-many', 0, 0)";
211     $GLOBALS['db']->query($sql); 
212
213     $rel = new Relationship();
214     $rel->delete_cache();
215     $rel->build_relationship_cache();
216     
217     $this->moduleList = $GLOBALS['moduleList'];
218 }
219
220 function tearDown() {
221     if(file_exists('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php')) {
222        unlink('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php'); 
223     }
224
225     if(file_exists('custom/metadata/abc_test_abc_testMetaData.php')) {
226        unlink('custom/metadata/abc_test_abc_testMetaData.php'); 
227     }    
228     
229     if(file_exists('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php')) {
230        unlink('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php'); 
231     }
232
233     if(file_exists('modules/abc_Test/metadata/studio.php')) {
234        unlink('modules/abc_Test/metadata/studio.php'); 
235     }    
236     
237         rmdir_recursive('custom/Extension/modules/abc_Test/Ext/Vardefs');
238         rmdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
239         rmdir_recursive('custom/Extension/modules/abc_Test/Ext');
240         rmdir_recursive('custom/Extension/modules/abc_Test');
241         rmdir_recursive('modules/abc_Test/metadata');
242         rmdir_recursive('modules/abc_Test');
243         
244         $sql = "DELETE FROM relationships WHERE id = '{$this->rel_guid}'";
245         $GLOBALS['db']->query($sql);
246         
247         $GLOBALS['moduleList'] = $this->moduleList;
248 }
249
250
251 function test_upgrade_custom_relationships() {  
252         $GLOBALS['moduleList'] = array();
253         $GLOBALS['moduleList'][] = 'abc_Test';
254         $GLOBALS['beanList']['abc_Test'] = 'abc_Test';
255         /*
256     include('modules/Administration/upgrade_custom_relationships.php');
257         upgrade_custom_relationships();
258         include('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php');
259         */
260 }
261
262
263 }
264 ?>