account_id = $account_id; $contact->account_name = $account_name; $contact->save(); $GLOBALS['db']->commit(); return $contact; } /** * Create account function */ public function createAccount($name, $deleted = 0) { $account = SugarTestAccountUtilities::createAccount(); $account->name = $account->account_name = $name; $account->deleted = $deleted; $account->save(); $GLOBALS['db']->commit(); return $account; } /** * Create user, account, contact */ public function setUp() { $this->_account1 = $this->createAccount("Account Bug61159Test"); $this->_account2 = $this->createAccount("Account Bug61159Test"); $this->_contact = $this->createContact($this->_account2->id, "Account Bug61159Test"); $this->_contact2 = $this->createContact(0, "Account Bug61159Test"); $this->_deletedAcc = $this->createAccount("Account Bug61159Test 2", 1); $this->_deletedAccContact = $this->createContact($this->_deletedAcc->id, "Account Bug61159Test 2"); parent::setUp(); } /** * Remove account, contact, user */ public function tearDown() { $GLOBALS['db']->query("DELETE FROM accounts WHERE id = '{$this->_account1->id}' OR id = '{$this->_account2->id}' OR id = '{$this->_deletedAcc->id}' OR id = '{$this->_deletedAccContact->account_id}'"); $GLOBALS['db']->query("DELETE FROM contacts WHERE id = '{$this->_contact->id}' OR id = '{$this->_deletedAccContact->id}' OR id = '{$this->_contact2->id}'"); $GLOBALS['db']->query("DELETE FROM accounts_contacts WHERE contact_id = '{$this->_contact->id}' OR contact_id = '{$this->_deletedAccContact->id}' OR contact_id = '{$this->_contact2->id}'"); if (isset($this->_tmpacc)) { $GLOBALS['db']->query("DELETE FROM accounts WHERE id = '{$this->_tmpacc->id}'"); } } /** * Test add_create_account() to see if it reassigns the contact's account (by Account id) */ public function testReassignContactById() { add_create_account($this->_contact); $this->assertEquals($this->_contact->account_id, $this->_account2->id); } /** * Test add_create_account() to see if it will assign an account to a contact without accounts */ public function testAssignAccountToContact() { add_create_account($this->_contact2); $this->assertNotEquals($this->_contact2->account_id, 0); } /** * Test add_create_account() to see if it will delete a deleted account and create a new one */ public function testDeletedAccountCreateNew() { add_create_account($this->_deletedAccContact); $this->assertNotEquals($this->_deletedAcc->id, $this->_deletedAccContact->account_id); } /** * Test add_create_account() to see if it will create a new account (non-existent by ID and non-existent by Name) */ public function testNotFoundCreateNew() { $dummyContact = new Contact(); $dummyContact->account_name = "UniqueAccountNameTest123"; add_create_account($dummyContact); $this->_tmpacc = new Account(); $this->_tmpacc->retrieve_by_string_fields(array('name' => 'UniqueAccountNameTest123')); $this->assertNotNull($this->_tmpacc->id); } }