コード例 #1
0
 /**
  * Create a relationship
  *
  * Params should be passed in as this:
  *
  * array(
  *       'relationship_type' => 'one-to-many',
  *       'lhs_module' => 'Accounts',
  *       'rhs_module' => 'Accounts',
  *   )
  *
  * @static
  * @param array $relationship_def
  * @return ActivitiesRelationship|bool|ManyToManyRelationship|ManyToOneRelationship|OneToManyRelationship|OneToOneRelationship
  */
 public static function createRelationship(array $relationship_def)
 {
     if (!self::checkRequiredFields($relationship_def)) {
         return false;
     }
     $relationships = new DeployedRelationships($relationship_def['lhs_module']);
     if (!isset($relationship_def['view_module'])) {
         $relationship_def['view_module'] = $relationship_def['lhs_module'];
     }
     $REQUEST_Backup = $_REQUEST;
     $_REQUEST = $relationship_def;
     $relationship = $relationships->addFromPost();
     $relationships->save();
     $relationships->build();
     LanguageManager::clearLanguageCache($relationship_def['lhs_module']);
     SugarRelationshipFactory::rebuildCache();
     // rebuild the dictionary to make sure that it has the new relationship in it
     SugarTestHelper::setUp('dictionary');
     // reset the link fields since we added one
     VardefManager::$linkFields = array();
     $_REQUEST = $REQUEST_Backup;
     unset($REQUEST_Backup);
     self::$_relsAdded[] = $relationship->getDefinition();
     return $relationship;
 }
コード例 #2
0
ファイル: Bug45339Test.php プロジェクト: delkyd/sugarcrm_dev
 /**
  * @group 45339
  */
 public function testGetExtensionsList()
 {
     // Create new relationship between Leads and Accounts
     $_REQUEST['view_module'] = "Leads";
     $_REQUEST['lhs_module'] = "Leads";
     $_REQUEST['rhs_module'] = "Accounts";
     $_REQUEST['lhs_label'] = "Leads";
     $_REQUEST['rhs_label'] = "Accounts";
     $deployedRelation = new DeployedRelationships($_REQUEST['view_module']);
     $relationLeadAccount = $deployedRelation->addFromPost();
     $deployedRelation->save();
     $deployedRelation->build();
     //create expected file paths from custom extensions
     $accountContactRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationAccountContact->getName() . '_Accounts.php', DIRECTORY_SEPARATOR);
     $contactAccountRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationContactAccount->getName() . '_Accounts.php', DIRECTORY_SEPARATOR);
     $leadAccountRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $relationLeadAccount->getName() . '_Accounts.php', DIRECTORY_SEPARATOR);
     $sugarfieldAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . 'sugarfield_' . $this->field->name . '.php', DIRECTORY_SEPARATOR);
     //call mbPackage to retrieve arrays of Files to be exported using different test parameters
     $accountAllExtensions = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts', 'Contacts', 'Leads'));
     $accountExtContacts = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts', 'Contacts'));
     $accountExtOnly = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts'));
     $contactExtWithWrongRelationship = $this->mbPackage->getExtensionsListTest('Contacts', array(''));
     $wrongModuleName = $this->mbPackage->getExtensionsListTest('Wrong_module_name');
     // Remove relationship
     $deployedRelation->delete($relationLeadAccount->getName());
     $deployedRelation->save();
     SugarRelationshipFactory::deleteCache();
     //assert that contact rels are exported when all rels were defined
     $this->assertContains($accountContactRelInAccountVardefExtensions, $accountAllExtensions, 'Contact Relationship should have been exported when accounts and contacts modules are exported');
     //assert that contact rels are not exported when contact is not defined
     $this->assertNotContains($accountContactRelInAccountVardefExtensions, $accountExtOnly, 'Contact Relationship should NOT have been exported when exporting accounts only');
     //assert that non relationship change is exported when no related module is defined
     $this->assertContains($sugarfieldAccountVardefExtensions, $accountExtOnly, 'Sugarfield change should have been exported when exporting Accounts only');
     //assert only contact and Account modules are present when both contact and Accounts are defined
     $this->assertContains($accountContactRelInAccountVardefExtensions, $accountExtContacts, 'Accounts rels should be present when exporting Contacts and Accounts');
     $this->assertContains($contactAccountRelInAccountVardefExtensions, $accountExtContacts, 'Contacts rels should be present when exporting Contacts and Accounts');
     $this->assertNotContains($leadAccountRelInAccountVardefExtensions, $accountExtContacts, 'Leads rels should NOT be present when exporting Contacts and Accounts');
     //assert that requesting a wrong relationship returns an empty array
     $this->assertInternalType('array', $contactExtWithWrongRelationship, 'array type should be returned when no relationships are exported, and no other changes exist');
     $this->assertEmpty($contactExtWithWrongRelationship, 'An empty array should be returned when no relationships are exported, and no other changes exist');
     //assert that requesting a wrong module name returns an empty array
     $this->assertInternalType('array', $wrongModuleName, 'An array type should be returned when a bad module is requested for export');
     $this->assertEmpty($wrongModuleName, 'An empty array should be returned when a bad module is requested for export');
 }