3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
41 * Export Customizations Does Not Cleanly Handle Relationships.
45 class Bug45339Test extends Sugar_PHPUnit_Framework_TestCase
48 private $relationAccountContact = null;
49 private $relationContactAccount = null;
50 private $mbPackage = null;
51 private $keys = array(
52 'module' => "ModuleBuilder",
53 'action' => "SaveRelationship",
54 'remove_tables' => "true",
56 'relationship_lang' => "en_us",
57 'relationship_name' => "",
59 'relationship_type' => "many-to-many",
63 'lhs_subpanel' => "default",
64 'rhs_subpanel' => "default",
66 private $packName = 'test_package';
68 public function setUp()
70 SugarTestHelper::setUp('current_user', array(true, 1));
71 SugarTestHelper::setUp('beanFiles');
72 SugarTestHelper::setUp('beanList');
73 SugarTestHelper::setUp('app_list_strings');
74 SugarTestHelper::setUp('app_strings');
76 $_REQUEST = $this->keys;
78 $_REQUEST['view_module'] = "Accounts";
79 $_REQUEST['lhs_module'] = "Accounts";
80 $_REQUEST['rhs_module'] = "Contacts";
81 $_REQUEST['lhs_label'] = "Accounts";
82 $_REQUEST['rhs_label'] = "Contacts";
84 $relationAccountContact = new DeployedRelationships($_REQUEST['view_module']);
85 $this->relationAccountContact = $relationAccountContact->addFromPost();
86 $relationAccountContact->save();
87 $relationAccountContact->build();
89 $_REQUEST['view_module'] = "Contacts";
90 $_REQUEST['lhs_module'] = "Contacts";
91 $_REQUEST['rhs_module'] = "Accounts";
92 $_REQUEST['lhs_label'] = "Contacts";
93 $_REQUEST['rhs_label'] = "Accounts";
95 $relationContactAccount = new DeployedRelationships($_REQUEST['view_module']);
96 $this->relationContactAccount = $relationContactAccount->addFromPost();
97 $relationContactAccount->save();
98 $relationContactAccount->build();
100 $this->mbPackage = new Bug45339MBPackageMock($this->packName);
103 public function tearDown()
105 $relationshipAccountContact = new DeployedRelationships($this->relationAccountContact->getLhsModule());
106 $relationshipAccountContact->delete($this->relationAccountContact->getName());
107 $relationshipAccountContact->save();
109 $relationshipContactAccount = new DeployedRelationships($this->relationContactAccount->getLhsModule());
110 $relationshipContactAccount->delete($this->relationContactAccount->getName());
111 $relationshipContactAccount->save();
113 SugarRelationshipFactory::deleteCache();
117 SugarTestHelper::tearDown();
123 public function testGetCustomRelationshipsByModuleName()
125 /* @var $this->mbPackage MBPackage */
126 $accountsAllCustomRelationships = $this->mbPackage->getCustomRelationshipsByModuleNameTest('Accounts');
127 // Created in the Account module.
128 $accountsLhsCustomRelationships = $this->mbPackage->getCustomRelationshipsByModuleNameTest('Accounts', true);
129 $wrongModuleName = $this->mbPackage->getCustomRelationshipsByModuleNameTest('Wrong_module_name');
131 $this->assertArrayHasKey($this->relationAccountContact->getName(), $accountsAllCustomRelationships);
132 $this->assertArrayHasKey($this->relationContactAccount->getName(), $accountsAllCustomRelationships);
134 $this->assertArrayHasKey($this->relationAccountContact->getName(), $accountsLhsCustomRelationships);
135 $this->assertArrayNotHasKey($this->relationContactAccount->getName(), $accountsLhsCustomRelationships);
137 $this->assertFalse($wrongModuleName); // check
143 public function testGetCustomRelationshipsMetaFilesByModuleName()
145 $accountContactMetaPath = sprintf(
146 'custom%1$smetadata%1$s' . $this->relationAccountContact->getName() . 'MetaData.php',
149 $accountContactTablePath = sprintf(
150 'custom%1$sExtension%1$sapplication%1$sExt%1$sTableDictionary%1$s' . $this->relationAccountContact->getName() . '.php',
153 $contactAccountMetaPath = sprintf(
154 'custom%1$smetadata%1$s' . $this->relationContactAccount->getName() . 'MetaData.php',
158 /* @var $this->mbPackage MBPackage */
159 $accountsAllFiles = $this->mbPackage->getCustomRelationshipsMetaFilesByModuleNameTest('Accounts');
160 $accountsOnlyMetaFile = $this->mbPackage->getCustomRelationshipsMetaFilesByModuleNameTest('Accounts', true, true);
161 $wrongModuleName = $this->mbPackage->getCustomRelationshipsMetaFilesByModuleNameTest('Wrong_module_name');
163 $this->assertContains($accountContactMetaPath, $accountsAllFiles);
164 $this->assertContains($accountContactTablePath, $accountsAllFiles);
165 $this->assertContains($contactAccountMetaPath, $accountsAllFiles);
167 $this->assertContains($accountContactMetaPath, $accountsOnlyMetaFile);
168 $this->assertNotContains($contactAccountMetaPath, $accountsOnlyMetaFile);
170 $this->assertInternalType('array', $wrongModuleName);
171 $this->assertEmpty($wrongModuleName);
177 public function testGetExtensionsList()
179 // Create new relationship between Leads and Accounts
180 $_REQUEST['view_module'] = "Leads";
181 $_REQUEST['lhs_module'] = "Leads";
182 $_REQUEST['rhs_module'] = "Accounts";
183 $_REQUEST['lhs_label'] = "Leads";
184 $_REQUEST['rhs_label'] = "Accounts";
186 $deployedRelation = new DeployedRelationships($_REQUEST['view_module']);
187 $relationLeadAccount = $deployedRelation->addFromPost();
188 $deployedRelation->save();
189 $deployedRelation->build();
191 $accountContactRelInAccountVardefExtensions = sprintf(
192 'custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationAccountContact->getName() . '_Accounts.php',
195 $contactAccountRelInAccountVardefExtensions = sprintf(
196 'custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationContactAccount->getName() . '_Accounts.php',
199 $leadAccountRelInAccountVardefExtensions = sprintf(
200 'custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $relationLeadAccount->getName() . '_Accounts.php',
204 /* @var $this->mbPackage MBPackage */
205 $accountAllExtensions = $this->mbPackage->getExtensionsListTest('Accounts');
206 $accountExtContacts = $this->mbPackage->getExtensionsListTest('Accounts', array('Contacts'));
207 $accountExtWithWrongRelationship = $this->mbPackage->getExtensionsListTest('Accounts', array(''));
208 $wrongModuleName = $this->mbPackage->getExtensionsListTest('Wrong_module_name');
210 // Remove relationship
211 $deployedRelation->delete($relationLeadAccount->getName());
212 $deployedRelation->save();
213 SugarRelationshipFactory::deleteCache();
215 $this->assertContains($accountContactRelInAccountVardefExtensions, $accountAllExtensions);
216 $this->assertContains($contactAccountRelInAccountVardefExtensions, $accountAllExtensions);
217 $this->assertContains($leadAccountRelInAccountVardefExtensions, $accountAllExtensions);
219 $this->assertContains($accountContactRelInAccountVardefExtensions, $accountExtContacts);
220 $this->assertContains($contactAccountRelInAccountVardefExtensions, $accountExtContacts);
221 $this->assertNotContains($leadAccountRelInAccountVardefExtensions, $accountExtContacts);
223 $this->assertEmpty($accountExtWithWrongRelationship);
225 $this->assertInternalType('array', $wrongModuleName);
226 $this->assertEmpty($wrongModuleName);
232 public function testGetExtensionsManifestForPackage()
234 /* @var $this->mbPackage MBPackage */
235 $this->mbPackage->exportCustom(array('Accounts'), false, false);
236 $installDefs = array();
237 $packExtentionsPath = $this->mbPackage->getBuildDir() . DIRECTORY_SEPARATOR . 'Extension' . DIRECTORY_SEPARATOR . 'modules';
240 $this->mbPackage->getExtensionsManifestForPackageTest($this->mbPackage->getBuildDir(), $installDefs);
242 $recursiveIterator = new RecursiveIteratorIterator(
243 new RecursiveDirectoryIterator($packExtentionsPath),
244 RecursiveIteratorIterator::SELF_FIRST
247 /* @var $fInfo SplFileInfo */
248 foreach (new RegexIterator($recursiveIterator, "/\.php$/i") as $fInfo)
250 if ($fInfo->isFile())
256 $this->mbPackage->delete();
257 $this->mbPackage->deleteBuild();
259 $this->assertEquals($expected, count($installDefs['copy']));
265 public function testCustomBuildInstall()
267 /* @var $this->mbPackage MBPackage */
268 $this->mbPackage->exportCustom(array('Accounts'), false, false);
269 $installDefString = $this->mbPackage->customBuildInstall(array('Accounts'), $this->mbPackage->getBuildDir());
271 eval($installDefString);
273 $this->mbPackage->delete();
274 $this->mbPackage->deleteBuild();
276 $this->assertArrayHasKey('relationships', $installdefs);
281 class Bug45339MBPackageMock extends MBPackage
284 public function getExtensionsManifestForPackageTest($path, &$installdefs)
286 return $this->getExtensionsManifestForPackage($path, $installdefs);
289 public function getExtensionsListTest($module, $includeRelationships = true)
291 return $this->getExtensionsList($module, $includeRelationships);
294 public function getCustomRelationshipsMetaFilesByModuleNameTest($moduleName, $lhs = false, $metadataOnly = false)
296 return $this->getCustomRelationshipsMetaFilesByModuleName($moduleName, $lhs, $metadataOnly);
299 public function getCustomRelationshipsByModuleNameTest($moduleName, $lhs = false)
301 return $this->getCustomRelationshipsByModuleName($moduleName, $lhs);