]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/data/Bug53223Test.php
Release 6.5.3
[Github/sugarcrm.git] / tests / data / Bug53223Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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
39
40 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
41 require_once 'include/SubPanel/SubPanelDefinitions.php';
42 require_once 'include/SubPanel/SubPanel.php';
43 /**
44  * Bug #53223
45  * wrong relationship from subpanel create button
46  *
47  * @ticket 53223
48  */
49 class Bug53223Test extends Sugar_PHPUnit_Framework_OutputTestCase //Sugar_PHPUnit_Framework_TestCase
50 {
51     /**
52      * @var DeployedRelationships
53      */
54     protected $relationships = null;
55
56     /**
57      * @var OneToOneRelationship
58      */
59     protected $relationship = null;
60
61     private $parentAccount;
62
63     private function createRelationship($lhs_module, $rhs_module = null, $relationship_type = 'one-to-many')
64     {
65         $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
66
67         // Adding relation between products and users
68         $this->relationships = new DeployedRelationships($lhs_module);
69         $definition = array(
70             'lhs_module' => $lhs_module,
71             'relationship_type' => $relationship_type,
72             'rhs_module' => $rhs_module,
73             'lhs_label' => $lhs_module,
74             'rhs_label' => $rhs_module,
75             'rhs_subpanel' => 'default'
76         );
77         $this->relationship = RelationshipFactory::newRelationship($definition);
78         $this->relationships->add($this->relationship);
79         $this->relationships->save();
80         $this->relationships->build();
81         LanguageManager::clearLanguageCache($lhs_module);
82
83         // Updating $dictionary by created relation
84         global $dictionary;
85         $moduleInstaller = new ModuleInstaller();
86         $moduleInstaller->silent = true;
87         $moduleInstaller->rebuild_tabledictionary();
88         require 'modules/TableDictionary.php';
89
90         // Updating vardefs
91         VardefManager::$linkFields = array();
92         VardefManager::clearVardef();
93         VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module));
94         if ( $lhs_module != $rhs_module )
95         {
96             VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module));
97         }
98         SugarRelationshipFactory::rebuildCache();
99     }
100
101     private function deleteRelationship($lhs_module, $rhs_module = null, $rel_name = null)
102     {
103         $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
104
105         $this->relationships = new DeployedRelationships($lhs_module);
106         $this->relationships->delete($rel_name !== null ? $rel_name : $this->relationship->getName());
107         $this->relationships->save();
108         SugarRelationshipFactory::deleteCache();
109         LanguageManager::clearLanguageCache($lhs_module);
110         if ( $lhs_module != $rhs_module )
111         {
112             LanguageManager::clearLanguageCache($rhs_module);
113         }
114     }
115
116     public function setUp()
117     {
118         $this->markTestIncomplete("This test is not yet complete. Artem is working on it");
119         $beanList = array();
120         $beanFiles = array();
121         require('include/modules.php');
122         $GLOBALS['beanList'] = $beanList;
123         $GLOBALS['beanFiles'] = $beanFiles;
124
125         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
126         $GLOBALS['current_user']->is_admin = 1;
127
128         $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
129         $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
130
131         $this->createRelationship('Accounts');
132         $this->parentAccount = SugarTestAccountUtilities::createAccount();
133     }
134
135     public function tearDown()
136     {
137         $this->markTestIncomplete("This test is not yet complete. Artem is working on it");
138         $this->deleteRelationship('Accounts');
139
140         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
141         unset($GLOBALS['current_user']);
142
143         unset($GLOBALS['beanFiles'], $GLOBALS['beanList']);
144         unset($GLOBALS['app_strings'], $GLOBALS['app_list_strings'], $GLOBALS['mod_strings']);
145
146         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
147         SugarTestAccountUtilities::removeAllCreatedAccounts();
148
149         unset($this->parentAccount);
150     }
151
152     /**
153      * @group 53223
154      */
155     public function testOneToManyRelationshipModule2Modult()
156     {
157         $_REQUEST['relate_id'] = $this->parentAccount->id;
158         $_REQUEST['relate_to'] = $this->relationship->getName();
159
160         // create new account
161         $objAccount = new Account();
162         $objAccount->name = "AccountBug53223".$_REQUEST['relate_to'].time();
163         $objAccount->save();
164         SugarTestAccountUtilities::setCreatedAccount(array($objAccount->id));
165
166         // Retrieve new data
167         $this->parentAccount->retrieve($this->parentAccount->id);
168         $objAccount->retrieve($objAccount->id);
169         $this->parentAccount->load_relationship($this->relationship->getName());
170         $objAccount->load_relationship($this->relationship->getName());
171
172         // Getting data of subpanel of parent bean
173         $_REQUEST['module'] = 'Accounts';
174         $_REQUEST['action'] = 'DetailView';
175         $_REQUEST['record'] = $this->parentAccount->id;
176         $_SERVER['REQUEST_METHOD'] = 'GET';
177         unset($GLOBALS['focus']);
178
179         $subpanels = new SubPanelDefinitions($this->parentAccount, 'Accounts');
180         $subpanelDef = $subpanels->load_subpanel($this->relationship->getName().'accounts_ida');
181         $subpanel = new SubPanel('Accounts', $this->parentAccount->id, 'default', $subpanelDef);
182         $subpanel->setTemplateFile('include/SubPanel/SubPanelDynamic.html');
183         $subpanel->display();
184         $actual = $this->getActualOutput();
185         $this->assertContains($objAccount->name, $actual, 'Account name is not displayed in subpanel of parent account');
186
187         ob_clean();
188
189         // Getting data of subpanel of child bean
190         $_REQUEST['module'] = 'Accounts';
191         $_REQUEST['action'] = 'DetailView';
192         $_REQUEST['record'] = $objAccount->id;
193         $_SERVER['REQUEST_METHOD'] = 'GET';
194         unset($GLOBALS['focus']);
195
196         $subpanels = new SubPanelDefinitions($objAccount, 'Accounts');
197         $subpanelDef = $subpanels->load_subpanel($this->relationship->getName().'accounts_ida');
198         $subpanel = new SubPanel('Accounts', $objAccount->id, 'default', $subpanelDef);
199         $subpanel->setTemplateFile('include/SubPanel/SubPanelDynamic.html');
200         $subpanel->display();
201         $actual = $this->getActualOutput();
202         $this->assertNotContains($this->parentAccount->name, $actual, 'Parent account name is displayed in subpanel of child aaccount');
203     }
204 }