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