2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
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');
48 class Bug40171Test extends Sugar_PHPUnit_Framework_TestCase
52 public function setUp()
54 global $moduleList, $beanList, $beanFiles;
55 require('include/modules.php');
56 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
57 $this->bean = new Contact();
60 public function tearDown()
62 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
63 unset($GLOBALS['current_user']);
65 foreach ($this->filename_check as $filename) {
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();
74 public function testSubpanelOverride()
80 'subpanel_name' => 'default',
81 'sort_order' => 'asc',
83 'title_key' => 'LBL_CONTACTS_CASES_1_FROM_CASES_TITLE',
84 'get_subpanel_data' => 'contacts_cases_1',
88 'widget_class' => 'SubPanelTopButtonQuickCreate',
91 'widget_class' => 'SubPanelTopSelectButton',
92 'mode' => 'MultiSelect',
96 $subpanel_list_fields_1['list_fields'] = array (
100 'vname' => 'LBL_PRIORITY',
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);
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;
118 'subpanel_name' => 'default',
119 'sort_order' => 'asc',
121 'title_key' => 'LBL_CONTACTS_CASES_2_FROM_CASES_TITLE',
122 'get_subpanel_data' => 'contacts_cases_2',
126 'widget_class' => 'SubPanelTopButtonQuickCreate',
129 'widget_class' => 'SubPanelTopSelectButton',
130 'mode' => 'MultiSelect',
134 $subpanel_list_fields_2 = array (
137 'vname' => 'LBL_LIST_NUMBER',
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);
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;
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)));
160 // laout_defs are reloaded in saveSubPanelDefOverride method, we lauched it
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']);