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 ********************************************************************************/
38 require_once('tests/service/SOAPTestCase.php');
39 require_once('soap/SoapHelperFunctions.php');
43 * Soap API add_create_account bug
45 * @author bsitnikovski@sugarcrm.com
48 class Bug61159Test extends Sugar_PHPUnit_Framework_TestCase
51 private $_account1, $_account2, $_contact;
52 private $_deletedAcc, $_deletedAccContact;
57 * Create contact function
59 public function createContact($account_id, $account_name)
61 $contact = SugarTestContactUtilities::createContact();
62 $contact->account_id = $account_id;
63 $contact->account_name = $account_name;
65 $GLOBALS['db']->commit();
70 * Create account function
72 public function createAccount($name, $deleted = 0)
74 $account = SugarTestAccountUtilities::createAccount();
75 $account->name = $account->account_name = $name;
76 $account->deleted = $deleted;
78 $GLOBALS['db']->commit();
83 * Create user, account, contact
85 public function setUp()
87 $this->_account1 = $this->createAccount("Account Bug61159Test");
88 $this->_account2 = $this->createAccount("Account Bug61159Test");
89 $this->_contact = $this->createContact($this->_account2->id, "Account Bug61159Test");
90 $this->_contact2 = $this->createContact(0, "Account Bug61159Test");
92 $this->_deletedAcc = $this->createAccount("Account Bug61159Test 2", 1);
93 $this->_deletedAccContact = $this->createContact($this->_deletedAcc->id, "Account Bug61159Test 2");
99 * Remove account, contact, user
101 public function tearDown()
103 $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}'");
104 $GLOBALS['db']->query("DELETE FROM contacts WHERE id = '{$this->_contact->id}' OR id = '{$this->_deletedAccContact->id}' OR id = '{$this->_contact2->id}'");
105 $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}'");
106 if (isset($this->_tmpacc))
108 $GLOBALS['db']->query("DELETE FROM accounts WHERE id = '{$this->_tmpacc->id}'");
113 * Test add_create_account() to see if it reassigns the contact's account (by Account id)
115 public function testReassignContactById()
117 add_create_account($this->_contact);
118 $this->assertEquals($this->_contact->account_id, $this->_account2->id);
122 * Test add_create_account() to see if it will assign an account to a contact without accounts
124 public function testAssignAccountToContact()
126 add_create_account($this->_contact2);
127 $this->assertNotEquals($this->_contact2->account_id, 0);
131 * Test add_create_account() to see if it will delete a deleted account and create a new one
133 public function testDeletedAccountCreateNew()
135 add_create_account($this->_deletedAccContact);
136 $this->assertNotEquals($this->_deletedAcc->id, $this->_deletedAccContact->account_id);
140 * Test add_create_account() to see if it will create a new account (non-existent by ID and non-existent by Name)
142 public function testNotFoundCreateNew()
144 $dummyContact = new Contact();
145 $dummyContact->account_name = "UniqueAccountNameTest123";
146 add_create_account($dummyContact);
147 $this->_tmpacc = new Account();
148 $this->_tmpacc->retrieve_by_string_fields(array('name' => 'UniqueAccountNameTest123'));
149 $this->assertNotNull($this->_tmpacc->id);