2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
37 class Bug36978Test extends Sugar_PHPUnit_Framework_TestCase {
40 var $has_custom_table_dictionary;
45 $this->markTestIncomplete("Skipping unless otherwise specified");
48 $GLOBALS['current_user'] = $admin->retrieve('1');
50 $GLOBALS['app_list_strings'] = return_app_list_strings_language('en_us');
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');
57 if(!file_exists('custom/Extension/modules/abc_Test/Ext/Layoutdefs')) {
58 mkdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
61 if(!file_exists('modules/abc_Test/metadata')) {
62 mkdir_recursive('modules/abc_Test/metadata');
65 if( $fh = @fopen('modules/abc_Test/metadata/studio.php', 'w+') )
68 \$GLOBALS['studioDefs']['abc_Test'] = array(
76 if( $fh = @fopen('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php', 'w+') )
81 \$dictionary["abc_Test"]["fields"]["abc_test_abc_test"] = array (
82 'name' => 'abc_test_abc_test',
84 'relationship' => 'abc_test_abc_test',
87 'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
91 \$dictionary["abc_Test"]["fields"]["abc_test_abc_test_name"] = array (
92 'name' => 'abc_test_abc_test_name',
95 'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_L_TITLE',
97 'id_name' => 'abc_test_ab6dabc_test_ida',
98 'link' => 'abc_test_abc_test',
99 'table' => 'abc_test',
100 'module' => 'abc_Test',
105 \$dictionary["abc_Test"]["fields"]["abc_test_ab6dabc_test_ida"] = array (
106 'name' => 'abc_test_ab6dabc_test_ida',
108 'relationship' => 'abc_test_abc_test',
109 'source' => 'non-db',
110 'reportable' => false,
112 'vname' => 'LBL_ABC_TEST_ABC_TEST_FROM_ABC_TEST_R_TITLE',
117 fputs( $fh, $string);
121 //Create the custom relationships
122 if(!file_exists('custom/metadata')) {
123 mkdir_recursive('custom/metadata');
126 if( $fh = @fopen('custom/metadata/abc_test_abc_testMetaData.php', 'w+') )
131 \$dictionary["abc_test_abc_test"] = array (
132 'true_relationship_type' => 'one-to-many',
135 'abc_test_abc_test' =>
137 'lhs_module' => 'abc_Test',
138 'lhs_table' => 'abc_test',
140 'rhs_module' => 'abc_Test',
141 'rhs_table' => 'abc_test',
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',
149 'table' => 'abc_test_abc_test_c',
160 'name' => 'date_modified',
161 'type' => 'datetime',
173 'name' => 'abc_test_ab6dabc_test_ida',
179 'name' => 'abc_test_aed49bc_test_idb',
188 'name' => 'abc_test_abc_testspk',
197 'name' => 'abc_test_abc_test_ida1',
201 0 => 'abc_test_ab6dabc_test_ida',
206 'name' => 'abc_test_abc_test_alt',
207 'type' => 'alternate_key',
210 0 => 'abc_test_aed49bc_test_idb',
219 fputs( $fh, $string);
224 if(!file_exists('custom/Extension/application/Ext/TableDictionary')) {
225 mkdir_recursive('custom/Extension/application/Ext/TableDictionary');
229 if( $fh = @fopen('custom/Extension/application/Ext/TableDictionary/abc_test_abc_test.php', 'w+') )
233 include('custom/metadata/abc_test_abc_testMetaData.php');
236 fputs( $fh, $string);
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);
244 $rel = new Relationship();
245 Relationship::delete_cache();
246 $rel->build_relationship_cache();
248 $this->moduleList = $GLOBALS['moduleList'];
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');
256 if(file_exists('custom/metadata/abc_test_abc_testMetaData.php')) {
257 unlink('custom/metadata/abc_test_abc_testMetaData.php');
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');
264 if(file_exists('modules/abc_Test/metadata/studio.php')) {
265 unlink('modules/abc_Test/metadata/studio.php');
268 if(is_dir('custom/Extension/modules/abc_Test/Ext/Vardefs')) {
269 rmdir_recursive('custom/Extension/modules/abc_Test/Ext/Vardefs');
271 if(is_dir('custom/Extension/modules/abc_Test/Ext/Layoutdefs')) {
272 rmdir_recursive('custom/Extension/modules/abc_Test/Ext/Layoutdefs');
274 if(is_dir('custom/Extension/modules/abc_Test/Ext')) {
275 rmdir_recursive('custom/Extension/modules/abc_Test/Ext');
277 if(is_dir('custom/Extension/modules/abc_Test')) {
278 rmdir_recursive('custom/Extension/modules/abc_Test');
280 if(is_dir('modules/abc_Test/metadata')) {
281 rmdir_recursive('modules/abc_Test/metadata');
283 if(is_dir('modules/abc_Test')) {
284 rmdir_recursive('modules/abc_Test');
287 if ( !empty($this->rel_guid) ) {
288 $sql = "DELETE FROM relationships WHERE id = '{$this->rel_guid}'";
289 $GLOBALS['db']->query($sql);
292 if ( !empty($this->moduleList) ) {
293 $GLOBALS['moduleList'] = $this->moduleList;
298 function test_upgrade_custom_relationships() {
299 $GLOBALS['moduleList'] = array();
300 $GLOBALS['moduleList'][] = 'abc_Test';
301 $GLOBALS['beanList']['abc_Test'] = 'abc_Test';
303 include('modules/Administration/upgrade_custom_relationships.php');
304 upgrade_custom_relationships();
305 include('custom/Extension/modules/abc_Test/Ext/Vardefs/test.php');