]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SubPanel/Bug44344Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / include / SubPanel / Bug44344Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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('include/SubPanel/SubPanelTilesTabs.php');
39
40 /**
41  * Bug #44344
42  * Custom relationships under same module only show once in subpanel tabs
43  *
44  * @ticket 44344
45  */
46 class Bug44344Test extends Sugar_PHPUnit_Framework_TestCase
47 {
48     private $account;
49     private $subPanel;
50     private $group_label;
51
52     public function setUp()
53     {
54         global $beanList, $beanFiles;
55         require('include/modules.php');
56
57         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser(true, 1);
58         $GLOBALS['current_user']->setPreference('max_tabs', '7');
59
60         // create vardef to add new relation account - cases
61         $this->addNewRelationships();
62
63         // add new tabgroup whit cases module
64         unset($GLOBALS['tabStructure']);
65         $this->group_label = 'LBL_GROUPTAB_'.mktime();
66         $GLOBALS['tabStructure'][$this->group_label] = array(
67             'label' => $this->group_label,
68             'modules' => array('Cases')
69         );
70
71         $this->account = SugarTestAccountUtilities::createAccount();
72     }
73
74     public function tearDown()
75     {
76         SugarTestAccountUtilities::removeAllCreatedAccounts();
77         unset($this->account);
78
79         unset($GLOBALS['tabStructure']);
80         unset($this->subPanel, $this->group_label);
81         unset($GLOBALS['dictionary']["accounts_cases_10000"]);
82
83         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
84         unset($GLOBALS['current_user']);
85
86         unset($GLOBALS['beanFiles']);
87         unset($GLOBALS['beanList']);
88     }
89
90     /**
91      * add new relation accounts_cases_10000 (Account to Cases: one-to-many)
92      * @return void
93      */
94     private function addNewRelationships()
95     {
96         $GLOBALS['dictionary']["accounts_cases_10000"] = array (
97             'true_relationship_type' => 'one-to-many',
98             'from_studio' => true,
99             'relationships' =>
100             array (
101                 'accounts_cases_10000' =>
102                 array (
103                     'lhs_module' => 'Accounts',
104                     'lhs_table' => 'accounts',
105                     'lhs_key' => 'id',
106                     'rhs_module' => 'Cases',
107                     'rhs_table' => 'cases',
108                     'rhs_key' => 'id',
109                     'relationship_type' => 'many-to-many',
110                     'join_table' => 'accounts_cases_10000_c',
111                     'join_key_lhs' => 'accounts_cases_10000accounts_ida',
112                     'join_key_rhs' => 'accounts_cases_10000cases_idb',
113                 ),
114             ),
115             'table' => 'accounts_cases_10000_c',
116             'fields' =>
117             array (
118                 0 => array ('name' => 'id', 'type' => 'varchar', 'len' => 36),
119                 1 => array ('name' => 'date_modified', 'type' => 'datetime'),
120                 2 => array ('name' => 'deleted', 'type' => 'bool', 'len' => '1', 'default' => '0', 'required' => true),
121                 3 => array ('name' => 'accounts_cases_10000accounts_ida', 'type' => 'varchar', 'len' => 36),
122                 4 => array ('name' => 'accounts_cases_10000cases_idb', 'type' => 'varchar', 'len' => 36),
123             ),
124             'indices' =>
125             array (
126                 0 => array ('name' => 'accounts_cases_10000spk', 'type' => 'primary', 'fields' => array (0 => 'id')),
127                 1 => array ('name' => 'accounts_cases_10000_ida1', 'type' => 'index', 'fields' => array (0 => 'accounts_cases_10000accounts_ida')),
128                 2 => array ('name' => 'accounts_cases_10000_alt', 'type' => 'alternate_key', 'fields' => array (0 => 'accounts_cases_10000cases_idb')),
129             ),
130         );
131     }
132
133     /**
134      * generate mock layout_defs for SubPanelDefinitions object
135      * add two subpanels: cases (default relation) and accounts_cases_10000 (test created relation)
136      * @return array
137      */
138     private function getLayoutDefs()
139     {
140         $layout_defs = array();
141
142         $layout_defs["subpanel_setup"]['cases'] = array(
143             'order' => 100,
144             'sort_order' => 'desc',
145             'sort_by' => 'case_number',
146             'module' => 'Cases',
147             'subpanel_name' => 'ForAccounts',
148             'get_subpanel_data' => 'cases',
149             'add_subpanel_data' => 'case_id',
150             'title_key' => 'LBL_CASES_SUBPANEL_TITLE',
151             'top_buttons' => array(
152                 array('widget_class' => 'SubPanelTopButtonQuickCreate'),
153                 array('widget_class' => 'SubPanelTopSelectButton', 'mode'=>'MultiSelect')
154             ),
155         );
156
157         $layout_defs["subpanel_setup"]['accounts_cases_10000'] = array (
158             'order' => 100,
159             'module' => 'Cases',
160             'subpanel_name' => 'default',
161             'sort_order' => 'asc',
162             'sort_by' => 'id',
163             'title_key' => 'LBL_ACCOUNTS_CASES_FROM_CASES_TITLE',
164             'get_subpanel_data' => 'accounts_cases_10000',
165         );
166         return $layout_defs;
167     }
168
169     /**
170      * @group 44344
171      * @outputBuffering enabled
172      */
173     public function testSubPanelTilesTabsGetTabs()
174     {
175         $tabs = array('cases', 'accounts_cases_10000');
176         $this->subPanel = new SubPanelTilesTabs($this->account, '', $this->getLayoutDefs());
177
178         // get tabs by selected group ($this->group_label)
179         $returned_tabs = $this->subPanel->getTabs($tabs, true, $this->group_label);
180
181         foreach ( $tabs as $tab )
182         {
183             $this->assertContains($tab, $returned_tabs);
184         }
185     }
186 }