2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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 ********************************************************************************/
40 require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
41 require_once 'include/SubPanel/SubPanelDefinitions.php';
42 require_once 'include/SubPanel/SubPanel.php';
45 * wrong relationship from subpanel create button
49 class Bug53223Test extends Sugar_PHPUnit_Framework_OutputTestCase //Sugar_PHPUnit_Framework_TestCase
52 * @var DeployedRelationships
54 protected $relationships = null;
57 * @var OneToOneRelationship
59 protected $relationship = null;
61 private $parentAccount;
63 private function createRelationship($lhs_module, $rhs_module = null, $relationship_type = 'one-to-many')
65 $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
67 // Adding relation between products and users
68 $this->relationships = new DeployedRelationships($lhs_module);
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'
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);
83 // Updating $dictionary by created relation
85 $moduleInstaller = new ModuleInstaller();
86 $moduleInstaller->silent = true;
87 $moduleInstaller->rebuild_tabledictionary();
88 require 'modules/TableDictionary.php';
91 VardefManager::$linkFields = array();
92 VardefManager::clearVardef();
93 VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module));
94 if ( $lhs_module != $rhs_module )
96 VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module));
98 SugarRelationshipFactory::rebuildCache();
101 private function deleteRelationship($lhs_module, $rhs_module = null, $rel_name = null)
103 $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
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 )
112 LanguageManager::clearLanguageCache($rhs_module);
116 public function setUp()
118 $this->markTestIncomplete("This test is not yet complete. Artem is working on it");
120 $beanFiles = array();
121 require('include/modules.php');
122 $GLOBALS['beanList'] = $beanList;
123 $GLOBALS['beanFiles'] = $beanFiles;
125 $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
126 $GLOBALS['current_user']->is_admin = 1;
128 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
129 $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
131 $this->createRelationship('Accounts');
132 $this->parentAccount = SugarTestAccountUtilities::createAccount();
135 public function tearDown()
137 $this->markTestIncomplete("This test is not yet complete. Artem is working on it");
138 $this->deleteRelationship('Accounts');
140 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
141 unset($GLOBALS['current_user']);
143 unset($GLOBALS['beanFiles'], $GLOBALS['beanList']);
144 unset($GLOBALS['app_strings'], $GLOBALS['app_list_strings'], $GLOBALS['mod_strings']);
146 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
147 SugarTestAccountUtilities::removeAllCreatedAccounts();
149 unset($this->parentAccount);
155 public function testOneToManyRelationshipModule2Modult()
157 $_REQUEST['relate_id'] = $this->parentAccount->id;
158 $_REQUEST['relate_to'] = $this->relationship->getName();
160 // create new account
161 $objAccount = new Account();
162 $objAccount->name = "AccountBug53223".$_REQUEST['relate_to'].time();
164 SugarTestAccountUtilities::setCreatedAccount(array($objAccount->id));
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());
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']);
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');
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']);
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');