]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/DynamicFields/Bug40658Test.php
Release 6.2.2
[Github/sugarcrm.git] / tests / modules / DynamicFields / Bug40658Test.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
38 class Bug40658Test extends Sugar_PHPUnit_Framework_TestCase
39 {
40     public function setup()
41     {
42             require('include/modules.php');
43             $GLOBALS['beanList'] = $beanList;
44             $GLOBALS['beanFiles'] = $beanFiles; 
45             //$this->useOutputBuffering = false;
46     }
47     
48     public function testGetRelateJoin()
49     {
50                 require_once('modules/DynamicFields/DynamicField.php');
51                 $dynamicField = new DynamicField();
52                 $account = new Account();
53                 $dynamicField->bean = $account;
54                 
55                 $field_def = array(
56                         'dependency' => '',
57                     'required' => '',
58                     'source' => 'non-db',
59                     'name' => 'm1_related_c',
60                     'vname' => 'LBL_M1_RELATED',
61                     'type' => 'relate',
62                     'massupdate' => 0,
63                     'default' => '',
64                     'comments' => '',
65                     'help' => '',
66                     'importable' => true,
67                     'duplicate_merge' => 'disabled',
68                     'duplicate_merge_dom_value' => 0,
69                     'audited' => '',
70                     'reportable' => 1,
71                     'calculated' => '',
72                     'len' => 255,
73                     'size' => 20,
74                     'id_name' => 'def_m1_id_c',
75                     'ext2' => 'Accounts',
76                     'module' => 'Accounts',
77                     'rname' => 'name',
78                     'quicksearch' => 'enabled',
79                     'studio' => 'visible',
80                     'id' => 'def_M1m1_related_c',
81                     'custom_module' => 'Accounts',
82             );
83                 
84             $joinTableAlias = 'jt1';
85             $relatedJoinInfo = $dynamicField->getRelateJoin($field_def, $joinTableAlias);
86             //echo var_export($relatedJoinInfo, true);
87             $this->assertEquals(', accounts_cstm.def_m1_id_c, jt1.name m1_related_c ', $relatedJoinInfo['select']);
88     }
89     
90     public function testSubpanelMetaDataParser()
91     {
92         $subpanelMetaDataParser = new SubpanelMetaDataParserMock('Bug40658Test', 'Accounts');
93         $defs = array('m1_related_c' => 
94                                 array (
95                                           'type' => 'relate',
96                                           'default' => true,
97                                           'studio' => 'visible',
98                                           'vname' => 'LBL_M2_RELATED',
99                                           'width' => '10%',
100                                         )
101                                 );
102         $result = $subpanelMetaDataParser->makeRelateFieldsAsLink($defs);
103                 $this->assertEquals('SubPanelDetailViewLink', $result['m1_related_c']['widget_class']);
104                 $this->assertEquals('def_M1', $result['m1_related_c']['target_module']);
105                 $this->assertEquals('def_m1_id_c', $result['m1_related_c']['target_record_key']);               
106     }
107 }
108
109 require_once('modules/ModuleBuilder/parsers/views/SubpanelMetaDataParser.php');
110
111 class SubpanelMetaDataParserMock extends SubpanelMetaDataParser
112 {
113         //Override constructor... don't do anything
114         function __construct ($subpanelName , $moduleName , $packageName = '')
115         {
116                 
117         }
118                 
119         public function makeRelateFieldsAsLink($defs)
120         {
121                 $this->_moduleName = 'def_M1';
122                 $this->_fielddefs = array('m1_related_c' => 
123                         array (
124                           'dependency' => '',
125                           'required' => false,
126                           'source' => 'non-db',
127                           'name' => 'm1_related_c',
128                           'vname' => 'LBL_M1_RELATED',
129                           'type' => 'relate',
130                           'massupdate' => '0',
131                           'default' => true,
132                           'comments' => '',
133                           'help' => '',
134                           'importable' => 'true',
135                           'duplicate_merge' => 'disabled',
136                           'duplicate_merge_dom_value' => '0',
137                           'audited' => false,
138                           'reportable' => true,
139                           'calculated' => false,
140                           'len' => '255',
141                           'size' => '20',
142                           'id_name' => 'def_m1_id_c',
143                           'ext2' => 'def_M1',
144                           'module' => 'def_M1',
145                           'rname' => 'name',
146                           'quicksearch' => 'enabled',
147                           'studio' => 'visible',
148                           'id' => 'def_M1m1_related_c',
149                           'custom_module' => 'def_M1',
150                           'label' => 'm1_related_c',
151                           'width' => '10%',
152                           'widget_class' => 'SubPanelDetailViewLink',
153                           'target_module' => 'def_M1',
154                           'target_record_key' => 'def_m1_id_c',
155                         )
156             );
157                 
158
159                
160                 return parent::makeRelateFieldsAsLink($defs);
161                                 
162         }
163 }