]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SubPanel/Bug40171Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / include / SubPanel / Bug40171Test.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 require_once('data/SugarBean.php');
39 require_once('modules/Contacts/Contact.php');
40 require_once('include/SubPanel/SubPanel.php');
41 require_once('include/SubPanel/SubPanel.php');
42 require_once('include/SubPanel/SubPanelDefinitions.php');
43
44 /**
45  * @ticket 41853
46  * @ticket 40171
47  */
48 class Bug40171Test extends Sugar_PHPUnit_Framework_TestCase 
49 {       
50     protected $bean;
51
52         public function setUp()
53         {
54             global $moduleList, $beanList, $beanFiles;
55         require('include/modules.php');
56             $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
57         $this->bean = new Contact();
58         }
59
60         public function tearDown()
61         {
62                 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
63         unset($GLOBALS['current_user']);
64
65         foreach ($this->filename_check as $filename) {
66             @unlink($filename);
67         }
68                 require_once('ModuleInstall/ModuleInstaller.php');
69                 $moduleInstaller = new ModuleInstaller();
70                 $moduleInstaller->silent = true; // make sure that the ModuleInstaller->log() function doesn't echo while rebuilding the layoutdefs
71                 $moduleInstaller->rebuild_layoutdefs();
72         }
73
74     public function testSubpanelOverride()
75     {
76         // Create Subpanel 1
77         $subpanel_1 = array(
78             'order' => 100,
79             'module' => 'Cases',
80             'subpanel_name' => 'default',
81             'sort_order' => 'asc',
82             'sort_by' => 'id',
83             'title_key' => 'LBL_CONTACTS_CASES_1_FROM_CASES_TITLE',
84             'get_subpanel_data' => 'contacts_cases_1',
85             'top_buttons' => 
86             array (
87                 0 => array (
88                       'widget_class' => 'SubPanelTopButtonQuickCreate',
89                 ),
90                 1 => array (
91                     'widget_class' => 'SubPanelTopSelectButton',
92                     'mode' => 'MultiSelect',
93                 ),
94             ),
95         );
96         $subpanel_list_fields_1['list_fields'] = array (
97             'priority' => 
98             array (
99                 'type' => 'enum',
100                 'vname' => 'LBL_PRIORITY',
101                 'sortable' => false,
102                 'width' => '10%',
103                 'default' => true,
104             ),
105         );
106         $subpanel_def_1 = new aSubPanel("contacts_cases_1", $subpanel_1, $this->bean);
107         $subpanel_1 = new SubPanel('Contacts', 'fab4', $subpanel_def_1->_instance_properties['subpanel_name'], $subpanel_def_1);
108         $subpanel_1->saveSubPanelDefOverride($subpanel_def_1, 'list_fields', $subpanel_list_fields_1);
109
110                 $path_1     = 'custom/modules/'. $subpanel_def_1->_instance_properties['module'] . '/metadata/subpanels';
111                 $filename_1 = $subpanel_def_1->parent_bean->object_name . "_subpanel_" . $subpanel_def_1->name;
112                 $extname_1  = '_override'.$subpanel_def_1->parent_bean->object_name . "_subpanel_" . $subpanel_def_1->name;
113         
114         // Create SubPane 2
115         $subpanel_2 = array(
116             'order' => 100,
117             'module' => 'Cases',
118             'subpanel_name' => 'default',
119             'sort_order' => 'asc',
120             'sort_by' => 'id',
121             'title_key' => 'LBL_CONTACTS_CASES_2_FROM_CASES_TITLE',
122             'get_subpanel_data' => 'contacts_cases_2',
123             'top_buttons' => 
124             array (
125                 0 => array (
126                       'widget_class' => 'SubPanelTopButtonQuickCreate',
127                 ),
128                 1 => array (
129                     'widget_class' => 'SubPanelTopSelectButton',
130                     'mode' => 'MultiSelect',
131                 ),
132             ),
133         );
134         $subpanel_list_fields_2 = array (
135             'case_number' => 
136             array (
137                 'vname' => 'LBL_LIST_NUMBER',
138                 'width' => '6%',
139                 'default' => true,
140             ),
141         );
142         $subpanel_def_2 = new aSubPanel("contacts_cases_2", $subpanel_2, $this->bean);
143         $subpanel_2 = new SubPanel('Contacts', 'fab4', $subpanel_def_2->_instance_properties['subpanel_name'], $subpanel_def_2);
144         $subpanel_2->saveSubPanelDefOverride($subpanel_def_2, 'list_fields', $subpanel_list_fields_2);
145
146                 $path_2     = 'custom/modules/'. $subpanel_def_2->_instance_properties['module'] . '/metadata/subpanels';
147                 $filename_2 = $subpanel_def_1->parent_bean->object_name . "_subpanel_" . $subpanel_def_2->name;
148                 $extname_2  = '_override'.$subpanel_def_1->parent_bean->object_name . "_subpanel_" . $subpanel_def_2->name;
149                 
150         // Check files genertaed by subpanel overriding : layout override and subpanel overire
151         $this->filename_check[] = 'custom/Extension/modules/'. $subpanel_def_1->parent_bean->module_dir . "/Ext/Layoutdefs/$extname_1.php";
152         $this->assertTrue(file_exists(end($this->filename_check)));
153         $this->filename_check[] = $path_1.'/' . $filename_1 .'.php';
154         $this->assertTrue(file_exists(end($this->filename_check)));
155         $this->filename_check[] = 'custom/Extension/modules/'. $subpanel_def_2->parent_bean->module_dir . "/Ext/Layoutdefs/$extname_2.php";
156         $this->assertTrue(file_exists(end($this->filename_check)));
157         $this->filename_check[] = $path_2.'/' . $filename_2 .'.php';
158         $this->assertTrue(file_exists(end($this->filename_check)));
159
160         // laout_defs are reloaded in saveSubPanelDefOverride method, we lauched it
161         global $layout_defs;
162
163         // Check override_subpanel_name are differents
164         $this->assertTrue(isset($layout_defs['Contacts']['subpanel_setup']['contacts_cases_1']['override_subpanel_name']));
165         $this->assertTrue(isset($layout_defs['Contacts']['subpanel_setup']['contacts_cases_2']['override_subpanel_name']));
166         $this->assertNotEquals($layout_defs['Contacts']['subpanel_setup']['contacts_cases_1']['override_subpanel_name'], $layout_defs['Contacts']['subpanel_setup']['contacts_cases_2']['override_subpanel_name']);
167
168     }
169
170
171 }